Skip to content

Commit c639f71

Browse files
committed
Charmhub module to fetch host address from model config
1 parent 00cb2c0 commit c639f71

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

juju/bundle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ async def run(self, context):
619619
self.application, charm, overrides=self.resources)
620620
elif Schema.CHARM_HUB.matches(url.schema):
621621
c_hub = charmhub.CharmHub(context.model)
622-
id_, _ = c_hub.get_charm_id(url.name)
622+
id_, _ = await c_hub.get_charm_id(url.name)
623623
origin.id_ = id_
624624
resources = await context.model._add_charmhub_resources(
625625
self.application, charm, origin, overrides=self.resources)

juju/charmhub.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ def request_charmhub_with_retry(self, url, retries):
1818
jasyncio.sleep(5)
1919
raise JujuError("Got {} from {}".format(_response.status_code, url))
2020

21-
def get_charm_id(self, charm_name):
21+
async def get_charm_id(self, charm_name):
2222
conn, headers, path_prefix = self.model.connection().https_connection()
2323

24-
url = "https://api.snapcraft.io/v2/charms/info/{}".format(charm_name)
24+
model_conf = await self.model.get_config()
25+
charmhub_url = model_conf['charmhub-url']
26+
url = "{}/v2/charms/info/{}".format(charmhub_url.value, charm_name)
2527
_response = self.request_charmhub_with_retry(url, 5)
2628
response = json.loads(_response.text)
2729
return response['id'], response['name']
2830

29-
def is_subordinate(self, charm_name):
31+
async def is_subordinate(self, charm_name):
3032
conn, headers, path_prefix = self.model.connection().https_connection()
3133

32-
url = "https://api.snapcraft.io/v2/charms/info/{}?fields=default-release.revision.subordinate".format(charm_name)
34+
model_conf = await self.model.get_config()
35+
charmhub_url = model_conf['charmhub-url']
36+
url = "{}/v2/charms/info/{}?fields=default-release.revision.subordinate".format(charmhub_url.value, charm_name)
3337
_response = self.request_charmhub_with_retry(url, 5)
3438
response = json.loads(_response.text)
3539
return 'subordinate' in response['default-release']['revision']

0 commit comments

Comments
 (0)