public ObjectNode buildAuthsObject() throws IOException { ObjectNode auths = MAPPER.createObjectNode(); for (ResolvedDockerRegistryEndpoint endpoint : this.endpoints) { DockerRegistryToken token = endpoint.getToken(); ObjectNode entry = MAPPER.createObjectNode() .put("email", token.getEmail()) .put("auth", token.getToken()); auths.set(endpoint.getUrl().toString(), entry); } return auths; } }
@Nonnull @Override public DockerRegistryToken convert(@Nonnull DockerRegistryAuthCredentials c) throws AuthenticationTokenException { return new DockerRegistryToken(c.getEmail(), Base64.encodeBase64String((c.getUsername() + ":" + c.getPassword().getPlainText()) .getBytes(Charsets.UTF_8))); } }
/** * @deprecated Call {@link #newKeyMaterialFactory(URL, VirtualChannel, Launcher, TaskListener)} */ @Deprecated public KeyMaterialFactory newKeyMaterialFactory(final URL endpoint, @Nonnull VirtualChannel target) throws InterruptedException, IOException { return newKeyMaterialFactory(endpoint, target, null, TaskListener.NULL); }
final String token = t.getToken();
public AuthConfig getAuthConfig(Job<?, ?> project) { if (dockerRegistryEndpoint == null || Strings.isNullOrEmpty(dockerRegistryEndpoint.getCredentialsId())) { return null; } AuthConfig authConfig = new AuthConfig(); authConfig.withRegistryAddress(dockerRegistryEndpoint.getUrl()); DockerRegistryToken token = this.dockerRegistryEndpoint.getToken(project); if (token != null) { String credentials = new String(Base64.decodeBase64(token.getToken()), Charsets.UTF_8); String[] usernamePassword = credentials.split(":"); authConfig.withUsername(usernamePassword[0]); authConfig.withPassword(usernamePassword[1]); authConfig.withEmail(token.getEmail()); } return authConfig; }
@Nonnull @Override public DockerRegistryToken convert(@Nonnull AmazonECSRegistryCredential credential) throws AuthenticationTokenException { LOG.log(Level.FINE,"Converting credential to Docker registry token : {0}",credential.getCredentialsId()); return new DockerRegistryToken(credential.getEmail(), Secret.toString(credential.getPassword())); } }
/** * @deprecated use {@link #newKeyMaterialFactory(URL, FilePath, Launcher, EnvVars, TaskListener, String)} */ @Deprecated public KeyMaterialFactory newKeyMaterialFactory(final URL endpoint, @Nonnull VirtualChannel target) throws InterruptedException, IOException { return newKeyMaterialFactory(endpoint, target, null, TaskListener.NULL); }
@NonNull @Override public DockerRegistryToken convert(UsernamePasswordCredentials c) throws AuthenticationTokenException { return new DockerRegistryToken(c.getUsername(), Base64.encodeBase64String((c.getUsername() + ":" + c.getPassword().getPlainText()) .getBytes(Charsets.UTF_8))); } }
/** * @deprecated use {@link #newKeyMaterialFactory(URL, FilePath, Launcher, EnvVars, TaskListener, String)} */ @Deprecated public KeyMaterialFactory newKeyMaterialFactory(@Nonnull URL endpoint, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener, @Nonnull String dockerExecutable) throws InterruptedException, IOException { return newKeyMaterialFactory(endpoint, workspace, launcher, new EnvVars(), listener, dockerExecutable); }
@NonNull @Override public DockerRegistryToken convert(UsernamePasswordCredentials c) throws AuthenticationTokenException { return new DockerRegistryToken(c.getUsername(), Base64.encodeBase64String((c.getUsername() + ":" + c.getPassword().getPlainText()) .getBytes(Charsets.UTF_8))); } }
/** * Makes the credentials available locally and returns {@link KeyMaterialFactory} that gives you the parameters * needed to access it. * @param workspace a workspace being used for operations ({@link WorkspaceList#tempDir} will be applied) * @param dockerExecutable as in {@link DockerTool#getExecutable}, with a 1.8+ client */ public KeyMaterialFactory newKeyMaterialFactory(@CheckForNull Item context, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull EnvVars env, @Nonnull TaskListener listener, @Nonnull String dockerExecutable) throws IOException, InterruptedException { if (credentialsId == null) { return KeyMaterialFactory.NULL; // nothing needed to be done } DockerRegistryToken token = getToken(context); if (token == null) { throw new AbortException("Could not find credentials matching " + credentialsId); } return token.newKeyMaterialFactory(getEffectiveUrl(), workspace, launcher, env, listener, dockerExecutable); }
/** * @deprecated Call {@link #newKeyMaterialFactory(Item, FilePath, Launcher, EnvVars, TaskListener, String)} */ @Deprecated public KeyMaterialFactory newKeyMaterialFactory(@CheckForNull Item context, @Nonnull VirtualChannel target, @CheckForNull Launcher launcher, @Nonnull TaskListener listener) throws IOException, InterruptedException { if (credentialsId == null) { return KeyMaterialFactory.NULL; // nothing needed to be done } DockerRegistryToken token = getToken(context); if (token == null) { throw new AbortException("Could not find credentials matching " + credentialsId); } return token.newKeyMaterialFactory(getEffectiveUrl(), target, launcher, listener); }
/** * Makes the credentials available locally and returns {@link KeyMaterialFactory} that gives you the parameters * needed to access it. */ public KeyMaterialFactory newKeyMaterialFactory(@CheckForNull Item context, @Nonnull VirtualChannel target, @CheckForNull Launcher launcher, @Nonnull TaskListener listener) throws IOException, InterruptedException { if (credentialsId == null) { return KeyMaterialFactory.NULL; // nothing needed to be done } DockerRegistryToken token = getToken(context); if (token == null) { throw new AbortException("Could not find credentials matching " + credentialsId); } return token.newKeyMaterialFactory(getEffectiveUrl(), target, launcher, listener); }
/** * Sets up an environment logged in to the specified Docker registry. * @param dockerExecutable as in {@link DockerTool#getExecutable}, with a 1.8+ client */ public KeyMaterialFactory newKeyMaterialFactory(@Nonnull URL endpoint, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull EnvVars env, @Nonnull TaskListener listener, @Nonnull String dockerExecutable) throws InterruptedException, IOException { if (!USE_CUSTOM_LOGIN) { try { // see UsernamePasswordDockerRegistryTokenSource for example String usernameColonPassword = new String(Base64.getDecoder().decode(token), StandardCharsets.UTF_8); int colon = usernameColonPassword.indexOf(':'); if (colon > 0) { return new RegistryKeyMaterialFactory(usernameColonPassword.substring(0, colon), usernameColonPassword.substring(colon + 1), endpoint, launcher, env, listener, dockerExecutable). contextualize(new KeyMaterialContext(WorkspaceList.tempDir(workspace))); } } catch (IllegalArgumentException x) { // not Base64-encoded } listener.getLogger().println("Warning: authentication token does not look like a username:password; falling back to direct manipulation of Docker configuration files"); } return newKeyMaterialFactory(endpoint, workspace.getChannel(), launcher, listener); }