bridgeapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 13 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 2022 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 2022 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 provides a client interface to the Crunchy Bridge Platform API for use of the Terraform provider. It lives within the internal tree to prevent external dependencies.

External dependencies are a signal that this package should be moved to its own repository and maintained as a public library.

Copyright 2022 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 2022 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 2022 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 2022 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")

	ErrorOldSecretFormat = errors.New("unexpected format for api secret, regeneration may be needed")
)
View Source
var (
	BridgeProviderNS = uuid.MustParse("cc67b0e5-7152-4d54-85ff-49a5c17fbbfe")
)

Functions

func DefaultClusterName

func DefaultClusterName() string

returns a randomized cluster name in the form of adverb-adjective-animal-dd (d = digit from 1-8)

Types

type APIMessage

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

type Account

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

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiURL *url.URL, cred Login, opts ...ClientOption) (*Client, error)

func (*Client) Account

func (c *Client) Account() (Account, error)

func (*Client) AccountTeams

func (c *Client) AccountTeams() (Teams, error)

func (*Client) Close

func (c *Client) Close() error

Close allows an explicit request to log out of the current session There is no explicit login, as login is triggered for every client call to ensure an active session state.

func (*Client) ClusterDetail

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

func (*Client) ClusterRoles

func (c *Client) ClusterRoles(id string) ([]ClusterRole, error)

func (*Client) ClusterStatus

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

func (*Client) ClustersForTeam

func (c *Client) ClustersForTeam(team_id string) ([]ClusterDetail, error)

func (*Client) CreateCluster

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

func (*Client) DeleteCluster

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

func (*Client) GetAllClusters

func (c *Client) GetAllClusters() ([]ClusterDetail, error)

func (*Client) Providers

func (c *Client) Providers() ([]Provider, error)

func (*Client) UpdateCluster

func (c *Client) UpdateCluster(id string, ur ClusterUpdateRequest) error

func (*Client) UpgradeCluster

func (c *Client) UpgradeCluster(id string, ur ClusterUpgradeRequest) error

type ClientOption

type ClientOption func(*Client) error

func WithContext

func WithContext(ctx context.Context) ClientOption

WithContext allows the client to be aware of a parent context. Currently, it is used to invalidate the access token when the provided context closes

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient allows the use of a custom-configured HTTP client for API requests, Client defaults to a default http.Client{} otherwise Setter - always returns nil error

func WithIdempotencyKey

func WithIdempotencyKey() ClientOption

WithIdempotencyKey causes the client to send an Idempotency Key header on cluster create N.B. This may have unexpected behavior tied to cached responses after system state changes invalidate the correctness of those responses

func WithImmediateLogin

func WithImmediateLogin() ClientOption

WithImmediateLogin triggers a login instead of waiting for lazy-initialization to occcur once a data function is called

func WithTokenExchange

func WithTokenExchange() ClientOption

WithTokenExchange instructs the client to force a token exchange for a short- lived token (gen 1 auth) instead of the user-managed bearer token (gen 2 auth)

func WithUserAgent

func WithUserAgent(ua string) ClientOption

WithUserAgent configures a UserAgent string to use in all requests to the API Setter - always returns nil error

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"`
	MaintWindowStart int       `json:"maintenance_window_start"`
	MemoryGB         int       `json:"memory"`
	Name             string    `json:"name"`
	PlanID           string    `json:"plan_id"`
	ProviderID       string    `json:"provider_id"`
	RegionID         string    `json:"region_id"`
	State            string    `json:"state"` // NOTE: Deprecated, but using to avoid extra status call on sync create for now
	StorageGB        int       `json:"storage"`
	TeamID           string    `json:"team_id"`
	Updated          time.Time `json:"updated_at"`
}

type ClusterDiskUsage

type ClusterDiskUsage struct {
	Available int `json:"disk_available_mb"`
	Total     int `json:"disk_total_size_mb"`
	Used      int `json:"disk_used_mb"`
}

type ClusterList

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

type ClusterRole

type ClusterRole struct {
	ClusterID string `json:"cluster_id"`
	Name      string `json:"name"`
	Password  string `json:"password"`
	TeamID    string `json:"team_id"`
	URI       string `json:"uri"`
}

type ClusterStatus

type ClusterStatus struct {
	DiskUsage      ClusterDiskUsage `json:"disk_usage"`
	OldestBackup   time.Time        `json:"oldest_backup_at"`
	OngoingUpgrade ClusterUpgrade   `json:"ongoing_upgrade"`
	State          string           `json:"state"`
}

type ClusterUpdateRequest

type ClusterUpdateRequest struct {
	MaintWindowStart *int    `json:"maintenance_window_start,omitempty"`
	Name             *string `json:"name,omitempty"`
}

type ClusterUpgrade

type ClusterUpgrade struct {
	Operations []ClusterUpgradeOperation
}

type ClusterUpgradeOperation

type ClusterUpgradeOperation struct {
	Flavor string `json:"flavor"`
	State  string `json:"state"`
}

type ClusterUpgradeRequest

type ClusterUpgradeRequest struct {
	HighAvailability *bool   `json:"is_ha,omitempty"`
	PGMajorVersion   *int    `json:"postgres_version_id,omitempty"`
	PlanID           *string `json:"plan_id,omitempty"`
	StorageGB        *int    `json:"storage,omitempty"`
}

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:"postgres_version_id"`
	HighAvailability bool   `json:"is_ha"`
}

type Login

type Login struct {
	Key    string
	Secret string
}

func (Login) Zero

func (l Login) Zero() bool

type Plan

type Plan struct {
	ID     string `json:"id"`
	CPU    int    `json:"cpu"`
	Memory int    `json:"memory"`
	Name   string `json:"display_name"`
	Rate   int    `json:"rate"`
}

type Provider

type Provider struct {
	ID       string       `json:"id"`
	Disk     ProviderDisk `json:"disk"`
	IconName string       `json:"icon_name"`
	Name     string       `json:"display_name"`
	Plans    []Plan       `json:"plans"`
	Regions  []Region     `json:"regions"`
}

type ProviderDisk

type ProviderDisk struct {
	Rate int `json:"rate"`
}

type Region

type Region struct {
	ID         string  `json:"id"`
	Name       string  `json:"display_name"`
	Location   string  `json:"location"`
	Multiplier float64 `json:"multiplier"`
}

type Team

type Team struct {
	ID      string `json:"id"`
	Default bool   `json:"is_default"`
	Name    string `json:"name"`
	Role    string `json:"role"`
}

type Teams

type Teams []Team

Jump to

Keyboard shortcuts

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