Class: Katello::Util::CdnVarSubstitutor
- Inherits:
-
Object
- Object
- Katello::Util::CdnVarSubstitutor
- Defined in:
- app/lib/katello/util/cdn_var_substitutor.rb
Instance Attribute Summary collapse
-
#bad_listings ⇒ Object
readonly
Returns the value of attribute bad_listings.
-
#good_listings ⇒ Object
readonly
Returns the value of attribute good_listings.
Instance Method Summary collapse
- #any_valid_metadata_file?(repo_path) ⇒ Boolean
-
#initialize(cdn_resource) ⇒ CdnVarSubstitutor
constructor
cdn_resource - an object providing access to CDN.
-
#substitute_vars(path) ⇒ Object
takes path e.g.
- #validate_substitutions(content, substitutions) ⇒ Object
Constructor Details
#initialize(cdn_resource) ⇒ CdnVarSubstitutor
cdn_resource - an object providing access to CDN. It has to provide a get method that takes a path (e.g. /content/rhel/6.2/listing) and returns the body response)
9 10 11 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 9 def initialize(cdn_resource) @resource = cdn_resource end |
Instance Attribute Details
#bad_listings ⇒ Object (readonly)
Returns the value of attribute bad_listings.
5 6 7 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 5 def bad_listings @bad_listings end |
#good_listings ⇒ Object (readonly)
Returns the value of attribute good_listings.
4 5 6 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 4 def good_listings @good_listings end |
Instance Method Details
#any_valid_metadata_file?(repo_path) ⇒ Boolean
50 51 52 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 50 def (repo_path) ['repodata/repomd.xml', 'PULP_MANIFEST', '.treeinfo', 'treeinfo'].any? { |filename| @resource.valid_path?(repo_path, filename) } end |
#substitute_vars(path) ⇒ Object
takes path e.g. “/rhel/server/5/$releasever/$basearch/os” returns PathWithSubstitutions objects
{ {"releasever" => "6Server", "basearch" => "i386"} => "/rhel/server/5/6Server/i386/os",
{"releasever" => "6Server", "basearch" => "x86_64"} => "/rhel/server/5/6Server/x84_64/os"}
values are loaded from CDN
20 21 22 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 20 def substitute_vars(path) find_substitutions([PathWithSubstitutions.new(path, {})]) end |
#validate_substitutions(content, substitutions) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/lib/katello/util/cdn_var_substitutor.rb', line 24 def validate_substitutions(content, substitutions) path_with_subs = PathWithSubstitutions.new(content.content_url, substitutions) real_path = path_with_subs.apply_substitutions unused_substitutions = path_with_subs.unused_substitutions needed_substitutions = PathWithSubstitutions.new(real_path, {}).substitutions_needed if unused_substitutions.any? fail Errors::CdnSubstitutionError, _("%{unused_substitutions} cannot be specified for %{content_name}"\ " as that information is not substitutable in %{content_url} ") % { unused_substitutions: unused_substitutions.join(','), content_name: content.name, content_url: content.content_url } end if needed_substitutions.any? fail Errors::CdnSubstitutionError, _("Missing arguments %{substitutions} for %{content_url}") % { substitutions: needed_substitutions.join(','), content_url: real_path } end unless (real_path) @resource.log :error, "No valid metadata files found for #{real_path}" fail Errors::CdnSubstitutionError, _("The path %{real_path} does not seem to be a valid repository."\ " If you think this is an error, please try refreshing your manifest.") % {real_path: real_path} end end |