client

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 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)
	}

	projectID := "1234"
	bucketName := "example"

	process, err := c.ObjectStorage.Buckets.Create(ctx, projectID, bucketName)
	if err != nil {
		panic(err)
	}

	// wait for bucket to be created
	if _, err := process.Wait(); err != nil {
		panic(err)
	}

	fmt.Printf("bucket '%s' created successfully", bucketName)
}

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

Enabling auto-retry

The client can automatically retry failed calls using pkg/retry

To enable retry in the client, use SetRetry in the following way:

c, _ := client.New(context.Background(), client.Config{})
c.SetRetry(retry.New())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchivedServices added in v1.0.0

type ArchivedServices struct {
	ResourceManagementV1 *resourceManagementV1.ResourceManagementV1Service
}

ArchivedServices is used for services that are being phased out

type Client

type Client struct {

	// 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

	// Archived - for services that are phased out
	Archived ArchivedServices
	// 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, v interface{}, errorHandlers ...func(*http.Response) error) (*http.Response, error)

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

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) Request

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

Request creates a new API request

func (*Client) Retry added in v0.3.0

func (c *Client) Retry() *retry.Retry

Retry returns the defined retry

func (*Client) SetBaseURL added in v1.1.0

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

SetBaseURL sets the base url

func (*Client) SetRetry added in v0.3.0

func (c *Client) SetRetry(r *retry.Retry)

SetRetry overrides default retry setting

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 {
	MongoDB  *mongodb.MongoDBService
	Postgres *postgres.PostgresService
}

IncubatorServices is the struct representing all services that are under development

type ProductiveServices

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

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)

Jump to

Keyboard shortcuts

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