Class: Registration::UrlHelpers

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n
Includes:
Yast::Logger
Defined in:
src/lib/registration/url_helpers.rb

Constant Summary collapse

BOOT_PARAM =

name of the boot parameter

"reg_url".freeze
SLP_SERVICE =

SLP service name

"registration.suse".freeze

Class Method Summary collapse

Class Method Details

.boot_reg_urlString?

Returns the boot command line parameter.

Returns:

  • (String, nil)

    the boot command line parameter


186
187
188
189
190
191
# File 'src/lib/registration/url_helpers.rb', line 186

def self.boot_reg_url
  reg_url = Yast::Linuxrc.InstallInf("regurl")
  log.info "Boot regurl option: #{reg_url.inspect}"

  reg_url
end

.credentials_from_url(url) ⇒ String

Returns "credentials" parameter from URL.

Parameters:

  • url (String)

    URL as string

Returns:

  • (String)

    "credentials" parameter from URL

Raises:

  • (URI::InvalidURIError)

    if URL is invalid


105
106
107
108
109
110
# File 'src/lib/registration/url_helpers.rb', line 105

def self.credentials_from_url(url)
  parsed_url = URI(url)
  params = Hash[URI.decode_www_form(parsed_url.query)]

  params["credentials"]
end

.reg_url_from_autoyast_configString, ...

get registration URL from AutoYaST configuration file

Returns:

  • (String, nil, Symbol)

    registration URL, nil means use the default, :cancel means that the user aborted the selection


128
129
130
131
132
# File 'src/lib/registration/url_helpers.rb', line 128

def self.reg_url_from_autoyast_config
  server = ::Registration::Storage::Config.instance.reg_server
  return server if server && !server.empty?
  SUSE::Connect::YaST::DEFAULT_URL
end

.registration_urlString, ...

Evaluate the registration URL to use for details

Returns:

  • (String, nil, Symbol)

    registration URL, nil means use the default, :cancel means that the user aborted the selection

See Also:


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'src/lib/registration/url_helpers.rb', line 56

def self.registration_url
  # cache the URL to use the same server for all operations
  cache = ::Registration::Storage::Cache.instance
  return cache.reg_url if cache.reg_url_cached

  log.info "Evaluating the registration URL in #{Yast::Mode.mode.inspect} mode"

  url = case Yast::Mode.mode
  when "installation"
    reg_url_at_installation
  when "normal"
    reg_url_at_running_system
  when "update"
    reg_url_at_upgrade
  when "autoupgrade", "autoinstallation"
    reg_url_from_autoyast_config
  else
    log.warn "Unknown mode: #{Yast::Mode.mode}, using default URL"
    # use the default
    nil
  end

  # SLP selection canceled, do not cache it
  return url if url == :cancel

  # cache the URL
  cache.reg_url = url
  cache.reg_url_cached = true
  url
end

.reset_registration_urlvoid

This method returns an undefined value.


88
89
90
91
# File 'src/lib/registration/url_helpers.rb', line 88

def self.reset_registration_url
  ::Registration::Storage::Cache.instance.reg_url = nil
  ::Registration::Storage::Cache.instance.reg_url_cached = false
end

.service_url(service) ⇒ String

convert service URL to plain URL, remove the SLP service prefix "service:registration.suse:smt:https://scc.suse.com/connect" -> "https://scc.suse.com/connect"

Parameters:

  • service (String)

Returns:

  • (String)

98
99
100
# File 'src/lib/registration/url_helpers.rb', line 98

def self.service_url(service)
  service.sub(/\Aservice:#{Regexp.escape(SLP_SERVICE)}:[^:]+:/, "")
end

.slp_discoveryArray<Yast::SlpServiceClass::Service>

Returns:

  • (Array<Yast::SlpServiceClass::Service>)

206
207
208
209
210
211
212
213
214
215
216
# File 'src/lib/registration/url_helpers.rb', line 206

def self.slp_discovery
  log.info "Searching for #{SLP_SERVICE} SLP services"
  services = Yast::SlpService.all(SLP_SERVICE)
  log.debug "Found services: #{services.inspect}"

  # ignore SUSE manager registration servers (bnc#894470)
  services.reject! { |service| service.slp_url.start_with?("service:#{SLP_SERVICE}:manager:") }

  log.info "Found #{services.size} services: #{services.map(&:slp_url).inspect}"
  services
end

.slp_discovery_feedbackArray<Yast::SlpServiceClass::Service>

Returns:

  • (Array<Yast::SlpServiceClass::Service>)

219
220
221
222
223
# File 'src/lib/registration/url_helpers.rb', line 219

def self.slp_discovery_feedback
  Yast::Popup.Feedback(_("Searching..."), _("Looking up local registration servers...")) do
    slp_discovery
  end
end

.slp_service_urlString, ...

Returns registration URL, nil means use the default, :cancel means that the user aborted the selection.

Returns:

  • (String, nil, Symbol)

    registration URL, nil means use the default, :cancel means that the user aborted the selection


197
198
199
200
201
202
203
# File 'src/lib/registration/url_helpers.rb', line 197

def self.slp_service_url
  log.info "Starting SLP discovery..."
  url = Yast::WFM.call("discover_registration_services")
  log.info "Selected SLP service: #{url.inspect}"

  url
end