ccv2

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2017 License: Apache-2.0 Imports: 8 Imported by: 3

README

ccv2

GoDoc Build Status

Package ccv2 provides read-only Cloud Foundry Cloud Controller API client. The client targets version 2 of the Cloud Controller's API.

For more details on the API itself, please refer to https://apidocs.cloudfoundry.org. For more details on the client's Go API, refer to its godoc.

Installation

As most Go packages, just go get it.

go get -u github.com/Bo0mer/ccv2

Developer's guide

If you want to introduce new functionality, fix a bug, or just play with the code, just make sure the tests are passing by executing go test -race ./... or ginkgo -r --race.

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

View Source
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"
)
View Source
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

type Client struct {
	API        *url.URL
	HTTPClient Doer
}

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

func (c *Client) Applications(ctx context.Context, queries ...Query) ([]Application, error)

Applications list all applications that conform to the provided queries.

func (*Client) Events

func (c *Client) Events(ctx context.Context, queries ...Query) ([]Event, error)

Events list all events that conform to the provided queries.

func (*Client) Info

func (c *Client) Info(ctx context.Context) (i Info, err error)

Info returns the info returned by the Cloud Controller info endpoint.

func (*Client) Organizations

func (c *Client) Organizations(ctx context.Context, queries ...Query) ([]Organization, error)

Organizations list all organizations that conform to the provided queries.

func (*Client) Spaces

func (c *Client) Spaces(ctx context.Context, queries ...Query) ([]Space, error)

Spaces list all spaces that conform to the provided queries.

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer does HTTP requests and returns the corresponding responses.

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 Filter

type Filter string

Filter specifies the target of a query.

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 Operator

type Operator string

Operator specifies an operator for a query.

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.

func (Query) String

func (q Query) String() string

String returns the string representation of the query. It is of the form <Filter><Op><Value>. It must be query encoded if to be used as a query param.

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.

Directories

Path Synopsis
cmd
cfapps
cfapps is a simple command line utility that prints one's Cloud Foundry organizations and applications.
cfapps is a simple command line utility that prints one's Cloud Foundry organizations and applications.

Jump to

Keyboard shortcuts

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