console

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	UAA     = "UAA"
	CONSOLE = "CONSOLE"
)

Constants

Variables

View Source
var (
	ErrNotFound                       = errors.New("entity not found")
	ErrMissingName                    = errors.New("missing name value")
	ErrMissingDescription             = errors.New("missing description value")
	ErrMalformedInputValue            = errors.New("malformed input value")
	ErrNotImplementedByHSDP           = errors.New("method not implemented by HSDP")
	ErrCouldNoReadResourceAfterCreate = errors.New("could not read resource after create")
	ErrConsoleURLCannotBeEmpty        = errors.New("console base URL cannot be empty")
	ErrUAAURLCannotBeEmpty            = errors.New("UAA URL cannot be empty")
	ErrEmptyResults                   = errors.New("empty results")
	ErrOperationFailed                = errors.New("operation failed")
	ErrMissingEtagInformation         = errors.New("missing etag information")
	ErrMissingRefreshToken            = errors.New("missing refresh token")
	ErrNotAuthorized                  = errors.New("not authorized")
	ErrNonHttp20xResponse             = errors.New("non http 20x console response")
)

Exported Errors

Functions

func CheckResponse added in v0.27.0

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present.

Types

type Application

type Application struct {
	Enabled      bool        `json:"enabled"`
	MaxInstances int         `json:"maxInstances"`
	MinInstances int         `json:"minInstances"`
	Name         string      `json:"name"`
	Thresholds   []Threshold `json:"thresholds,omitempty"`
}

type AutoscalersResponse

type AutoscalersResponse struct {
	Data struct {
		Applications []Application `json:"applications"`
	} `json:"data"`
	Status string `json:"status"`
	Error  Error  `json:"error,omitempty"`
}

type CFLinksResponse

type CFLinksResponse struct {
	Links struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		CloudControllerV2 struct {
			Href string `json:"href"`
			Meta struct {
				Version string `json:"version"`
			} `json:"meta"`
		} `json:"cloud_controller_v2"`
		CloudControllerV3 struct {
			Href string `json:"href"`
			Meta struct {
				Version string `json:"version"`
			} `json:"meta"`
		} `json:"cloud_controller_v3"`
		NetworkPolicyV0 struct {
			Href string `json:"href"`
		} `json:"network_policy_v0"`
		NetworkPolicyV1 struct {
			Href string `json:"href"`
		} `json:"network_policy_v1"`
		Login struct {
			Href string `json:"href"`
		} `json:"login"`
		UAA struct {
			Href string `json:"href"`
		} `json:"uaa"`
		Credhub interface{} `json:"credhub"`
		Routing struct {
			Href string `json:"href"`
		} `json:"routing"`
		Logging struct {
			Href string `json:"href"`
		} `json:"logging"`
		LogCache struct {
			Href string `json:"href"`
		} `json:"log_cache"`
		LogStream struct {
			Href string `json:"href"`
		} `json:"log_stream"`
		AppSSH struct {
			Href string `json:"href"`
			Meta struct {
				HostKeyFingerprint string `json:"host_key_fingerprint"`
				OauthClient        string `json:"oauth_client"`
			} `json:"meta"`
		} `json:"app_ssh"`
	} `json:"links"`
}

type Client

type Client struct {

	// User agent used when communicating with the HSDP IAM API.
	UserAgent string

	Metrics *MetricsService

	sync.Mutex
	// contains filtered or unexported fields
}

A Client manages communication with HSDP IAM API

func NewClient

func NewClient(httpClient *http.Client, config *Config) (*Client, error)

NewClient returns a new HSDP Console API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide a valid oAuth bearer token.

func (*Client) Close

func (c *Client) Close()

Close releases allocated resources of clients

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) Expires

func (c *Client) Expires() int64

Expires returns the expiry time (Unix) of the access token

func (*Client) HttpClient

func (c *Client) HttpClient() *http.Client

Returns the http Client used for connections

func (*Client) IDToken

func (c *Client) IDToken() string

IDToken returns the ID token

func (*Client) Login

func (c *Client) Login(username, password string) error

Login logs in a user with `username` and `password`

func (*Client) NewRequest

func (c *Client) NewRequest(endpoint, method, path string, opt interface{}, options []OptionFunc) (*http.Request, error)

NewRequest creates an API request. A relative URL path can be provided in urlStr, in which case it is resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) RefreshToken

func (c *Client) RefreshToken() string

RefreshToken returns the refresh token

func (*Client) SetBaseConsoleURL

func (c *Client) SetBaseConsoleURL(urlStr string) error

SetBaseConsoleURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

func (*Client) SetBaseUAAURL

func (c *Client) SetBaseUAAURL(urlStr string) error

SetBaseIDMURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

func (*Client) Token

func (c *Client) Token() string

Token returns the current token

func (*Client) TokenRefresh

func (c *Client) TokenRefresh() error

TokenRefresh refreshes the accessToken

func (*Client) WithLogin added in v0.27.0

func (c *Client) WithLogin(username, password string) (*Client, error)

WithLogin returns a cloned client with new login

type Config

type Config struct {
	Region         string
	BaseConsoleURL string
	UAAURL         string
	Scopes         []string
	Debug          bool
	DebugLog       string
}

Config contains the configuration of a client

type ContextKey

type ContextKey string

type Endpoint

type Endpoint string

Endpoint type

type Error added in v0.27.0

type Error struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

type Group

type Group struct {
	Name  string `json:"name"`
	Rules []Rule `json:"rules"`
}

type Instance

type Instance struct {
	CreatedAt    time.Time `json:"createdAt"`
	GUID         string    `json:"guid"`
	Name         string    `json:"name"`
	Organization string    `json:"organization"`
	Space        string    `json:"space"`
}

type MetricsResponse

type MetricsResponse struct {
	Data struct {
		Instances []Instance `json:"instances"`
	} `json:"data"`
	Status string `json:"status"`
	Error  Error  `json:"error,omitempty"`
}

type MetricsService

type MetricsService struct {
	// contains filtered or unexported fields
}

func (*MetricsService) GetApplicationAutoscaler

func (c *MetricsService) GetApplicationAutoscaler(id, app string, options ...OptionFunc) (*Application, *Response, error)

GetApplicationAutoscaler looks up a specific application autoscaler settings

func (*MetricsService) GetApplicationAutoscalers

func (c *MetricsService) GetApplicationAutoscalers(id string, options ...OptionFunc) (*[]Application, *Response, error)

GetApplicationAutoscalers looks up all available autoscalers

func (*MetricsService) GetGroupedRules

func (c *MetricsService) GetGroupedRules(options ...OptionFunc) (*[]Group, *Response, error)

GetGroupedRules looks up available rules

func (*MetricsService) GetInstanceByID

func (c *MetricsService) GetInstanceByID(id string, options ...OptionFunc) (*Instance, *Response, error)

GetInstanceByID looks up an instance by ID

func (*MetricsService) GetInstances

func (c *MetricsService) GetInstances(options ...OptionFunc) (*[]Instance, *Response, error)

GetInstances looks up available instances

func (*MetricsService) GetRuleByID

func (c *MetricsService) GetRuleByID(id string, options ...OptionFunc) (*Rule, *Response, error)

GetRuleByID looks up available instances

func (*MetricsService) UpdateApplicationAutoscaler

func (c *MetricsService) UpdateApplicationAutoscaler(id string, settings Application, options ...OptionFunc) (*Application, *Response, error)

GetApplicationAutoscaler looks up a specific application autoscaler settings

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

func WithContext

func WithContext(ctx context.Context) OptionFunc

WithContext runs the request with the provided context

type Response

type Response struct {
	*http.Response
	Error
}

Response is a HSDP Console API response. This wraps the standard http.Response returned from HSDP Console and provides convenient access to things like errors

type Rule

type Rule struct {
	Annotations struct {
		Description string `json:"description"`
		Resolved    string `json:"resolved"`
		Summary     string `json:"summary"`
	} `json:"annotations"`
	Description string `json:"description"`
	ID          string `json:"id"`
	Metric      string `json:"metric"`
	Rule        struct {
		ExtraFor []struct {
			Name         string   `json:"name"`
			Options      []string `json:"options"`
			Type         string   `json:"type"`
			VariableName string   `json:"variableName"`
		} `json:"extraFor,omitempty"`
		Extras []struct {
			Name         string   `json:"name"`
			Options      []string `json:"options"`
			Type         string   `json:"type"`
			VariableName string   `json:"variableName"`
		} `json:"extras"`
		Operators []string  `json:"operators"`
		Subject   string    `json:"subject"`
		Threshold Threshold `json:"threshold"`
	} `json:"rule"`
	Template string `json:"template"`
}

type RuleResponse

type RuleResponse struct {
	Data struct {
		Groups []Group `json:"groups"`
	} `json:"data"`
	Status string `json:"status"`
	Error  Error  `json:"error,omitempty"`
}

type Threshold added in v0.23.0

type Threshold struct {
	Default int      `json:"default,omitempty"`
	Enabled bool     `json:"enabled"`
	Max     float64  `json:"max"`
	Min     float64  `json:"min"`
	Name    string   `json:"name"`
	Type    string   `json:"type,omitempty"`
	Unit    []string `json:"unit,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL