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

com.spotify.docker.client.messages.AuthRegistryConfig Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*-
 * -\-\-
 * docker-client
 * --
 * Copyright (C) 2016 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/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 com.spotify.docker.client.messages;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.google.common.base.MoreObjects;

import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * A formatted string passed in X-Registry-Config request header. {"myrepository":{
 * "username":"myusername", "password":"mypassword", "auth":"", "email":"myemail",
 * "serveraddress":"myserverAddress"}}
 */
public class AuthRegistryConfig {


  private final Map> configs = new HashMap<>();
  private final String repository;
  private final String username;
  private final String password;
  private final String auth;
  private final String email;
  private final String serverAddress;

  public static final AuthRegistryConfig EMPTY = new AuthRegistryConfig("", "", "", "", "", "");

  /**
   * Wrapper to support X-Registry-Config header with auth.
   *
   * @param repository    Repository name (uniquely identifies the config)
   * @param username      User name
   * @param password      Password for authentication
   * @param auth          Not used but must be supplied
   * @param email         EMAIL address of authenticated user
   * @param serverAddress The address of the repository
   */
  public AuthRegistryConfig(final String repository,
                            final String username,
                            final String password,
                            final String auth,
                            final String email,
                            final String serverAddress) {
    this.repository = repository;
    this.username = username;
    this.password = password;
    this.auth = auth;
    this.email = email;
    this.serverAddress = serverAddress;
    configs.put(repository, ImmutableMap.of(
        "username", username,
        "password", password,
        "auth", auth,
        "email", email,
        "serveraddress", serverAddress
    ));
  }

  /**
   * Wrapper to support X-Registry-Config header without auth.
   *
   * @param repository    Repository name (uniquely identifies the config)
   * @param username      User name
   * @param password      Password for authentication
   * @param email         EMAIL address of authenticated user
   * @param serverAddress The address of the repository
   */
  public AuthRegistryConfig(final String repository,
                            final String username,
                            final String password,
                            final String email,
                            final String serverAddress) {
    this(repository, username, password, "", email, serverAddress);
  }

  @JsonAnyGetter
  public Map> getConfigs() {
    return configs;
  }

  @Override
  public boolean equals(final Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
      return false;
    }

    final AuthRegistryConfig that = (AuthRegistryConfig) obj;

    return Objects.equals(this.repository, that.repository)
           && Objects.equals(this.username, that.username)
           && Objects.equals(this.password, that.password)
           && Objects.equals(this.auth, that.auth)
           && Objects.equals(this.email, that.email)
           && Objects.equals(this.serverAddress, that.serverAddress);
  }

  @Override
  public int hashCode() {
    return Objects.hash(repository, username, password, auth, email, serverAddress);
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper(this)
        .add("repository", repository)
        .add("username", username)
        .add("password", password)
        .add("auth", auth)
        .add("email", email)
        .add("serverAddress", serverAddress)
        .toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy