MCPcopy Create free account
hub / github.com/METR/vivaria / fetchAccessToken

Method fetchAccessToken

server/src/docker/docker.ts:369–395  ·  view source on GitHub ↗
(registryUrl: string)

Source from the content-addressed store, hash-verified

367 }
368
369 private async fetchAccessToken(registryUrl: string) {
370 if (registryUrl === 'registry.hub.docker.com') {
371 if (
372 this.cached_dockerhub_access_token != null &&
373 this.cached_dockerhub_access_token_expiry != null &&
374 Date.now() < this.cached_dockerhub_access_token_expiry
375 ) {
376 return this.cached_dockerhub_access_token
377 }
378 const login_response = await fetch(`https://${registryUrl}/v2/auth/token`, {
379 method: 'POST',
380 body: JSON.stringify({
381 identity: this.config.DOCKER_REGISTRY_IDENTITY,
382 secret: this.config.DOCKER_REGISTRY_TOKEN,
383 }),
384 })
385 if (!login_response.ok) {
386 throw new Error(`Failed to login to registry: ${login_response.statusText}`)
387 }
388 const { access_token } = (await login_response.json()) as { access_token: string }
389 this.cached_dockerhub_access_token = access_token
390 this.cached_dockerhub_access_token_expiry = Date.now() + 1000 * 60 * 5
391 return access_token
392 } else {
393 return this.config.DOCKER_REGISTRY_TOKEN
394 }
395 }
396}

Callers 1

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected