Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

foreman_content

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foreman_content - rubygems Package Compare versions

Comparing version
0.1
to
0.2
+29
app/models/concerns/content/custom_repository_paths.rb
module Content
module CustomRepositoryPaths
extend ActiveSupport::Concern
def repo_path_from_content_path(environment, content_path)
content_path = content_path.sub(/^\//, "")
path_prefix = [environment.organization.label, environment.label].join("/")
"#{path_prefix}/#{content_path}"
end
# repo path for custom product repos (RH repo paths are derived from
# content url)
def custom_repo_path(org_label, environment_label, product_label, repo_label)
prefix = [org_label, environment_label].map { |x| x.gsub(/[^-\w]/, "_") }.join("/")
prefix + custom_content_path(product_label, repo_label)
end
def custom_content_path(product_label, repo_label)
parts = []
# We generate repo path only for custom product content. We add this
# constant string to avoid collisions with RH content. RH content url
# begins usually with something like "/content/dist/rhel/...".
# There we prefix custom content/repo url with "/custom/..."
parts << "custom"
parts += [product_label, repo_label]
"/" + parts.map { |x| x.gsub(/[^-\w]/, "_") }.join("/")
end
end
end
module Content::EnvironmentExtensions
extend ActiveSupport::Concern
included do
has_many :environment_products, :dependent => :destroy, :uniq => true, :class_name => 'Content::EnvironmentProduct'
has_many :products, :through => :environment_products, :class_name => 'Content::Product'
end
end
module Content::HomeHelper
extend ActiveSupport::Concern
included do
alias_method_chain :setting_options, :content_link
end
# Adds a content link to the More menu
def setting_options_with_content_link
choices = setting_options_without_content_link
content_group =
[
[_('Products'), :"content/products"],
[_('Repositories'), :"content/repositories"],
[_('Gpg keys'), :"content/gpg_keys"]
]
choices.insert(3, [:divider], [:group, _("Content"), content_group])
end
end
module Content::HostExtensions
extend ActiveSupport::Concern
included do
has_many :host_products, :dependent => :destroy, :uniq => true, :foreign_key => :host_id, :class_name => 'Content::HostProduct'
has_many :products, :through => :host_products, :class_name => 'Content::Product'
scoped_search :in => :products, :on => :name, :complete_value => true, :rename => :product
alias_method_chain :params, :repositories
end
# adds repository hash to ENC global parameters
def params_with_repositories
# convert all repos to a format that puppet create_resource with yumrepo can consume
repos = Hash[attached_repositories.map { |repo| [repo.to_label, format_repo(repo)] }]
# adds a global parameter called repositories contain all repos
params_without_repositories.merge('repositories' => repos)
end
# product_ids from the os default and hostgroup.
def inherited_product_ids
products = []
products += operatingsystem.product_ids if operatingsystem
products += Content::HostgroupProduct.where(:hostgroup_id => hostgroup.path_ids).pluck(:product_id) if hostgroup_id
products.uniq
end
def all_product_ids
(inherited_product_ids + product_ids).uniq
end
def attached_repositories
Content::Repository.attached_to_host(self)
end
private
# convert a repository to a format that puppet create_resource with yumrepo can consume
def format_repo repo
{
'baseurl' => repo.full_path,
# yum repos have descr field but no name, if descr is empty use the repo name
'descr' => repo.description.blank? ? repo.name : repo.description,
'enabled' => repo.enabled ? '1' : '0',
'gpgcheck' => !!repo.gpg_key ? '1' : '0'
}
end
end
module Content::HostgroupExtensions
extend ActiveSupport::Concern
included do
has_many :hostgroup_products, :dependent => :destroy, :uniq => true, :class_name => 'Content::HostgroupProduct'
has_many :products, :through => :hostgroup_products, :class_name => 'Content::Product'
scoped_search :in => :products, :on => :name, :complete_value => true, :rename => :product
end
def inherited_product_ids
Content::HostgroupProduct.where(:hostgroup_id => hostgroup.ancestor_ids).pluck(:product_id)
end
def all_product_ids
(inherited_product_ids + product_ids).uniq
end
end
module Content::OperatingsystemExtensions
extend ActiveSupport::Concern
included do
has_many :operatingsystem_repositories, :dependent => :destroy, :uniq => true, :class_name => 'Content::OperatingsystemRepository'
has_many :repositories, :through => :operatingsystem_repositories, :class_name => 'Content::Repository'
has_many :product_operatingsystems, :dependent => :destroy, :uniq => true, :class_name => 'Content::ProductOperatingsystem'
has_many :products, :through => :product_operatingsystems, :class_name => 'Content::Product'
has_many :default_repositories, :through => :products, :source => :repositories, :class_name => 'Content::Repository'
end
end
module Content::RedhatExtensions
extend ActiveSupport::Concern
included do
alias_method_chain :medium_uri, :content_uri
end
def medium_uri_with_content_uri host, url = nil
if url.nil? && (full_path = Content::Repository.available_for_host(host).kickstart.first.try(:full_path))
URI.parse(full_path)
else
medium_uri_without_content_uri(host, url)
end
end
# return an array of repositories for kickstart script as additional repos
# to the kickstart main repo, this list will typically include updates and epel
def repos host
host.attached_repositories.yum.map { |repo| format_repo(repo) }
end
private
# convert a repository to a format that kickstart script can consume
def format_repo repo
{
:baseurl => repo.full_path,
:name => repo.to_label,
:description => repo.product.description,
:enabled => repo.enabled,
:gpgcheck => !!repo.gpg_key
}
end
end
module Content::TaxonomyExtensions
extend ActiveSupport::Concern
included do
has_many :products, :through => :taxable_taxonomies, :source => :taxable, :source_type => 'Content::Product'
alias_method_chain :dup, :content_dup
end
def dup_with_content_dup
new = dup_without_content_dup
new.products = products
new
end
end
require 'runcible'
require 'uri'
class Content::PulpConfiguration
def initialize options = {}
Runcible::Base.config = runcible_config.merge(options)
end
def runcible_config
pulp_url = URI(Setting.pulp_url)
{
:url => "#{pulp_url.scheme}://#{pulp_url.host}:#{pulp_url.port}",
:api_path => pulp_url.path,
:user => "admin",
:timeout => 60,
:open_timeout => 60,
:oauth => { :oauth_secret => Setting['pulp_oauth_secret'],
:oauth_key => Setting['pulp_oauth_key'] },
:logging => { :logger => Rails.logger,
:exception => true,
:debug => true }
}
end
end
+2
-0

@@ -40,2 +40,4 @@ module Content

def initialize_pulp
# initiate pulp connection
Content::PulpConfiguration.new
self.pulp_id ||= Foreman.uuid.gsub("-", '')

@@ -42,0 +44,0 @@ self.relative_path ||= custom_repo_path("acme_org", "library", product.name, name) if name

+10
-19

@@ -1,11 +0,1 @@

require 'content_home_helper_patch'
require 'content_taxonomy'
require 'content_environment'
require 'content_operatingsystem'
require 'content_redhat'
require 'content_hostgroup'
require 'content_host'
require 'pulp_configuration'
module Content

@@ -16,2 +6,5 @@ ENGINE_NAME = "content"

config.autoload_paths += Dir["#{config.root}/app/services"]
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
# Load this before the Foreman config initializers, so that the Setting.descendants

@@ -25,3 +18,2 @@ # list includes the plugin STI setting class

app.config.paths['db/migrate'] += Content::Engine.paths['db/migrate'].existent
app.config.autoload_paths += Dir["#{config.root}/app/services)"]
end

@@ -31,17 +23,16 @@

config.to_prepare do
::PulpConfiguration.initialize_runcible
# Patch the menu
::HomeHelper.send :include, ContentHomeHelperPatch
::HomeHelper.send :include, Content::HomeHelper
# Extend the taxonomy model
::Taxonomy.send :include, ContentTaxonomy
::Taxonomy.send :include, Content::TaxonomyExtensions
# Extend the environment model
::Environment.send :include, ContentEnvironment
::Environment.send :include, Content::EnvironmentExtensions
# Extend OS model
::Operatingsystem.send :include, ContentOperatingsystem
::Operatingsystem.send :include, Content::OperatingsystemExtensions
# Extend RedHat OS family model
::Redhat.send :include, ContentRedhat
::Redhat.send :include, Content::RedhatExtensions
# Extend the hostgroup model
::Hostgroup.send :include, ContentHostgroup
::Hostgroup.send :include, Content::HostgroupExtensions
# Extend the host model
::Host::Managed.send :include, ContentHost
::Host::Managed.send :include, Content::HostExtensions
end

@@ -48,0 +39,0 @@ end

module Content
VERSION = "0.1"
VERSION = "0.2"
end
module Content
module CustomRepositoryPaths
def repo_path_from_content_path(environment, content_path)
content_path = content_path.sub(/^\//, "")
path_prefix = [environment.organization.label, environment.label].join("/")
"#{path_prefix}/#{content_path}"
end
# repo path for custom product repos (RH repo paths are derived from
# content url)
def custom_repo_path(org_label, environment_label, product_label, repo_label)
prefix = [org_label, environment_label].map { |x| x.gsub(/[^-\w]/, "_") }.join("/")
prefix + custom_content_path(product_label, repo_label)
end
def custom_content_path(product_label, repo_label)
parts = []
# We generate repo path only for custom product content. We add this
# constant string to avoid collisions with RH content. RH content url
# begins usually with something like "/content/dist/rhel/...".
# There we prefix custom content/repo url with "/custom/..."
parts << "custom"
parts += [product_label, repo_label]
"/" + parts.map { |x| x.gsub(/[^-\w]/, "_") }.join("/")
end
end
end
module ContentEnvironment
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :environment_products, :dependent => :destroy, :uniq=>true, :class_name => 'Content::EnvironmentProduct'
has_many :products, :through => :environment_products, :class_name => 'Content::Product'
end
end
module InstanceMethods
end
end
module ContentHomeHelperPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :setting_options, :content_link
end
end
module InstanceMethods
# Adds a content link to the More menu
def setting_options_with_content_link
choices = setting_options_without_content_link
content_group =
[
[_('Products'), :"content/products"],
[_('Repositories'), :"content/repositories"],
[_('Gpg keys'), :"content/gpg_keys"]
]
choices.insert(3, [:divider], [:group, _("Content"), content_group])
end
end
end
module ContentHost
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :host_products, :dependent => :destroy, :uniq=>true,:foreign_key => :host_id, :class_name => 'Content::HostProduct'
has_many :products, :through => :host_products, :class_name => 'Content::Product'
scoped_search :in=>:products, :on=>:name, :complete_value => true, :rename => :product
alias_method_chain :params, :repositories
end
end
module InstanceMethods
# adds repository hash to ENC global parameters
def params_with_repositories
# convert all repos to a format that puppet create_resource with yumrepo can consume
repos = Hash[attached_repositories.map{ |repo| [repo.to_label, format_repo(repo)] }]
# adds a global parameter called repositories contain all repos
params_without_repositories.merge('repositories' => repos)
end
# product_ids from the os default and hostgroup.
def inherited_product_ids
products = []
products += operatingsystem.product_ids if operatingsystem
products += Content::HostgroupProduct.where(:hostgroup_id => hostgroup.path_ids).pluck(:product_id) if hostgroup_id
products.uniq
end
def all_product_ids
(inherited_product_ids + product_ids).uniq
end
def attached_repositories
Content::Repository.attached_to_host(self)
end
private
# convert a repository to a format that puppet create_resource with yumrepo can consume
def format_repo repo
{
'baseurl' => repo.full_path,
# yum repos have descr field but no name, if descr is empty use the repo name
'descr' => repo.description.blank? ? repo.name : repo.description,
'enabled' => repo.enabled ? '1': '0',
'gpgcheck' => !!repo.gpg_key ? '1': '0'
}
end
end
end
module ContentHostgroup
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :hostgroup_products, :dependent => :destroy, :uniq=>true, :class_name => 'Content::HostgroupProduct'
has_many :products, :through => :hostgroup_products, :class_name => 'Content::Product'
scoped_search :in=>:products, :on=>:name, :complete_value => true, :rename => :product
end
end
module InstanceMethods
def inherited_product_ids
Content::HostgroupProduct.where(:hostgroup_id => hostgroup.ancestor_ids).pluck(:product_id)
end
def all_product_ids
(inherited_product_ids + product_ids).uniq
end
end
end
module ContentOperatingsystem
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :operatingsystem_repositories, :dependent => :destroy, :uniq => true, :class_name => 'Content::OperatingsystemRepository'
has_many :repositories, :through => :operatingsystem_repositories, :class_name => 'Content::Repository'
has_many :product_operatingsystems, :dependent => :destroy, :uniq => true, :class_name => 'Content::ProductOperatingsystem'
has_many :products, :through => :product_operatingsystems, :class_name => 'Content::Product'
has_many :default_repositories, :through => :products, :source => :repositories, :class_name => 'Content::Repository'
end
end
module InstanceMethods
end
end
module ContentRedhat
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :medium_uri, :content_uri
end
end
module InstanceMethods
def medium_uri_with_content_uri host, url = nil
if url.nil? && (full_path = Content::Repository.available_for_host(host).kickstart.first.try(:full_path))
URI.parse(full_path)
else
medium_uri_without_content_uri(host, url)
end
end
# return an array of repositories for kickstart script as additional repos
# to the kickstart main repo, this list will typically include updates and epel
def repos host
host.attached_repositories.yum.map{ |repo| format_repo(repo) }
end
private
# convert a repository to a format that kickstart script can consume
def format_repo repo
{
:baseurl => repo.full_path,
:name => repo.to_label,
:description => repo.product.description,
:enabled => repo.enabled,
:gpgcheck => !!repo.gpg_key
}
end
end
end
module ContentTaxonomy
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :products, :through => :taxable_taxonomies, :source => :taxable, :source_type => 'Content::Product'
alias_method_chain :dup, :content_dup
end
end
module InstanceMethods
def dup_with_content_dup
new = dup_without_content_dup
new.products = products
new
end
end
end
require 'runcible'
class PulpConfiguration
def self.initialize_runcible
Runcible::Base.config = runcible_config
end
def self.runcible_config
pulp_url = URI(Setting.pulp_url)
{
:url => "#{pulp_url.scheme}://#{pulp_url.host}:#{pulp_url.port}",
:api_path => pulp_url.path,
:user => "admin",
:timeout => 60,
:open_timeout => 60,
:oauth => { :oauth_secret => Setting['pulp_oauth_secret'],
:oauth_key => Setting['pulp_oauth_key'] },
:logging => { :logger => Rails.logger,
:exception => true,
:debug => true }
}
end
end