Skip to content

Commit

Permalink
Implement service retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed Jun 19, 2018
1 parent 73a6737 commit fdc44d1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/suse/connect/client.rb
Expand Up @@ -19,6 +19,8 @@ def initialize(config)
@config = config
@api = Api.new(@config)
log.debug "Merged options: #{@config}"

Dnf.config = config
end

# Announces the system, activates the product on SCC and adds the service to the system
Expand Down
19 changes: 19 additions & 0 deletions lib/suse/connect/dnf.rb
Expand Up @@ -51,6 +51,25 @@ def repositories
JSON.parse(helper_out, symbolize_names: true)
end

# Internal method that implements service refresh logic missing in dnf
def read_service(service_url)
connection = Connection.new(
service_url,
language: Dnf.config.language,
insecure: Dnf.config.insecure,
verify_callback: Dnf.config.verify_callback,
debug: Dnf.config.debug
)
auth = Class.new.extend(SUSE::Toolkit::Utilities).system_auth

uri = URI.parse(service_url)
request = Net::HTTP::Get.new(uri.path)
request['Authorization'] = auth
service_index = connection.http.request(request)
xml_doc = REXML::Document.new(service_index.body, compress_whitespace: [])
xml_doc.root.elements.map(&:to_hash)
end

def root_arg
"--installroot '#{SUSE::Connect::System.filesystem_root}' " if SUSE::Connect::System.filesystem_root
end
Expand Down
29 changes: 29 additions & 0 deletions spec/connect/dnf_spec.rb
Expand Up @@ -105,4 +105,33 @@
expect(subject.repositories.size).to eq 0
end
end

describe '.read_service' do
let(:service_name) { 'valid_service' }
let(:service_url) { 'http://example.com/access/service/666' }
let(:login) { 'login' }
let(:password) { 'password' }
let(:system_credentials) { Credentials.new(login, password, Credentials::GLOBAL_CREDENTIALS_FILE) }
let(:repo) do
{ alias: 'RES7',
autorefresh: 'true',
enabled: 'true',
name: 'RES7',
url: 'https://updates.suse.com/repo/$RCE/RES7/src?token' }
end

before do
allow(Dnf).to receive(:config).at_least(1).and_return(Config.new)
allow(Credentials).to receive(:read).with(Credentials::GLOBAL_CREDENTIALS_FILE).and_return(system_credentials)
stub_request(:get, "http://#{login}:#{password}@example.com/access/service/666")
.to_return(status: 200, body: File.read('spec/fixtures/service_response.xml'))
end

it 'returns a list of repositories' do
service = subject.read_service(service_url)
expect(service.size).to eq 2
expect(service.first).to eq repo
end
end

end
7 changes: 7 additions & 0 deletions spec/fixtures/service_response.xml
@@ -0,0 +1,7 @@
<repoindex ttl="86400">
<repo url="https://updates.suse.com/repo/$RCE/RES7/src?token"
alias="RES7" name="RES7" autorefresh="true" enabled="true"/>
<repo
url="https://updates.suse.com/repo/$RCE/RES7/x86_64?token"
alias="RES7" name="RES7" autorefresh="true" enabled="true"/>
</repoindex>

0 comments on commit fdc44d1

Please sign in to comment.