Skip to content

Commit

Permalink
refactor(docker): replace www-authenticate with auth-header (#11942)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Oct 1, 2021
1 parent 02f7253 commit 41bafac
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 497 deletions.
10 changes: 6 additions & 4 deletions lib/datasource/docker/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ECR, ECRClientConfig } from '@aws-sdk/client-ecr';
import is from '@sindresorhus/is';
import { parse } from 'auth-header';
import hasha from 'hasha';
import wwwAuthenticate from 'www-authenticate';
import { HOST_DISABLED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { HostRule } from '../../types';
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function getAuthHeaders(
return null;
}

const authenticateHeader = new wwwAuthenticate.parsers.WWW_Authenticate(
const authenticateHeader = parse(
apiCheckResponse.headers['www-authenticate']
);

Expand Down Expand Up @@ -127,7 +127,9 @@ export async function getAuthHeaders(
// * www-authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"
if (
authenticateHeader.scheme.toUpperCase() !== 'BEARER' ||
parseUrl(authenticateHeader.parms.realm) == null
!is.string(authenticateHeader.params.realm) ||
!is.string(authenticateHeader.params.service) ||
parseUrl(authenticateHeader.params.realm) === null
) {
logger.trace(
{ registryHost, dockerRepository, authenticateHeader },
Expand All @@ -136,7 +138,7 @@ export async function getAuthHeaders(
return opts.headers;
}

const authUrl = `${authenticateHeader.parms.realm}?service=${authenticateHeader.parms.service}&scope=repository:${dockerRepository}:pull`;
const authUrl = `${authenticateHeader.params.realm}?service=${authenticateHeader.params.service}&scope=repository:${dockerRepository}:pull`;
logger.trace(
{ registryHost, dockerRepository, authUrl },
`Obtaining docker registry token`
Expand Down
1 change: 0 additions & 1 deletion lib/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { getTagsQuayRegistry } from './quay';

// TODO: add got typings when available (#9646)
// TODO: replace www-authenticate with https://www.npmjs.com/package/auth-header (#9645)

export { id };
export const customRegistrySupport = true;
Expand Down
18 changes: 0 additions & 18 deletions lib/types/www-authenticate.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"@sindresorhus/is": "4.2.0",
"@yarnpkg/core": "2.4.0",
"@yarnpkg/parsers": "2.4.0",
"auth-header": "1.0.0",
"azure-devops-node-api": "11.0.1",
"bunyan": "1.8.15",
"cacache": "15.3.0",
Expand Down Expand Up @@ -192,7 +193,6 @@
"upath": "2.0.1",
"url-join": "4.0.1",
"validate-npm-package-name": "3.0.0",
"www-authenticate": "0.6.2",
"xmldoc": "1.1.2"
},
"optionalDependencies": {
Expand All @@ -206,6 +206,7 @@
"@ls-lint/ls-lint": "1.10.0",
"@renovate/eslint-plugin": "https://github.com/renovatebot/eslint-plugin#v0.0.3",
"@semantic-release/exec": "6.0.1",
"@types/auth-header": "1.0.2",
"@types/bunyan": "1.8.7",
"@types/cacache": "15.0.1",
"@types/changelog-filename-regex": "2.0.0",
Expand Down

0 comments on commit 41bafac

Please sign in to comment.