Skip to content

Commit

Permalink
Use refresh robot secret to set the robot secret (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
steadyk authored Jul 16, 2024
1 parent 24ec5be commit 117b163
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ async def construct_full_robot_name(target_robot: Robot) -> str:
return f'{robot_name_prefix}{target_robot["name"]}'


async def set_robot_secret(robot_name: str, robot_id: int):
secret = os.environ.get(
robot_name.upper().replace("-", "_")
)
if secret:
print(f'Set secret for {robot_name}')
await client.refresh_robot_secret(robot_id, secret)
else:
print(f'WARN: No secret found for {robot_name}')



async def sync_robot_accounts(target_robots: [Robot]):
# Get all system level robots
current_system_robots = await client.get_robots(
Expand Down Expand Up @@ -241,25 +253,25 @@ async def sync_robot_accounts(target_robots: [Robot]):
full_robot_name = await construct_full_robot_name(target_robot)
print(f'Full robot name: {full_robot_name}')
target_robot = Robot(**target_robot)
target_robot.secret = os.environ.get(
target_robot.name.upper().replace("-", "_")
)
# Modify existing robot
if full_robot_name in current_robot_names:
robot_id = current_robot_id[
current_robot_names.index(full_robot_name)
]
short_robot_name = target_robot.name
target_robot.name = full_robot_name
print(f'- Syncing robot "{target_robot.name}".')
await client.update_robot(robot_id=robot_id, robot=target_robot)
await set_robot_secret(short_robot_name, robot_id)
# Create new robot
else:
print(
"- Creating new robot"
f' "{full_robot_name}"'
)
try:
await client.create_robot(robot=target_robot)
created_robot = await client.create_robot(robot=target_robot)
await set_robot_secret(target_robot.name, created_robot.id)
except Conflict as e:
print(
f''' => "{full_robot_name}"
Expand Down

0 comments on commit 117b163

Please sign in to comment.