client

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 23 Imported by: 1

README

Community Go Client for STACKIT

Go Report Card Unit Tests Coverage Status GoDoc reference License


The client is community-supported and not an official STACKIT release, it is maintained by internal Schwarz IT teams integrating with STACKIT

Install

To install the latest stable release, run:

go get github.com/SchwarzIT/community-stackit-go-client@latest

Usage Example

In order to use the client, a STACKIT Service Account must be created and have relevant roles assigned to it.
For further assistance, please contact STACKIT support

package main

import (
	"context"
	"fmt"
	"os"

	client "github.com/SchwarzIT/community-stackit-go-client"
)

func main() {
	ctx := context.Background()
	c, err := client.New(ctx, client.Config{
		ServiceAccountEmail: os.Getenv("STACKIT_SERVICE_ACCOUNT_EMAIL"),
		ServiceAccountToken: os.Getenv("STACKIT_SERVICE_ACCOUNT_TOKEN"),
	})
	if err != nil {
		panic(err)
	}

	res, err := c.Services.Kubernetes.ProviderOptions.GetProviderOptionsWithResponse(ctx)
	if err != nil {
		panic(fmt.Errorf("preparing request failed: %s", err))
	}
	if res.HasError != nil {
		panic(fmt.Errorf("request failed: %s", res.HasError))
	}

	fmt.Println("Kubernetes availability zones are:")
	if res.JSON200.AvailabilityZones != nil {
		for _, zone := range *res.JSON200.AvailabilityZones {
			if zone.Name == nil {
				continue
			}
			fmt.Printf("- %s\n", *zone.Name)
		}
	}
}


Further usage examples can be found in terraform-provider-stackit

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Services services

	// Legacy
	//----------
	// Productive services - services that are ready to be used in production
	ProductiveServices

	// Incubator - services under development or currently being tested
	// not ready for production usage
	Incubator IncubatorServices
	// contains filtered or unexported fields
}

Client service for managing interactions with STACKIT API

func MockServer

func MockServer() (c *Client, mux *http.ServeMux, teardown func(), err error)

MockServer mocks STACKIT api server and returns a client pointing to it, mux, teardown function and an error indicator

func New

func New(ctx context.Context, cfg Config) (*Client, error)

New returns a new client

func (*Client) Clone added in v1.1.0

func (c *Client) Clone() common.Client

Clone creates a shallow clone of the client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) GetBaseURL added in v1.1.0

func (c *Client) GetBaseURL() string

GetBaseURL returns the base url string

func (*Client) GetConfig

func (c *Client) GetConfig() Config

GetConfig returns the client config

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

GetHTTPClient returns the HTTP client

func (*Client) LegacyDo added in v1.3.0

func (c *Client) LegacyDo(req *http.Request, v interface{}, errorHandlers ...func(*http.Response) error) (*http.Response, error)

LegacyDo performs the request, including retry if set To set retry, use WithRetry() which returns a shalow copy of the client

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, body []byte) (*http.Request, error)

Request creates a new API request

func (*Client) SetBaseURL added in v1.1.0

func (c *Client) SetBaseURL(url string) error

SetBaseURL sets the base url

func (*Client) SetToken

func (c *Client) SetToken(token string)

type Config

type Config struct {
	BaseUrl             *url.URL
	ServiceAccountToken string
	ServiceAccountEmail string
}

Config is the STACKIT client configuration

func (*Config) SetURL

func (c *Config) SetURL(value string) error

SetURL sets a given url string as the base url in the config if the given value is empty, the default base URL will be used

func (*Config) Validate

func (c *Config) Validate() error

Validate verifies that the given config is valid

type IncubatorServices

type IncubatorServices struct {
}

IncubatorServices is the struct representing all services that are under development

type ProductiveServices

type ProductiveServices struct {
	Argus              *argus.ArgusService
	Costs              *costs.CostsService
	DataServices       DataServices
	Kubernetes         *kubernetes.KubernetesService
	Membership         *membership.MembershipService
	MongoDBFlex        *mongodbFlex.MongoDBService
	ObjectStorage      *objectstorage.ObjectStorageService
	PostgresFlex       *postgresFlex.PostgresService
	ResourceManagement *resourceManagement.ResourceManagementService
}

ProductiveServices is the struct representing all productive services

Directories

Path Synopsis
examples
internal
common
client file in package common holds the client interface and service struct used by each service that the client is connecting with services using the Service struct are located under pkg/api
client file in package common holds the client interface and service struct used by each service that the client is connecting with services using the Service struct are located under pkg/api
pkg
api/v2/membership/roles
package roles is used for creating and managing custom roles (and permissions assigned to them)
package roles is used for creating and managing custom roles (and permissions assigned to them)
services/kubernetes/v1.0/generated
Package kubernetes provides primitives to interact with the openapi HTTP API.
Package kubernetes provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0/generated/cluster
Package cluster provides primitives to interact with the openapi HTTP API.
Package cluster provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0/generated/credentials
Package credentials provides primitives to interact with the openapi HTTP API.
Package credentials provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0/generated/operation
Package operation provides primitives to interact with the openapi HTTP API.
Package operation provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0/generated/project
Package project provides primitives to interact with the openapi HTTP API.
Package project provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0/generated/provider-options
Package provideroptions provides primitives to interact with the openapi HTTP API.
Package provideroptions provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated
Package postgresflex provides primitives to interact with the openapi HTTP API.
Package postgresflex provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/backups
Package backups provides primitives to interact with the openapi HTTP API.
Package backups provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/flavors
Package flavors provides primitives to interact with the openapi HTTP API.
Package flavors provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/instance
Package instance provides primitives to interact with the openapi HTTP API.
Package instance provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/storage
Package storage provides primitives to interact with the openapi HTTP API.
Package storage provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/users
Package users provides primitives to interact with the openapi HTTP API.
Package users provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0/generated/versions
Package versions provides primitives to interact with the openapi HTTP API.
Package versions provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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