Skip to content

Commit

Permalink
Do not export registered add-ons
Browse files Browse the repository at this point in the history
* They should liste in the <suse_register/> section.
  • Loading branch information
imobachgs committed Jul 15, 2020
1 parent 184ec0e commit fc5da62
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions src/modules/AddOnOthers.rb
Expand Up @@ -58,18 +58,65 @@ def Read
# </add_on_others>
# </add-on>
def Export
others = @add_on_others.map do |p|
{ "media_url" => p["url"],
"alias" => p["alias"],
"priority" => p["priority"],
"name" => p["name"],
"product_dir" => p["product_dir"] }
others = @add_on_others.each_with_object([]) do |addon, all|
next if registered_addon?(addon)

all << {
"media_url" => addon["url"],
"alias" => addon["alias"],
"priority" => addon["priority"],
"name" => addon["name"],
"product_dir" => addon["product_dir"]
}
end
{ "add_on_others" => others }
end

publish function: :Export, type: "map ()"
publish function: :Read, type: "map()"

private

# Determine whether an addon corresponds to a registered product
#
# @param addon [Hash] Addon data
# @return [Boolean]
def registered_addon?(addon)
return false unless addon["url"]

url = normalize_url(addon["url"])
registered_repositories_urls.include?(url)
end

# Returns the URLs corresponding to registered products repositories
#
# @return [Array<URI>]
def registered_repositories_urls
return @registered_repositories_urls if @registered_repositories_urls

begin
require "suse/connect"
rescue LoadError
[]
end
status = SUSE::Connect::YaST.status({})
repositories = status.activated_products.map(&:repositories).flatten
@registered_repositories_urls = repositories.map { |r| normalize_url(r["url"]) }
end

# Normalizes the URL to make the comparison easier
#
# It removes the query, the fragment and the trailing '/' character is found.
#
# @param url [URI,String] URL to normalize
# @return [URI]
def normalize_url(url)
uri = URI(url)
uri.fragment = nil
uri.query = nil
uri.path = uri.delete_suffix("/")
uri
end
end

AddOnOthers = AddOnOthersClass.new
Expand Down

0 comments on commit fc5da62

Please sign in to comment.