Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(provider/docker): Only log trailing whitespace warning during failure #1973

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DockerBearerTokenService {
String username
String password
File passwordFile
String authWarning

final static String userAgent = DockerUserAgent.getUserAgent()

Expand Down Expand Up @@ -70,11 +71,11 @@ class DockerBearerTokenService {
if (resolvedPassword?.length() > 0) {
def message = "Your registry password has %s whitespace, if this is unintentional authentication will fail."
if (resolvedPassword.charAt(0).isWhitespace()) {
log.warn sprintf(message, ["leading"])
authWarning = sprintf(message, ["leading"])
}

if (resolvedPassword.charAt(resolvedPassword.length() - 1).isWhitespace()) {
log.warn sprintf(message, ["trailing"])
authWarning = sprintf(message, ["trailing"])
}
}

Expand Down Expand Up @@ -192,11 +193,18 @@ class DockerBearerTokenService {

def tokenService = getTokenService(authenticateDetails.realm)
def token
if (basicAuthHeader) {
token = tokenService.getToken(authenticateDetails.path, authenticateDetails.service, authenticateDetails.scope, basicAuthHeader, userAgent)
}
else {
token = tokenService.getToken(authenticateDetails.path, authenticateDetails.service, authenticateDetails.scope, userAgent)
try {
if (basicAuthHeader) {
token = tokenService.getToken(authenticateDetails.path, authenticateDetails.service, authenticateDetails.scope, basicAuthHeader, userAgent)
} else {
token = tokenService.getToken(authenticateDetails.path, authenticateDetails.service, authenticateDetails.scope, userAgent)
}
} catch (Exception e) {
if (authWarning) {
throw new DockerRegistryAuthenticationException("Authentication failed ($authWarning): ${e.getMessage()}", e)
} else {
throw new DockerRegistryAuthenticationException("Authentication failed: ${e.getMessage()}", e)
}
}

cachedTokens[repository] = token
Expand Down