Categorygithub.com/jess-sheneberger/cockroach-cloud-golang
repositorypackage
0.0.0-20220706214933-ca9e10582985
Repository: https://github.com/jess-sheneberger/cockroach-cloud-golang.git
Documentation: pkg.go.dev

# README

Go API client for ccloud

To regenerate run:

gen.sh

Requires openapi-generator to be installed. I used 6.0.0 on a mac. For some reason I didn't dig into too deeply, the generated code is broken (missing open curly brace on some if statements) so I just patched the results. When openapi-generator or the go plugin changes sufficiently it will likely break the patch, which will need to be removed or adjusted.

API docs API reference docs

autogenerated follows

This is an early access, experimental version of the Cloud API. The interface and output is subject to change, and there may be bugs.

Authentication

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 2022-03-31
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen For more information, please visit https://support.cockroachlabs.com

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import ccloud "github.com/jess-sheneberger/cockroach-cloud-golang"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), ccloud.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), ccloud.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), ccloud.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), ccloud.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://cockroachlabs.cloud

ClassMethodHTTP requestDescription
CockroachCloudApiAddAllowlistEntryPost /api/v1/clusters/{cluster_id}/networking/allowlistAdd a new CIDR address to the IP allowlist.
CockroachCloudApiAddAllowlistEntry2Put /api/v1/clusters/{cluster_id}/networking/allowlist/{entry.cidr_ip}/{entry.cidr_mask}Add a new CIDR address to the IP allowlist.
CockroachCloudApiCreateClusterPost /api/v1/clustersCreate and initialize a new cluster.
CockroachCloudApiCreateSQLUserPost /api/v1/clusters/{cluster_id}/sql-usersCreate a new SQL user.
CockroachCloudApiDeleteAllowlistEntryDelete /api/v1/clusters/{cluster_id}/networking/allowlist/{cidr_ip}/{cidr_mask}Delete an IP allowlist entry.
CockroachCloudApiDeleteClusterDelete /api/v1/clusters/{cluster_id}Delete a cluster and all of its data.
CockroachCloudApiDeleteSQLUserDelete /api/v1/clusters/{cluster_id}/sql-users/{name}Delete a SQL user.
CockroachCloudApiEnableCMEKPost /api/v1/clusters/{cluster_id}/cmekEnable CMEK for a cluster.
CockroachCloudApiGetCMEKClusterInfoGet /api/v1/clusters/{cluster_id}/cmekGet CMEK-related information for a cluster.
CockroachCloudApiGetClusterGet /api/v1/clusters/{cluster_id}Get extended information about a cluster.
CockroachCloudApiListAllowlistEntriesGet /api/v1/clusters/{cluster_id}/networking/allowlistGet the IP allowlist and propagation status for a cluster.
CockroachCloudApiListAvailableRegionsGet /api/v1/clusters/available-regionsList the regions available for new clusters and nodes.
CockroachCloudApiListClusterNodesGet /api/v1/clusters/{cluster_id}/nodesList nodes for a cluster.
CockroachCloudApiListClustersGet /api/v1/clustersList clusters owned by an organization.
CockroachCloudApiListSQLUsersGet /api/v1/clusters/{cluster_id}/sql-usersList SQL users for a cluster.
CockroachCloudApiUpdateAllowlistEntryPatch /api/v1/clusters/{cluster_id}/networking/allowlist/{entry.cidr_ip}/{entry.cidr_mask}Update an IP allowlist entry.
CockroachCloudApiUpdateCMEKStatusPatch /api/v1/clusters/{cluster_id}/cmekUpdate the CMEK-related status for a cluster.
CockroachCloudApiUpdateClusterPatch /api/v1/clusters/{cluster_id}Scale or edit a cluster.
CockroachCloudApiUpdateSQLUserPasswordPut /api/v1/clusters/{cluster_id}/sql-users/{name}/passwordUpdate a SQL user's password.

Documentation For Models

Documentation For Authorization

Bearer

  • Type: HTTP Bearer token authentication

Example

auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

[email protected]