Skip to content

Commit

Permalink
fix: check if setup was a success
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderMatt committed Sep 16, 2024
1 parent 6efe076 commit 16cd857
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/operator/harbor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const HarborGroupType = {
}

let lastState: DependencyState = {}
let setupSuccess = false
const errors: string[] = []
const systemRobot: any = {
name: 'harbor',
Expand Down Expand Up @@ -218,11 +219,17 @@ async function checkAndExecute() {
await setupHarbor()
}

if (currentState.teamNames && currentState.teamNames.length > 0 && currentState.teamNames !== lastState.teamNames) {
if (!setupSuccess) await setupHarbor()

if (
setupSuccess &&
currentState.teamNames &&
currentState.teamNames.length > 0 &&
currentState.teamNames !== lastState.teamNames
) {
await Promise.all(currentState.teamNames.map((namespace) => processNamespace(`team-${namespace}`)))
lastState = { ...currentState }
}

lastState = { ...currentState }
}

async function runSetupHarbor() {
Expand Down Expand Up @@ -265,14 +272,18 @@ async function setupHarbor() {
self_registration: false,
}

const bearerAuth = await getBearerToken()
robotApi.setDefaultAuthentication(bearerAuth)
configureApi.setDefaultAuthentication(bearerAuth)
projectsApi.setDefaultAuthentication(bearerAuth)
memberApi.setDefaultAuthentication(bearerAuth)

await doApiCall(errors, 'Putting Harbor configuration', () => configureApi.configurationsPut(config))
handleErrors(errors)
try {
const bearerAuth = await getBearerToken()
robotApi.setDefaultAuthentication(bearerAuth)
configureApi.setDefaultAuthentication(bearerAuth)
projectsApi.setDefaultAuthentication(bearerAuth)
memberApi.setDefaultAuthentication(bearerAuth)
await doApiCall(errors, 'Putting Harbor configuration', () => configureApi.configurationsPut(config))
if (errors.length > 0) handleErrors(errors)
setupSuccess = true
} catch (error) {
console.debug('Failed to set bearer Token for Harbor Api :', error)
}
}

/**
Expand Down

0 comments on commit 16cd857

Please sign in to comment.