Skip to content

Commit

Permalink
[xena] Ensure get_requests_for_local_unit doesn't fail on incomplete …
Browse files Browse the repository at this point in the history
…relation

This is a rebuild/make sync for charms to pickup the fix in charmhelpers to fix
any inadvertant accesses of ['ca'] in the relation data before it is available
from vault in the certificates relation.  Fix in charmhelpers is in [1].

[1] juju/charm-helpers#828
Closes-Bug: #2028683

Change-Id: I9981aad11d9372b29b0095f56d3f04c1471fe4b0
  • Loading branch information
ajkavanagh committed Aug 17, 2023
1 parent 9d69e71 commit 830835e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion charm-helpers-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
repo: https://github.com/juju/charm-helpers@stable/21.10
repo: https://github.com/juju/charm-helpers@stable/xena
destination: charmhelpers
include:
- core
Expand Down
33 changes: 21 additions & 12 deletions charmhelpers/contrib/openstack/cert_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,27 @@ def get_requests_for_local_unit(relation_name=None):
is_legacy_request = set(sent).intersection(legacy_keys)
for unit in related_units(rid):
data = relation_get(rid=rid, unit=unit)
if data.get(raw_certs_key):
bundles.append({
'ca': data['ca'],
'chain': data.get('chain'),
'certs': json.loads(data[raw_certs_key])})
elif is_legacy_request:
bundles.append({
'ca': data['ca'],
'chain': data.get('chain'),
'certs': {sent['common_name']:
{'cert': data.get(local_name + '.server.cert'),
'key': data.get(local_name + '.server.key')}}})
# Note: Bug#2028683 - data may not be available if the certificates
# relation hasn't been populated by the providing charm. If no 'ca'
# in the data then don't attempt the bundle at all.
if data.get('ca'):
if data.get(raw_certs_key):
bundles.append({
'ca': data['ca'],
'chain': data.get('chain'),
'certs': json.loads(data[raw_certs_key])
})
elif is_legacy_request:
bundles.append({
'ca': data['ca'],
'chain': data.get('chain'),
'certs': {
sent['common_name']: {
'cert': data.get(local_name + '.server.cert'),
'key': data.get(local_name + '.server.key')
}
}
})

return bundles

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ deps = -r{toxinidir}/requirements.txt
[testenv:pep8]
basepython = python3
deps = flake8==3.9.2
charm-tools==2.8.3
PyYAML==6.0.1
charm-tools==2.8.6
commands = flake8 {posargs} hooks unit_tests tests actions lib files
charm-proof

Expand Down

0 comments on commit 830835e

Please sign in to comment.