How to use authConfigUsingHelper method of org.testcontainers.utility.RegistryAuthLocator class

Best Testcontainers-java code snippet using org.testcontainers.utility.RegistryAuthLocator.authConfigUsingHelper

Source:RegistryAuthLocator.java Github

copy

Full Screen

...102 try {103 final JsonNode config = OBJECT_MAPPER.readTree(configFile);104 log.debug("registryName [{}] for dockerImageName [{}]", registryName, dockerImageName);105 // use helper preferentially (per https://docs.docker.com/engine/reference/commandline/cli/)106 final AuthConfig helperAuthConfig = authConfigUsingHelper(config, registryName);107 if (helperAuthConfig != null) {108 log.debug("found helper auth config [{}]", toSafeString(helperAuthConfig));109 return Optional.of(helperAuthConfig);110 }111 // no credsHelper to use, using credsStore:112 final AuthConfig storeAuthConfig = authConfigUsingStore(config, registryName);113 if (storeAuthConfig != null) {114 log.debug("found creds store auth config [{}]", toSafeString(storeAuthConfig));115 return Optional.of(storeAuthConfig);116 }117 // fall back to base64 encoded auth hardcoded in config file118 final AuthConfig existingAuthConfig = findExistingAuthConfig(config, registryName);119 if (existingAuthConfig != null) {120 log.debug("found existing auth config [{}]", toSafeString(existingAuthConfig));121 return Optional.of(existingAuthConfig);122 }123 } catch (Exception e) {124 log.warn("Failure when attempting to lookup auth config (dockerImageName: {}, configFile: {}. Falling back to docker-java default behaviour. Exception message: {}",125 dockerImageName,126 configFile,127 e.getMessage());128 }129 return Optional.empty();130 }131 private AuthConfig findExistingAuthConfig(final JsonNode config, final String reposName) throws Exception {132 final Map.Entry<String, JsonNode> entry = findAuthNode(config, reposName);133 if (entry != null && entry.getValue() != null && entry.getValue().size() > 0) {134 final AuthConfig deserializedAuth = OBJECT_MAPPER135 .treeToValue(entry.getValue(), AuthConfig.class)136 .withRegistryAddress(entry.getKey());137 if (isBlank(deserializedAuth.getUsername()) &&138 isBlank(deserializedAuth.getPassword()) &&139 !isBlank(deserializedAuth.getAuth())) {140 final String rawAuth = new String(Base64.getDecoder().decode(deserializedAuth.getAuth()));141 final String[] splitRawAuth = rawAuth.split(":", 2);142 if (splitRawAuth.length == 2) {143 deserializedAuth.withUsername(splitRawAuth[0]);144 deserializedAuth.withPassword(splitRawAuth[1]);145 }146 }147 return deserializedAuth;148 }149 return null;150 }151 private AuthConfig authConfigUsingHelper(final JsonNode config, final String reposName) throws Exception {152 final JsonNode credHelpers = config.get("credHelpers");153 if (credHelpers != null && credHelpers.size() > 0) {154 final JsonNode helperNode = credHelpers.get(reposName);155 if (helperNode != null && helperNode.isTextual()) {156 final String helper = helperNode.asText();157 return runCredentialProvider(reposName, helper);158 }159 }160 return null;161 }162 private AuthConfig authConfigUsingStore(final JsonNode config, final String reposName) throws Exception {163 final JsonNode credsStoreNode = config.get("credsStore");164 if (credsStoreNode != null && !credsStoreNode.isMissingNode() && credsStoreNode.isTextual()) {165 final String credsStore = credsStoreNode.asText();...

Full Screen

Full Screen

authConfigUsingHelper

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.DockerClientFactory;2import org.testcontainers.utility.RegistryAuthLocator;3import org.testcontainers.containers.GenericContainer;4import org.testcontainers.containers.output.Slf4jLogConsumer;5import org.testcontainers.images.builder.ImageFromDockerfile;6import org.testcontainers.utility.DockerImageName;7import org.testcontainers.utility.MountableFile;8import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;9import org.testcontainers.containers.wait.strategy.Wait;10import java.util.concurrent.TimeUnit;11import org.testcontainers.shaded.com.github.dockerjava.api.command.InspectContainerResponse;12import org.testcontainers.shaded.com.github.dockerjava.api.model.AuthConfig;13import org.testcontainers.shaded.com.github.dockerjava.api.model.ContainerNetwork;14import org.testcontainers.shaded.com.github.dockerjava.api.model.ExposedPort;15import org.testcontainers.shaded.com.github.dockerjava.api.model.Ports;16import org.testcontainers.shaded.com.github.dockerjava.api.model.Ports.Binding;17import org.testcontainers.shaded.com.github.dockerjava.core.command.PullImageResultCallback;18import org.testcontainers.shaded.com.github.dockerjava.core.command.PushImageResultCallback;19import org.testcontainers.shaded.org.apache.commons.lang.StringUtils;20import org.testcontainers.shaded.org.apache.commons.lang.SystemUtils;21import org.testcontainers.utility.DockerLoggerFactory;22import org.testcontainers.utility.ResourceReaper;23public class PushImageUsingAuthConfig {24 public static void main(String[] args) throws Exception {25 String registry = "registry-1.docker.io";26 String repository = "testcontainers/ryuk";27 AuthConfig authConfig = RegistryAuthLocator.instance().authConfigFor(registry, repository);28 GenericContainer container = new GenericContainer(DockerImageName.parse(repository))29 .withAuthConfig(authConfig);30 container.start();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful