Skip to content

Commit

Permalink
ApiPolicySource: Log errors in bundle init/update before retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
roekatz committed Sep 20, 2023
1 parent c68e0d1 commit 7102de0
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions packages/opal-common/opal_common/sources/api_policy_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,51 @@ async def get_initial_policy_state_from_remote(self):
"""init remote data to local repo."""
async for attempt in AsyncRetrying(wait=wait_fixed(5)):
with attempt:
await self.fetch_policy_bundle_from_api_source(
self.remote_source_url, self.token
)
self.local_git = self.tar_to_git.create_local_git()
try:
await self.fetch_policy_bundle_from_api_source(
self.remote_source_url, self.token
)
self.local_git = self.tar_to_git.create_local_git()
except Exception:
logger.exception(
"Failed to load initial policy from remote API bundle server"
)
raise

async def api_update_policy(self) -> Tuple[bool, str, str]:
async for attempt in AsyncRetrying(wait=wait_fixed(5)):
with attempt:
(
tmp_bundle_path,
prev_version,
current_hash,
) = await self.fetch_policy_bundle_from_api_source(
self.remote_source_url, self.token
)
if tmp_bundle_path and prev_version and current_hash:
commit_msg = f"new version {current_hash}"
try:
(
self.local_git,
prev_commit,
new_commit,
) = self.tar_to_git.extract_bundle_to_local_git(
commit_msg=commit_msg
)
return (
True,
tmp_bundle_path,
prev_version,
current_hash,
prev_commit,
new_commit,
) = await self.fetch_policy_bundle_from_api_source(
self.remote_source_url, self.token
)
if tmp_bundle_path and prev_version and current_hash:
commit_msg = f"new version {current_hash}"
(
self.local_git,
prev_commit,
new_commit,
) = self.tar_to_git.extract_bundle_to_local_git(
commit_msg=commit_msg
)
return (
True,
prev_version,
current_hash,
prev_commit,
new_commit,
)
else:
return False, None, current_hash, None, None
except Exception as e:
logger.exception(
f"Failed to update policy from remote API bundle server"
)
else:
return False, None, current_hash, None, None
raise

def build_auth_headers(self, token=None, path=None):
# if it's a simple HTTP server with a bearer token
Expand Down

0 comments on commit 7102de0

Please sign in to comment.