This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Implementation of ops requires side of aws interface #17
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93c25c6
Implementation of ops requires side of aws interface
addyess 08af76b
woke check
addyess ce433f4
drop python3.7, support 3.12
addyess a831c14
wrap metadata requests to catch HTTP failures
addyess 340a70c
docs string nits
addyess 49e8c6c
Apply docs and linting
addyess beed34f
When aws relation joins, print the metadata
addyess f5e061a
calculate expected hash by first unrolling json data, sorting by rela…
addyess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,14 +130,22 @@ def _joined(self, _): | |
self.instance_id, | ||
self.region, | ||
) | ||
self._to_publish["instance-id"] = self.instance_id | ||
self._to_publish["region"] = self.region | ||
self._request({"instance-id": self.instance_id, "region": self.region}) | ||
|
||
@property | ||
def is_ready(self): | ||
completed = json.loads(self._received.get("completed", "{}")) | ||
response_hash = completed.get(self.instance_id) | ||
return response_hash == self._expected_hash | ||
ready = response_hash == self._expected_hash | ||
if not response_hash: | ||
log.warning("Remote end is yet to calculate a response") | ||
elif not ready: | ||
log.warning( | ||
"Waiting for response_hash=%s to be self._expected_hash=%s", | ||
response_hash, | ||
self._expected_hash, | ||
) | ||
Comment on lines
+139
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some handy logging to figure out of the requires side has seen the correct hash yet. |
||
return ready | ||
|
||
def evaluate_relation(self, event) -> Optional[str]: | ||
"""Determine if relation is ready.""" | ||
|
@@ -168,9 +176,14 @@ def region(self): | |
|
||
@property | ||
def _expected_hash(self): | ||
return sha256( | ||
json.dumps(dict(self._to_publish), sort_keys=True).encode("utf8") | ||
).hexdigest() | ||
def from_json(s: str): | ||
try: | ||
return json.loads(s) | ||
except json.decoder.JSONDecodeError: | ||
return s | ||
|
||
Comment on lines
+179
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mateoflorido @eaudetcobello |
||
to_sha = {key: from_json(val) for key, val in self._to_publish.items()} | ||
return sha256(json.dumps(to_sha, sort_keys=True).encode()).hexdigest() | ||
|
||
def _request(self, keyvals): | ||
kwds = {key: json.dumps(val) for key, val in keyvals.items()} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
completed: '{"i-abcdefghijklmnopq": "1fca8013323a5aaa67a9a816ab1b910a2402165c198f8502c69d7c0b2a0546cf"}' | ||
completed: '{"i-abcdefghijklmnopq": "3577342edb3a0a9a4b6861b7d2f580f35db2709e92f3ddd17bb027eb85a2f670"}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
make sure this stuff gets encoded in json rather than just left to be a string.