github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/api/uaa/client.go (about)

     1  // Package uaa is a GoLang library that interacts with CloudFoundry User
     2  // Account and Authentication (UAA) Server.
     3  //
     4  // It is currently designed to support UAA API X.X.X. However, it may include
     5  // features and endpoints of later API versions.
     6  package uaa
     7  
     8  import (
     9  	"fmt"
    10  	"runtime"
    11  	"time"
    12  
    13  	"github.com/liamawhite/cli-with-i18n/api/uaa/internal"
    14  )
    15  
    16  // Client is the UAA client
    17  type Client struct {
    18  	id     string
    19  	secret string
    20  
    21  	connection Connection
    22  	router     *internal.Router
    23  	userAgent  string
    24  }
    25  
    26  // Config allows the Client to be configured
    27  type Config struct {
    28  	// AppName is the name of the application/process using the client.
    29  	AppName string
    30  
    31  	// AppVersion is the version of the application/process using the client.
    32  	AppVersion string
    33  
    34  	// DialTimeout is the DNS lookup timeout for the client. If not set, it is
    35  	// infinite.
    36  	DialTimeout time.Duration
    37  
    38  	// ClientID is the UAA client ID the client will use.
    39  	ClientID string
    40  
    41  	// ClientSecret is the UAA client secret the client will use.
    42  	ClientSecret string
    43  
    44  	// SkipSSLValidation controls whether a client verifies the server's
    45  	// certificate chain and host name. If SkipSSLValidation is true, TLS accepts
    46  	// any certificate presented by the server and any host name in that
    47  	// certificate for *all* client requests going forward.
    48  	//
    49  	// In this mode, TLS is susceptible to man-in-the-middle attacks. This should
    50  	// be used only for testing.
    51  	SkipSSLValidation bool
    52  }
    53  
    54  // NewClient returns a new UAA Client with the provided configuration
    55  func NewClient(config Config) *Client {
    56  	userAgent := fmt.Sprintf("%s/%s (%s; %s %s)",
    57  		config.AppName,
    58  		config.AppVersion,
    59  		runtime.Version(),
    60  		runtime.GOARCH,
    61  		runtime.GOOS,
    62  	)
    63  
    64  	client := Client{
    65  		id:     config.ClientID,
    66  		secret: config.ClientSecret,
    67  
    68  		connection: NewConnection(config.SkipSSLValidation, config.DialTimeout),
    69  		userAgent:  userAgent,
    70  	}
    71  	client.WrapConnection(NewErrorWrapper())
    72  
    73  	return &client
    74  }