Skip to content

Commit

Permalink
Merge branch 'develop' into fix/list-anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
m8vago authored Mar 20, 2024
2 parents 1f75a49 + cd09956 commit 12ac63b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class GithubRegistryClient implements RegistryApiClient {
async labels(image: string, tag: string): Promise<Record<string, string>> {
// NOTE(@robot9706): ghcr.io expects the accept manifest to be "v1" but it responds with v2 manifests
const labelClient = new V2Labels(
'ghcr.io',
REGISTRY_GITHUB_URL,
this.imageNamePrefix,
{
headers: this.basicAuthHeaders,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ export class GitlabRegistryClient implements RegistryApiClient {
}

async labels(image: string, tag: string): Promise<Record<string, string>> {
const labelClient = new V2Labels(this.urls.registryUrl, null, null, {
const labelClient = new V2Labels(this.urls.registryUrl, null, null, null, {
headers: this.basicAuthHeaders,
})

return labelClient.fetchLabels(image, tag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ export class GoogleRegistryClient implements RegistryApiClient {
await this.registryCredentialsToBearerAuth()
}

const labelClient = new V2Labels(this.url, {
const labelClient = new V2Labels(this.url, null, {
headers: {
Authorization: (this.headers as Record<string, string>).Authorization,
},
})

return labelClient.fetchLabels(image, tag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default abstract class HubApiClient {

async labels(image: string, tag: string): Promise<Record<string, string>> {
const labelClient = new V2Labels(DOCKER_HUB_REGISTRY_URL)

return labelClient.fetchLabels(this.prefix ? `${this.prefix}/${image}` : image, tag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default class PrivateHubApiClient extends HubApiClient implements Registr
}

async labels(image: string, tag: string): Promise<Record<string, string>> {
const labelClient = new V2Labels(DOCKER_HUB_REGISTRY_URL, null, null, this.labelsAuth)
const labelClient = new V2Labels(DOCKER_HUB_REGISTRY_URL, null, null, null, this.labelsAuth)

return labelClient.fetchLabels(this.prefix ? `${this.prefix}/${image}` : image, tag)
}
}
3 changes: 2 additions & 1 deletion web/crux/src/app/registry/registry-clients/v2-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class RegistryV2ApiClient implements RegistryApiClient {
}

async labels(image: string, tag: string): Promise<Record<string, string>> {
const labelClient = new V2Labels(this.url, {
const labelClient = new V2Labels(this.url, null, {
headers: this.headers,
})

return labelClient.fetchLabels(image, tag)
}

Expand Down
19 changes: 15 additions & 4 deletions web/crux/src/app/registry/registry-clients/v2-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export default class V2Labels {
private requestInit: RequestInit

constructor(
private baseUrl: string,
private readonly baseUrl: string,
private readonly imageNamePrefix?: string,
requestInit?: RequestInit,
manifestMime?: string,
private tokenInit?: RequestInit,
private readonly tokenInit?: RequestInit,
) {
this.requestInit = requestInit ?? {}
this.requestInit = {
Expand Down Expand Up @@ -130,17 +131,21 @@ export default class V2Labels {
const tokenService = params.service
const tokenScope = params.scope

const tokenInit = this.tokenInit ?? this.requestInit

const tokenUrl = `${tokenServer}?service=${encodeURIComponent(tokenService)}&scope=${encodeURIComponent(
tokenScope,
)}`

this.logger.debug(`Fetching token from '${tokenUrl}'`)

const tokenResponse = await fetch(tokenUrl, this.tokenInit)
const tokenResponse = await fetch(tokenUrl, tokenInit)

this.logger.debug(`Got token response for '${tokenUrl}' - ${tokenResponse.status}`)

if (tokenResponse.status !== 200) {
this.logger.error('V2 token fetch failed', tokenResponse.status, await tokenResponse.text())

throw new CruxInternalServerErrorException({
message: 'Failed to fetch V2 token',
})
Expand Down Expand Up @@ -206,6 +211,7 @@ export default class V2Labels {
return null
}

this.logger.error('V2 API fetch failed', result.res.status, result.data)
throw new CruxInternalServerErrorException({
message: 'Failed to fetch v2 API!',
})
Expand All @@ -214,7 +220,7 @@ export default class V2Labels {
return result.data
}

async fetchLabelsByManifest(
private async fetchLabelsByManifest(
image: string,
manifest: ManifestBaseResponse,
depth: number,
Expand Down Expand Up @@ -259,11 +265,16 @@ export default class V2Labels {
}

async fetchLabels(image: string, tag: string): Promise<Record<string, string>> {
if (this.imageNamePrefix) {
image = `${this.imageNamePrefix}/${image}`
}

const manifest = await this.fetchV2<ManifestBaseResponse>(`${image}/manifests/${tag ?? 'latest'}`, {
headers: {
Accept: this.manifestMimeType,
},
})

if (!manifest) {
return {}
}
Expand Down

0 comments on commit 12ac63b

Please sign in to comment.