github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/caas/kubernetes/clientconfig/types.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package clientconfig
     5  
     6  import (
     7  	"io"
     8  
     9  	"github.com/juju/errors"
    10  
    11  	"github.com/juju/juju/cloud"
    12  )
    13  
    14  // ClientConfig - a set of cloud endpoint info and user credentials
    15  // Clouds and user Credentials are joined by
    16  // Contexts. There should always be a valid Context with same name as
    17  // the CurrentContext string.
    18  type ClientConfig struct {
    19  	Type           string
    20  	Contexts       map[string]Context
    21  	CurrentContext string
    22  	Clouds         map[string]CloudConfig
    23  	Credentials    map[string]cloud.Credential
    24  }
    25  
    26  // Context joins Clouds and Credentials.
    27  type Context struct {
    28  	CloudName      string
    29  	CredentialName string
    30  }
    31  
    32  func (c Context) isEmpty() bool {
    33  	return c.CloudName == "" && c.CredentialName == ""
    34  }
    35  
    36  // CloudConfig stores information about how to connect to a Cloud.
    37  type CloudConfig struct {
    38  	Endpoint   string
    39  	Attributes map[string]interface{}
    40  }
    41  
    42  // If existing CAAS cloud has Cluster_A and User_A, here's what happens when we try to define a new CAAS cloud:
    43  
    44  // Cluster_B, User_B: New Cloud & new Credential for that cloud
    45  // Cluster B, User A: New Cloud & New Credential for that cloud (duplicate is necessary)
    46  // Cluster_A, User_A: error. already exists.
    47  // Cluster_A, User_B: No new Cloud, new Credential for the cloud.
    48  
    49  // ClientConfigFunc is a function that returns a ClientConfig. Functions of this type should be available for each supported CAAS framework, e.g. Kubernetes.
    50  type ClientConfigFunc func(io.Reader, string, string, K8sCredentialResolver) (*ClientConfig, error)
    51  
    52  // NewClientConfigReader returns a function of type ClientConfigFunc to read the client config for a given cloud type.
    53  func NewClientConfigReader(cloudType string) (ClientConfigFunc, error) {
    54  	switch cloudType {
    55  	case "kubernetes":
    56  		return NewK8sClientConfig, nil
    57  	default:
    58  		return nil, errors.Errorf("Cannot read local config: unsupported cloud type '%s'", cloudType)
    59  	}
    60  }