From d8085a6ef896ff7b63ee295765031829eb07de2b Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Mon, 4 Feb 2019 17:50:26 +0000 Subject: [PATCH] fix: Don't attempt a pull if the token requests fails Change-type: patch Closes: #879 Signed-off-by: Cameron Diver --- src/lib/docker-utils.ts | 14 ++++++++------ src/lib/errors.ts | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib/docker-utils.ts b/src/lib/docker-utils.ts index 9a769424..98b4b282 100644 --- a/src/lib/docker-utils.ts +++ b/src/lib/docker-utils.ts @@ -11,6 +11,7 @@ import { DeltaStillProcessingError, InternalInconsistencyError, InvalidNetGatewayError, + ImageAuthenticationError, } from './errors'; import { request, requestLib, resumable } from './request'; import { EnvVarObject } from './types'; @@ -113,17 +114,18 @@ export class DockerUtils extends DockerToolbelt { const tokenResponseBody = (await request.getAsync(tokenUrl, tokenOpts))[1]; const token = tokenResponseBody != null ? tokenResponseBody.token : null; + if (token == null) { + throw new ImageAuthenticationError(); + } + const opts: requestLib.CoreOptions = { followRedirect: false, timeout: deltaOpts.deltaRequestTimeout, - }; - - if (token != null) { - opts.auth = { + auth: { bearer: token, sendImmediately: true, - }; - } + }, + }; const url = `${deltaOpts.deltaEndpoint}/api/v${ deltaOpts.deltaVersion diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 70802261..4abcd168 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -60,3 +60,5 @@ export class ConfigurationValidationError extends TypedError { ); } } + +export class ImageAuthenticationError extends TypedError {}