bridgeapi

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

bridgeapi represents a client library to the Crunchy Bridge public API it structures the API calls in convenient forms and maintains the logged-in state of the client through the use of internal timers and a provided source of credential information via the CredentialProvider interface

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Crunchy Data Solutions, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBadRequest = errors.New("Invalid request")
	ErrorConflict   = errors.New("Non-unique name specified in request")
	ErrorAPIUnset   = errors.New("No API target URL set")

	ErrorFailedLogin  = errors.New("Initial login not established")
	ErrorFailedRenew  = errors.New("Failed to establish renewed login")
	ErrorInvalidCreds = errors.New("Invalid credentials for API login")
	ErrorUnstarted    = errors.New("Successful login not yet achieved")
)

Functions

This section is empty.

Types

type APIMessage

type APIMessage struct {
	Message   string `json:"message"`
	RequestID string `json:"request_id"`
}

type Account added in v0.0.5

type Account struct {
	ID            string `json:"id"`
	DefaultTeamID string `json:"default_team_id"`
}

type Client

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

func NewClient

func NewClient(apiURL *url.URL, cp CredentialProvider, opts ...ClientOption) (*Client, error)

func (*Client) ClusterByName

func (c *Client) ClusterByName(name string) (ClusterDetail, error)

ClusterByName returns the cluster detail for the named cluster at present, it is syntactic sugar for finding the named cluster in the ListAllClusters response and retrieving its detail from the individual cluster endpoint. This pivot is required as the cluster list does not include the state field

Returns a zero-value ClusterDetail and nil error when not found

func (*Client) ClusterDetail

func (c *Client) ClusterDetail(id string) (ClusterDetail, error)

func (*Client) CreateCluster

func (c *Client) CreateCluster(cr CreateRequest) error

func (*Client) DefaultConnRole

func (c *Client) DefaultConnRole(id string) (ConnectionRole, error)

DefaultConnRole returns the default connection role for the cluster identified by id

func (*Client) DefaultTeamID

func (c *Client) DefaultTeamID() (string, error)

DefaultTeamID returns the team id for creation requests

func (*Client) DeleteCluster

func (c *Client) DeleteCluster(id string) error

func (*Client) GetLoginState

func (c *Client) GetLoginState() LoginState

func (*Client) ListAllClusters

func (c *Client) ListAllClusters() (ClusterList, error)

ListAllClusters returns all clusters visible to the user, including both personal clusters and team visibility

func (*Client) ListClusters

func (c *Client) ListClusters() (ClusterList, error)

func (*Client) ListTeamClusters

func (c *Client) ListTeamClusters(teamID string) (ClusterList, error)

type ClientOption

type ClientOption func(*Client)

func SetAuthURL

func SetAuthURL(authURL *url.URL) ClientOption

SetAuthURL allows setting a different authentication provider URL if different from the API URL, defaults to the API URL provided in NewClient

func SetHTTPClient

func SetHTTPClient(hc *http.Client) ClientOption

SetHTTPClient allows the use of a custom-configured HTTP client for API requests, Client defaults to a default http.Client{} otherwise

func SetLogger

func SetLogger(logger logr.Logger) ClientOption

func SetVersion

func SetVersion(ver string) ClientOption

SetVersion sets the operator version in the client for self-identification

type ClusterDetail

type ClusterDetail struct {
	CPU              int             `json:"cpu"`
	Created          time.Time       `json:"created_at"`
	ID               string          `json:"id"`
	HighAvailability bool            `json:"is_ha"`
	PGMajorVersion   int             `json:"major_version"`
	MemoryGB         int             `json:"memory"`
	Name             string          `json:"name"`
	OldestBackup     time.Time       `json:"oldest_backup"`
	ProviderID       string          `json:"provider_id"`
	RegionID         string          `json:"region_id"`
	State            string          `json:"state"` // Leave as string until graceful error handling
	StorageGB        int             `json:"storage"`
	TeamID           string          `json:"team_id"`
	Updated          time.Time       `json:"updated_at"`
	Replicas         []ClusterDetail `json:"replicas"`
}

type ClusterList

type ClusterList struct {
	Clusters []ClusterDetail `json:"clusters"`
}

type ClusterState

type ClusterState string
const (
	StateUnknown  ClusterState = "unknown"
	StateCreating ClusterState = "creating"
	StateReady    ClusterState = "ready"
)

type ConnectionRole

type ConnectionRole struct {
	Name     string `json:"name"`
	Password string `json:"password"`
	URI      string `json:"uri"`
}

type CreateRequest

type CreateRequest struct {
	Name             string `json:"name"`
	TeamID           string `json:"team_id"`
	Plan             string `json:"plan_id"`
	StorageGB        int    `json:"storage"`
	Provider         string `json:"provider_id"`
	Region           string `json:"region_id"`
	PGMajorVersion   int    `json:"major_version"`
	HighAvailability bool   `json:"is_ha"`
	Trial            bool   `json:"is_trial"`
}

type CredentialProvider

type CredentialProvider interface {
	ProvideCredential() (LoginCred, error)
}

type LoginCred

type LoginCred struct {
	Key    string
	Secret string
}

func (LoginCred) ProvideCredential

func (lc LoginCred) ProvideCredential() (LoginCred, error)

LoginCred is a static source of credentials and never returns an error

func (LoginCred) Zero

func (lc LoginCred) Zero() bool

type LoginState

type LoginState int
const (
	// Unstarted reflects an uninitialized login state, typical of an
	// asynchronous authentication environment
	LoginUnstarted LoginState = iota
	// Failed reflects a login that has never had a success
	LoginFailed
	// Active represents an active login token has been obtained, but makes
	// no guarantees regarding revocation of said token
	LoginActive
	// Inactive represents a token that has expired without successfully
	// being renewed with a new token (auto-refresh failure), exclusive of
	// bad credentials
	LoginInactive
	// InvalidCreds is a non-temporary failed state, requiring new credential
	// data to resolve
	LoginInvalidCreds
)

Jump to

Keyboard shortcuts

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