github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/crossmodel/externalcontroller.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package crossmodel
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"gopkg.in/juju/names.v2"
     9  
    10  	"github.com/juju/juju/network"
    11  )
    12  
    13  // ControllerInfo holds the details required to connect to a controller.
    14  type ControllerInfo struct {
    15  	// ControllerTag holds tag for the controller.
    16  	ControllerTag names.ControllerTag
    17  
    18  	// Alias holds a (human friendly) alias for the controller.
    19  	Alias string
    20  
    21  	// Addrs holds the addresses and ports of the controller's API servers.
    22  	Addrs []string
    23  
    24  	// CACert holds the CA certificate that will be used to validate
    25  	// the API server's certificate, in PEM format.
    26  	CACert string
    27  }
    28  
    29  // Validate returns an error if the ControllerInfo contains bad data.
    30  func (info *ControllerInfo) Validate() error {
    31  	if !names.IsValidController(info.ControllerTag.Id()) {
    32  		return errors.NotValidf("ControllerTag")
    33  	}
    34  
    35  	if len(info.Addrs) < 1 {
    36  		return errors.NotValidf("empty controller api addresses")
    37  	}
    38  	for _, addr := range info.Addrs {
    39  		_, err := network.ParseHostPort(addr)
    40  		if err != nil {
    41  			return errors.NotValidf("controller api address %q", addr)
    42  		}
    43  	}
    44  	return nil
    45  }