Files
shields/services/docker/docker-cloud-common-fetch.js
chris48s 880c1fb49c call [docker] with auth (#9803)
* allow user to set dockerhub credentials

* add withJwtAuth function to AuthHelper

* use withJwtAuth in DockerHub badges

* add unit tests for JWT auth

* use auth when calling docker cloud

* refactor and assert fetch helpers call withJwtAuth

* store token for a max duration (defaults to 1 hour)

* tangent: update test example
2023-12-31 14:55:18 +00:00

29 lines
687 B
JavaScript

import Joi from 'joi'
const cloudBuildSchema = Joi.object({
objects: Joi.array()
.items(
Joi.object({
state: Joi.string(),
build_settings: Joi.array(),
}),
)
.required(),
}).required()
async function fetchBuild(serviceInstance, { user, repo }) {
return serviceInstance._requestJson(
await serviceInstance.authHelper.withJwtAuth(
{
schema: cloudBuildSchema,
url: 'https://cloud.docker.com/api/build/v1/source',
options: { searchParams: { image: `${user}/${repo}` } },
httpErrors: { 404: 'repo not found' },
},
'https://hub.docker.com/v2/users/login/',
),
)
}
export { fetchBuild }