Skip to content

Commit

Permalink
Merge pull request #1301 from candlepin/alikins/1168268_ostee_proxy_i…
Browse files Browse the repository at this point in the history
…n_repo

1168268: Add rhsm.conf proxy info to ostree repo
  • Loading branch information
wottop committed Sep 22, 2015
2 parents 203e8bb + e58e8bd commit 891ff19
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
30 changes: 29 additions & 1 deletion src/subscription_manager/plugin/ostree/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ def clear_remotes(self):
def set(self, section, key, value):
return self.config_parser.set(section, key, value)

def get_proxy(self):
proxy_host = CFG.get('server', 'proxy_hostname')
# proxy_port as string is fine here
proxy_port = CFG.get('server', 'proxy_port')
proxy_user = CFG.get('server', 'proxy_user')
proxy_password = CFG.get('server', 'proxy_password')

proxy_uri = None
if proxy_host == "":
return proxy_uri

proxy_auth = ""
if proxy_user != "" and proxy_password != "":
proxy_auth = "%s:%s@" % (proxy_user, proxy_password)

# TODO: does libsoup want all proxies to be 'http'
proxy_uri = "http://%s%s" % (proxy_auth, proxy_host)

if proxy_port != "":
proxy_uri = "%s:%s" % (proxy_uri, proxy_port)

return proxy_uri
# These could be empty string, in which case they will not be
# set in the yum repo file:

def set_remote(self, ostree_remote):
"""Add a remote section to config file based on a OstreeRemote."""
# format section name
Expand All @@ -196,7 +221,6 @@ def set_remote(self, ostree_remote):
ca_cert = CFG.get('rhsm', 'repo_ca_cert')

full_url = utils.url_base_join(baseurl, ostree_remote.url)
log.debug("full_url: %s" % full_url)

self.set(section_name, 'url', full_url)

Expand All @@ -216,6 +240,10 @@ def set_remote(self, ostree_remote):
# support multiple CDNInfos setup.
self.set(section_name, 'tls-ca-path', ca_cert)

proxy_uri = self.get_proxy()
if proxy_uri:
self.set(section_name, 'proxy', proxy_uri)

def set_core(self, ostree_core):
# Assuming we don't need to check validy of any [core] values
# update the core section with the current values
Expand Down
12 changes: 10 additions & 2 deletions src/subscription_manager/plugin/ostree/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ def tls_ca_path(self):
def tls_ca_path(self, value):
self.data['tls_ca_path'] = value

@property
def proxy(self):
return self.data.get('proxy')

@proxy.setter
def proxy(self, value):
self.data['proxy'] = value

@classmethod
def from_config_section(cls, section, items):
"""Create a OstreeRemote object from a repo config section name and map of items.
Expand Down Expand Up @@ -235,9 +243,9 @@ def map_gpg(content):

def __repr__(self):
r = super(OstreeRemote, self).__repr__()
template = "%s\n (name=%s\n url=%s\n gpg_verify=%s\n tls_client_cert_path=%s\n tls_client_key_path=%s)"
template = "%s\n (name=%s\n url=%s\n gpg_verify=%s\n tls_client_cert_path=%s\n tls_client_key_path=%s\n proxy=%s)"
return template % (r, self.name, self.url, self.gpg_verify,
self.tls_client_cert_path, self.tls_client_key_path)
self.tls_client_cert_path, self.tls_client_key_path, self.proxy)

def report(self):
return self.report_template.format(self=self)
Expand Down
8 changes: 4 additions & 4 deletions test/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
insecure = 1
ssl_verify_depth = 3
ca_cert_dir = /etc/rhsm/ca/
proxy_hostname =
proxy_port =
proxy_user =
proxy_password =
proxy_hostname = notaproxy.grimlock.usersys.redhat.com
proxy_port = 3128
proxy_user = proxy_user
proxy_password = proxy_password
[rhsm]
baseurl= https://content.example.com
Expand Down
18 changes: 18 additions & 0 deletions test/test_ostree_content_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,24 @@ def test_section_set_remote(self, mock_get_config_parser):

rf.set_remote(remote)

expected_proxy = "http://proxy_user:proxy_password@notaproxy.grimlock.usersys.redhat.com:3128"
repo_proxy_uri = rf.config_parser.get('remote "awesomeos-remote"', 'proxy')
self.assertEquals(expected_proxy, repo_proxy_uri)

@mock.patch('subscription_manager.plugin.ostree.config.RepoFile._get_config_parser')
def section_set_remote(self, mock_get_config_parser):
mock_get_config_parser.return_value = self._rf_cfg()
rf = config.RepoFile('')

remote = model.OstreeRemote()
remote.url = "/some/path"
remote.name = "awesomeos-remote"
remote.gpg_verify = 'true'
remote.tls_client_cert_path = "/etc/pki/entitlement/54321.pem"
remote.tls_client_key_path = "/etc/pki/entitlement/54321-key.pem"

rf.set_remote(remote)


class TestOstreeRepoFileNoRemote(BaseOstreeRepoFileTest):
repo_cfg = """
Expand Down

0 comments on commit 891ff19

Please sign in to comment.