Skip to content

Commit

Permalink
added retention policy synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
peters-david committed May 2, 2024
1 parent c0b1c5f commit 50532d5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
WebhookPolicy,
Project,
ProjectMemberEntity,
RetentionPolicy,
)
import argparse
import json
Expand Down Expand Up @@ -105,6 +106,33 @@ async def main() -> None:
await sync_webhook(**webhook)
print("")

# Sync retention policies
print('SYNCING RETENTION POLICIES')
retention_policies_config = json.load(open(config_folder_path + "/retention-policies.json"))
await sync_retention_policies(retention_policies=retention_policies_config)


async def sync_retention_policies(retention_policies: [RetentionPolicy]):
retention_policies_to_update = []
retention_policies_to_create = []
# Check for existing retention policies
for retention_policy in retention_policies:
retention_id = retention_policy.id
try:
current_retention_policy = await client.get_retention_policy(retention_id)
if retention_policy != current_retention_policy:
retention_policies_to_update.append(retention_policy)
except NotFound e:
retention_policies_to_create.append(retention_policy)
# Update retention policies
for retention_policy_to_update in retention_policies_to_update:
retention_id = retention_policy_to_update.id
await client.update_retention_policy(retention_id, retention_policies_to_update)
# Create retention policies
for retention_policy_to_create in retention_policies_to_create:
await client.update_retention_policy(retention_policies_to_update)



async def sync_harbor_config(harbor_config: Configurations):
await client.update_config(harbor_config)
Expand Down

0 comments on commit 50532d5

Please sign in to comment.