Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/testcontainers/src/container-runtime/auth/auths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Auth, AuthConfig, ContainerRuntimeConfig } from "./types";
import { Auth, AuthConfig, AuthCredentialConfig, ContainerRuntimeConfig } from "./types";
import { RegistryAuthLocator } from "./registry-auth-locator";
import { registryMatches } from "./registry-matches";

Expand All @@ -13,7 +13,7 @@ export class Auths implements RegistryAuthLocator {
return undefined;
}

const authConfig: Partial<AuthConfig> = { registryAddress: registry };
const authConfig: Partial<AuthCredentialConfig> = { registryAddress: registry };

if (auth.email) {
authConfig.email = auth.email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export abstract class CredentialProvider implements RegistryAuthLocator {

const response = await this.runCredentialProvider(registry, programName);

if (response.Username === "<token>") {
return {
identityToken: response.Secret,
registryAddress: response.ServerURL,
};
}

return {
username: response.Username,
password: response.Secret,
Expand Down
9 changes: 8 additions & 1 deletion packages/testcontainers/src/container-runtime/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ export type Auth = {
password?: string;
};

export type AuthConfig = {
export type AuthCredentialConfig = {
username: string;
password: string;
registryAddress: string;
email?: string;
};

export type AuthIdentityTokenConfig = {
identityToken: string;
registryAddress: string;
};

export type AuthConfig = AuthCredentialConfig | AuthIdentityTokenConfig;

export type RegistryConfig = {
[registryAddress: string]: {
username: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GenericContainerBuilder {
buildargs: this.buildArgs,
pull: this.pullPolicy ? "true" : undefined,
nocache: !this.cache,
registryconfig: registryConfig,
registryconfig: registryConfig as any, // @types/dockerode registry config type is wrong
labels,
target: this.target,
});
Expand All @@ -95,6 +95,13 @@ export class GenericContainerBuilder {

return authConfigs
.map((authConfig) => {
if ("identityToken" in authConfig) {
return {
[authConfig.registryAddress]: {
identitytoken: authConfig.identityToken,
},
};
}
return {
[authConfig.registryAddress]: {
username: authConfig.username,
Expand Down
19 changes: 14 additions & 5 deletions packages/testcontainers/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,27 @@ export type Labels = { [key: string]: string };
export type HostPortBindings = Array<{ hostIp: string; hostPort: number }>;
export type Ports = { [containerPort: number]: HostPortBindings };

export type AuthConfig = {
export type AuthCredentialConfig = {
username: string;
password: string;
registryAddress: string;
email?: string;
};

export type AuthIdentityTokenConfig = {
identityToken: string;
registryAddress: string;
};

export type AuthConfig = AuthCredentialConfig | AuthIdentityTokenConfig;

export type RegistryConfig = {
[registryAddress: string]: {
username: string;
password: string;
};
[registryAddress: string]:
| {
username: string;
password: string;
}
| { identitytoken: string };
};

export type BuildArgs = { [key in string]: string };
Expand Down