Skip to content

Commit

Permalink
Add retention rules (#13)
Browse files Browse the repository at this point in the history
* added retention policy synchronization

* reformatted client calls to keep within maxiumum line length

* removed whitespace line

* removed unneeded error name
  • Loading branch information
peters-david authored Jul 10, 2024
1 parent 4a30d89 commit bd5f73d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 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,41 @@ 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:
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_policy_to_update
)
# Create retention policies
for retention_policy_to_create in retention_policies_to_create:
await client.create_retention_policy(retention_policy_to_create)


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

0 comments on commit bd5f73d

Please sign in to comment.