configuration.go raw

   1  package gotransip
   2  
   3  import (
   4  	"io"
   5  	"net/http"
   6  	"time"
   7  
   8  	"github.com/transip/gotransip/v6/authenticator"
   9  )
  10  
  11  const (
  12  	libraryVersion  = "6.26.1"
  13  	defaultBasePath = "https://api.transip.nl/v6"
  14  	userAgent       = "go-client-gotransip/" + libraryVersion
  15  )
  16  
  17  // APIMode specifies in which mode the API is used. Currently this is only
  18  // supports either readonly or readwrite
  19  type APIMode string
  20  
  21  var (
  22  	// APIModeReadOnly specifies that no changes can be made from API calls.
  23  	// If you do try to order a product or change some data, the api will return an error.
  24  	APIModeReadOnly APIMode = "readonly"
  25  	// APIModeReadWrite specifies that changes can be made from API calls
  26  	APIModeReadWrite APIMode = "readwrite"
  27  )
  28  
  29  // DemoClientConfiguration is the default configuration to use when testing the demo mode of the transip api.
  30  // Demo mode allows users to test without authenticating with their own credentials.
  31  var DemoClientConfiguration = ClientConfiguration{Token: authenticator.DemoToken}
  32  
  33  // ClientConfiguration stores the configuration of the API client
  34  type ClientConfiguration struct {
  35  	// AccountName is the name of the account of the user, this is used in combination with a private key.
  36  	// When requesting a new token, the account name will be part of the token request body
  37  	AccountName string
  38  	// URL is set by default to the transip api server
  39  	// this is mainly used in tests to point to a mock server
  40  	URL string
  41  	// PrivateKeyPath is the filesystem location to the private key
  42  	PrivateKeyPath string
  43  	// For users that want the possibility to store their key elsewhere,
  44  	// not on a filesystem but on X datastore
  45  	PrivateKeyReader io.Reader
  46  	// Token field gives users the option of providing their own acquired token,
  47  	// for example when generated in the transip control panel
  48  	Token string
  49  	// TestMode is used when users want to tinker with the api without touching their real data.
  50  	// So you can view your own data, order new products, but the actual order never happens.
  51  	TestMode bool
  52  	// optionally you can set your own HTTPClient
  53  	// to set extra non default settings
  54  	HTTPClient *http.Client
  55  	// APIMode specifies in which mode the API is used. Currently this is only
  56  	// supports either readonly or readwrite
  57  	Mode APIMode
  58  	// TokenCache is used to retrieve previously acquired tokens and saving new ones
  59  	// If not set we do not use a cache to store the new acquired tokens
  60  	TokenCache authenticator.TokenCache
  61  	// TokenExpiration defines the lifetime of new tokens requested by the authenticator.
  62  	// If unspecified, the default is 1 day.
  63  	// This has no effect for tokens provided via the Token field.
  64  	TokenExpiration time.Duration
  65  	// TokenWhitelisted is used to indicate only whitelisted IP's may use the new tokens requested by the authenticator.
  66  	// This has no effect for tokens provided via the Token field.
  67  	TokenWhitelisted bool
  68  }
  69