Documentation ¶
Overview ¶
Package ccv2 implements read-only Cloud Foundry Cloud Controller API client, targeting version 2 of the API. For more details about the API, see https://apidocs.cloudfoundry.org/.
Note that this is only a Cloud Controller client, thus it does not deal with authentication and authorization. It is responsiblity of the client the provided an authenticated HTTP client.
Example usage:
apiURL, _ := url.Parse("https://api.bosh-lite.com") cf := &ccv2.Client{ API: apiURL, HTTPClient: http.DefaultClient, } ctx := context.Background() infoCtx, cancel := context.WithTimeout(ctx, time.Second*5) defer cancel() info, err := cf.Info(infoCtx) if err != nil { log.Fatalf("error fetching info: %v\n", err) } authConfig := &oauth2.Config{ ClientID: "cf", Scopes: []string{""}, Endpoint: oauth2.Endpoint{ AuthURL: info.TokenEndpoint + "/oauth/auth", TokenURL: info.TokenEndpoint + "/oauth/token", }, } tCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() token, err := authConfig.PasswordCredentialsToken(tCtx, "admin", "admin") if err != nil { log.Fatalf("error fetching token: %v\n", err) } cf = &ccv2.Client{ API: apiURL, HTTPClient: authConfig.Client(ctx, token), } // Use cf as authenticated on behalf of admin:admin.
Index ¶
- Constants
- type Application
- type ApplicationSummary
- type Client
- func (c *Client) ApplicationSummary(ctx context.Context, app Application) (a ApplicationSummary, err error)
- func (c *Client) Applications(ctx context.Context, queries ...Query) ([]Application, error)
- func (c *Client) Events(ctx context.Context, queries ...Query) ([]Event, error)
- func (c *Client) Info(ctx context.Context) (i Info, err error)
- func (c *Client) Organizations(ctx context.Context, queries ...Query) ([]Organization, error)
- func (c *Client) Spaces(ctx context.Context, queries ...Query) ([]Space, error)
- type Doer
- type Event
- type Filter
- type Info
- type Metadata
- type Operator
- type Organization
- type Query
- type Space
- type UnexpectedResponseError
Constants ¶
const ( // FilterName specifies that the query should filter on the name field. FilterName Filter = "name" // FilterOrganizationGUID specifies that the query should filter on the // organization_guid field. FilterOrganizationGUID = "organization_guid" // FilterSpaceGUID specifies that the query should filter on the space_guid // field. FilterSpaceGUID = "space_guid" // FilterTimestamp specifies that the query should filter on the timestamp // field. FilterTimestamp = "timestamp" // FilterActee specifies that the query should filter on the actee field. FilterActee = "actee" // FilterActor specifies that the query should filter on the actor field. FilterActor = "actor" // FilterType specifies that the query should filter on the type field. FilterType = "type" )
const ( // OperatorEqual specifies that the result should match the value. OperatorEqual Operator = ":" // OperatorGreater specifies that the result should be greater than the value. OperatorGreater = ">" // OperatorLess specifies that the result should be less than the value. OperatorLess = "<" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct { Metadata `json:"metadata"` Entity struct { Name string `json:"name"` SpaceGUID string `json:"space_guid"` StackGUID string `json:"stack_guid"` Memory int `json:"memory"` Instances int `json:"instances"` DiskQuota int `json:"disk_quota"` State string `json:"state"` Version string `json:"version"` PackageState string `json:"package_state"` HealthCheckType string `json:"health_check_type"` HealthCheckTimeout int `json:"health_check_timeout"` Buildpack string `json:"buildpack"` Command string `json:"command"` DetectedBuildpack string `json:"detected_buildpack"` DetectedCommand string `json:"detected_start_command"` Diego bool `json:"diego"` EnableSSH bool `json:"enable_ssh"` } `json:"entity"` }
Application represents a Cloud Foundry application.
type ApplicationSummary ¶
type ApplicationSummary struct { GUID string `json:"guid"` Name string `json:"name"` SpaceGUID string `json:"space_guid"` StackGUID string `json:"stack_guid"` Memory int `json:"memory"` Instances int `json:"instances"` DiskQuota int `json:"disk_quota"` State string `json:"state"` Version string `json:"version"` PackageState string `json:"package_state"` HealthCheckType string `json:"health_check_type"` HealthCheckTimeout int `json:"health_check_timeout"` Buildpack string `json:"buildpack"` Command string `json:"command"` DetectedBuildpack string `json:"detected_buildpack"` DetectedCommand string `json:"detected_start_command"` Diego bool `json:"diego"` EnableSSH bool `json:"enable_ssh"` RunningInstances int `json:"running_instances"` }
ApplicationSummary represents summary about an application.
type Client ¶
Client implements a read-only Cloud Controller client.
func (*Client) ApplicationSummary ¶
func (c *Client) ApplicationSummary(ctx context.Context, app Application) (a ApplicationSummary, err error)
ApplicationSummary returns summary for a given application.
func (*Client) Applications ¶
Applications list all applications that conform to the provided queries.
func (*Client) Organizations ¶
Organizations list all organizations that conform to the provided queries.
type Event ¶
type Event struct { Metadata `json:"metadata"` Entity struct { Type string `json:"type"` Actor string `json:"actor"` ActorType string `json:"actor_type"` ActorName string `json:"actor_name"` Actee string `json:"actee"` ActeeType string `json:"actee_type"` ActeeName string `json:"actee_name"` Timestamp time.Time `json:"timestamp"` SpaceGUID string `json:"space_guid"` OrganizationGUID string `json:"organization_guid"` } `json:"entity"` }
Event represents a Cloud Foundry application event.
type Info ¶
type Info struct { Name string `json:"name"` Build string `json:"build"` Support string `json:"support"` Version int `json:"version"` Description string `json:"description"` MinCliVersion string `json:"min_cli_version"` APIVersion string `json:"api_version"` AppSSHEndpoint string `json:"app_ssh_endpoint"` AuthorizationEndpoint string `json:"authorization_endpoint"` TokenEndpoint string `json:"token_endpoint"` RoutingEndpoint string `json:"routing_endpoint"` LoggingEndpoint string `json:"logging_endpoint"` DopplerEndpoint string `json:"doppler_logging_endpoint"` }
Info represents a Cloud Controller info.
type Metadata ¶
type Metadata struct { GUID string `json:"guid"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` }
Metadata represents metadata for a resource.
type Organization ¶
type Organization struct { Metadata `json:"metadata"` Entity struct { Name string `json:"name"` BillingEnabled bool `json:"billing_enabled"` QuotaDefinitonGUID string `json:"quota_definiton_guid"` Status string `json:"status"` } `json:"entity"` }
Organization represents a Cloud Foundry organization.
type Query ¶
type Query struct { // Filter is the field on which the query will act. Filter Filter // Op is the operator that will be applied during filtering. Op Operator // Value is the value that will be used when applying the Op. Value string }
Query gives means to filter list of resources.
type Space ¶
type Space struct { Metadata `json:"metadata"` Entity struct { Name string `json:"name"` OrganizationGUID string `json:"organization_guid"` SpaceQuotaDefinitonGUID string `json:"space_quota_definiton_guid"` AllowSSH bool `json:"allow_ssh"` } `json:"entity"` }
Space represents a Cloud Foundry space.
type UnexpectedResponseError ¶
type UnexpectedResponseError struct { StatusCode int `json:"status_code"` Description string `json:"description"` ErrorCode string `json:"error_code"` }
UnexpectedResponseError wraps response that indicates error.
func (*UnexpectedResponseError) Error ¶
func (e *UnexpectedResponseError) Error() string
Error returns a description of the error.