-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-2342] Charm Relation (i.e. 'external') Secrets #91
base: main
Are you sure you want to change the base?
Conversation
203c86e
to
11a9374
Compare
9e70a2a
to
c7a5d3f
Compare
11a9374
to
30c02e7
Compare
30c02e7
to
2674ffa
Compare
c7a5d3f
to
cb7dc4a
Compare
2674ffa
to
577ee22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks great! I think we are in the right path with this implementation.
About the cache, from what I could see, it will be restricted to the event lifetime only.
I left comments about other details.
63de4bd
to
e0c9efa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the direction that this implementation is taking! Abstracting away whether a relation data is stored in a secrets backend or in the relational databag is an excellent idea!
A couple of high level comments/questions I had after my first review were:
- SecretCache is not really a cache - it is a wrapper around a Secret in a Juju secrets backend
- Should we allow the Requires application to decide which fields are
SECRET_FIELDS
instead of hardcoding them? (and fallback to the hardcoded value if they are not specified?) -> this will allow users to specify all the fields that they want as secrets
SecretCache: Your point is valid, it is
The point is that, once you fetch a secret via a SecretCache object, it won't be fetched again within the same event scope. (I may need to polish up a code, there could be errors on this still :-) ) |
e0c9efa
to
99e4ca5
Compare
99e4ca5
to
c3e2a57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a flood of small nits/questions
7481a42
to
1a81c55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing some of the secret context, but could follow the implementation. Overall looking good, my nits are well represented by other reviews
ec4c19c
to
f2b8bc9
Compare
f2b8bc9
to
8ba180c
Compare
8ba180c
to
96d890d
Compare
DON'T USE the encapsulated helper variable outside of this function | ||
""" | ||
if not hasattr(self, "_cached_jujuversion"): | ||
self._cached_jujuversion = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, I can add this init() function:
def __init__(self, handle: Handle, relation: Relation, app: Optional[Application] = None, unit: Optional[Unit] = None):
super().__init__(handle, relation, app, unit)
self._cached_jujuversion = None
self._cached_secrets = None
...and then copy this into 6 --currently very pretty, one-liner-- descendant classes:
def __init__(self, handle: Handle, relation: Relation, app: Optional[Application] = None, unit: Optional[Unit] = None):
super().__init__(handle, relation, app, unit)
...but this is so ugly, that it doesn't even feel right -- just for two internal helper variables, that aren't supposed to be used outside of their encapsulated scope.... That I'd rather go with the technically less safe, but in another sense still more elegant solution. As instructions on the property functions clearly indicate: the helper variabes are meant to be encapsulated inside, noone should refer to them otherwise.
Anyway, if strong feelings on the other side, I can go for the __init__()
solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less ugly?
self._cached_jujuversion = None | |
if not hasattr(self, "_cached_jujuversion") or not self._cached_jujuversion: | |
self._cached_jujuversion = JujuVersion.from_environ() |
@@ -934,6 +981,11 @@ def tls(self) -> Optional[str]: | |||
if not self.relation.app: | |||
return None | |||
|
|||
if self.secrets_enabled: | |||
secret = self._get_secret("tls") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (use walrus):
if secret := self._get_secret("tls"):
return secret.get("tls")
@@ -331,6 +334,33 @@ def _on_topic_requested(self, event: TopicRequestedEvent): | |||
deleted - key that were deleted""" | |||
|
|||
|
|||
# Local map to associate labels with secrets potentially as a group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CRITICAL] Increase LIBVERSION
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@juditnovak is this PR still revelant? if not, should we close? |
Disclaimer
Here we introduce Relations Secrets on top of the existing
data_interfaces
logic.New interfaces:
get_relation_secret_data()
(Provides
,Requires
)set_relation_secret_fields()
(Provides
)get_relation_secret_fields()
,get_relation_secret_fields()
(Requires
)POC demo of usage demonstrated on Opensearch: canonical/opensearch-operator#116