fix: Don't attempt a pull if the token requests fails

Change-type: patch
Closes: #879
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-02-04 17:50:26 +00:00
parent 93460d36b9
commit d8085a6ef8
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -60,3 +60,5 @@ export class ConfigurationValidationError extends TypedError {
);
}
}
export class ImageAuthenticationError extends TypedError {}