All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.spotify.docker.client.auth.MultiRegistryAuthSupplier Maven / Gradle / Ivy

The newest version!
/*-
 * -\-\-
 * docker-client
 * --
 * Copyright (C) 2016 - 2017 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in org.testifyproject.testifyprojectpliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org.testifyproject/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package org.testifyproject.testifyproject.spotify.docker.client.auth;

import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.Lists;
import org.testifyproject.testifyproject.spotify.docker.client.exceptions.DockerException;
import org.testifyproject.testifyproject.spotify.docker.client.messages.RegistryAuth;
import org.testifyproject.testifyproject.spotify.docker.client.messages.RegistryConfigs;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A RegistryAuthSupplier that org.testifyproject.testifyprojectbines authentication info from multiple RegistryAuthSupplier
 * instances.
 *
 * 

The order of the suppliers matters: RegistryAuthSuppliers earlier in the list are * checked first to see if they can handle authentication for the given operation before trying * later RegistryAuthSuppliers in the list (a RegistryAuthSupplier signals that it can't handle the * operation by returning {@code null}).

*/ public class MultiRegistryAuthSupplier implements RegistryAuthSupplier { private final List suppliers; public MultiRegistryAuthSupplier(final List suppliers) { this.suppliers = suppliers; } @Override public RegistryAuth authFor(final String imageName) throws DockerException { for (RegistryAuthSupplier supplier : suppliers) { final RegistryAuth auth = supplier.authFor(imageName); if (auth != null) { return auth; } } return null; } @Override public RegistryAuth authForSwarm() throws DockerException { for (RegistryAuthSupplier supplier : suppliers) { final RegistryAuth auth = supplier.authForSwarm(); if (auth != null) { return auth; } } return null; } @Override public RegistryConfigs authForBuild() throws DockerException { final Map allConfigs = new HashMap<>(); // iterate through suppliers in reverse so that the earlier suppliers in the list // have precedence for (RegistryAuthSupplier supplier : Lists.reverse(suppliers)) { final RegistryConfigs configs = supplier.authForBuild(); if (configs != null && configs.configs() != null) { allConfigs.putAll(configs.configs()); } } return RegistryConfigs.create(allConfigs); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy