Skip to content

Commit

Permalink
Better key add/change logging
Browse files Browse the repository at this point in the history
* Switch between added/changed in the log entry depending on the action
* Don't log a change/add if nothing was commited
  • Loading branch information
cvaroqui committed Mar 11, 2022
1 parent c363e5d commit b933b19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions opensvc/core/objects/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def _add_key(self, key, data):
data = "base64:"+bdecode(base64.urlsafe_b64encode(bencode(data)))
else:
data = "literal:"+data
self.set_multi(["data.%s=%s" % (key, data)])
self.log.info("configuration key '%s' added (%s)", key, print_size(len(data), compact=True, unit="b"))
applied = self.set_multi(["data.%s=%s" % (key, data)])
if len(applied) == 0:
return
did = "added" if self.running_action == "add" else "changed"
self.log.info("configuration key '%s' %s (%s)", key, did, print_size(len(data), compact=True, unit="b"))
# refresh if in use
self.postinstall(key)

Expand Down
7 changes: 5 additions & 2 deletions opensvc/core/objects/sec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def _add_key(self, key, data):
if data is None:
raise ex.Error("secret value can not be empty")
data = "crypt:"+base64.urlsafe_b64encode(self.encrypt(data, cluster_name="join", encode=True)).decode()
self.set_multi(["data.%s=%s" % (key, data)])
self.log.info("secret key '%s' added (%s)", key, print_size(len(data), compact=True, unit="b"))
applied = self.set_multi(["data.%s=%s" % (key, data)])
if len(applied) == 0:
return
did = "added" if self.running_action == "add" else "changed"
self.log.info("secret key '%s' %s (%s)", key, did, print_size(len(data), compact=True, unit="b"))
# refresh if in use
self.postinstall(key)

Expand Down

0 comments on commit b933b19

Please sign in to comment.