UNPKG

@iexec/iapp

Version:

A CLI to guide you through the process of building an iExec iApp

27 lines 1.04 kB
/** * get an authorization token to perform operations on a repository of the docker hub registry * * NB: delivered token expires after 5 mins */ export async function getAuthToken({ repository, action = 'pull,push', dockerhubUsername, dockerhubAccessToken, }) { const response = await fetch(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repository}:${action}`, { headers: { Authorization: `Basic ${Buffer.from(`${dockerhubUsername}:${dockerhubAccessToken}`).toString('base64')}`, }, }); if (!response.ok) { throw Error(`Fail to get authorization token for scope=${repository}:${action}`); } return response .json() .catch(() => { throw Error(`Unexpected response from dockerhub auth server`); }) .then(({ token }) => { if (!token) { throw Error(`Unexpected response from dockerhub auth server: Missing token`); } return token; }); } //# sourceMappingURL=dockerhub.js.map