Skip to content

Commit

Permalink
moved granting secrets to opensearch_secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
skourta committed Oct 21, 2024
1 parent 14dcd4a commit e4d2229
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,13 @@ def _grant_rel_data_secrets(
"""Grant the secrets to all the related apps."""
credentials = rel_data_secret_content["credentials"]
for key, secret_id in credentials.items():
# s3 and admin-username are not secrets
# admin-username is not secrets
if key == "admin_username":
continue

secret = self.model.get_secret(id=secret_id)
for rel_id in all_rel_ids:
if relation := self.get_rel(rel_id=rel_id):
secret.grant(relation)
self.secrets.grant_secret_to_relation(secret_id, relation)


class OpenSearchPeerClusterRequirer(OpenSearchPeerClusterRelation):
Expand Down
7 changes: 6 additions & 1 deletion lib/charms/opensearch/v0/opensearch_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Scope,
SecretCache,
)
from ops import JujuVersion, Secret, SecretNotFoundError
from ops import JujuVersion, Relation, Secret, SecretNotFoundError
from ops.charm import SecretChangedEvent
from ops.framework import Object
from overrides import override
Expand Down Expand Up @@ -373,3 +373,8 @@ def get_secret_id(self, scope: Scope, key: str) -> Optional[str]:
"""Get the secret ID from the cache."""
label = self.label(scope, key)
return self._charm.peers_data.get(scope, label)

def grant_secret_to_relation(self, secret_id: int, relation: Relation):
"""Grant a secret to a relation."""
secret = self._charm.model.get_secret(id=secret_id)
secret.grant(relation)

0 comments on commit e4d2229

Please sign in to comment.