stackit

package module
v1.19.0-pre Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

README

Community Go Client for STACKIT

Go Report Card Unit Tests Coverage Status GoDoc reference License

This is a Go client designed to help developers interact with STACKIT APIs. It is maintained by the STACKIT community within Schwarz IT.

 

Installation

To install the community-stackit-go-client package, run the following command:

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

 

Usage

package main

import (
    "context"
    "fmt"

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

func main() {
    ctx := context.Background()
    c := stackit.MustNewClientWithKeyAuth(ctx)

    res, err := c.Kubernetes.ProviderOptions.List(ctx)
    if err = validate.Response(res, err, "JSON200.AvailabilityZones"); err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println("STACKIT Kubernetes Engine (SKE) availability zones:")
    for _, zone := range *res.JSON200.AvailabilityZones {
        if zone.Name == nil {
            continue
        }
        fmt.Printf("- %s\n", *zone.Name)
    }
}
  1. Copy the code above to a file called example.go

  2. Make sure environment variables for key flow are in place (read more in the Authentication section below)

  3. Now you can run the example with the following command:

    go run example.go
    

    output should look similar to:

    STACKIT Kubernetes Engine (SKE) availability zones:
    - eu01-m
    - eu01-1
    - eu01-2
    - eu01-3
    
Further Examples
  1. Under /examples directory
  2. In our terraform-provider-stackit

 

Authentication

Before you can start using the client, you will need to create a STACKIT Service Account in your project and assign it the appropriate permissions (i.e. project.owner).

After the service account has been created, you can authenticate to the client using the Key authentication flow (recommended) or with the static Token flow (less secure as the token is long-lived).

Key flow
  1. Create an RSA key pair:

    openssl req -x509 -nodes -newkey rsa:2048 -days 365 \
       -keyout private_key.pem -out public_key.pem -subj "/CN=unused"
    
  2. Create a service account key:

    • copy the private key to examples/service-accounts

    • Modify create_sa_key.go (fill out the consts)

    • Run with:

      go run create_sa_key.go
      
  3. Set environment variables:

    export STACKIT_SERVICE_ACCOUNT_KEY_PATH="sa_key.json"
    export STACKIT_PRIVATE_KEY_PATH="private_key.pem"
    
    # optionally modify the API environment to one of:
    # `dev`, `qa` or `prod` (default)
    export STACKIT_ENV=prod
    
  4. Configure the client

    package main
    
    import (
        "context"
        stackit "github.com/SchwarzIT/community-stackit-go-client"
    )
    
    func main() {
        ctx := context.Background()
        c := stackit.MustNewClientWithTokenAuth(ctx)
        // ...
    }
    
Token flow
  1. Set the following environment variables:

    export STACKIT_SERVICE_ACCOUNT_EMAIL=email
    export STACKIT_SERVICE_ACCOUNT_TOKEN=token
    
    # optionally modify the API environment to one of:
    # `dev`, `qa` or `prod` (default)
    export STACKIT_ENV=prod
    
  2. Configure the client

    package main
    
    import (
        "context"
        stackit "github.com/SchwarzIT/community-stackit-go-client"
    )
    
    func main() {
        ctx := context.Background()
        c := stackit.MustNewClientWithTokenAuth(ctx)
        // ...
    }
    

 

Contributing

If you find a bug or have an idea for a new feature, feel free to submit an issue or pull request!

Please make sure to include tests for any new functionality you add, and to run the existing tests before submitting your changes.

 

License

This project is licensed under the Apache-2.0 license - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustNewClientWithKeyAuth added in v1.19.0

func MustNewClientWithKeyAuth(ctx context.Context, cfg ...clients.KeyFlowConfig) *services.Services[clients.KeyFlowConfig]

MustNewClientWithKeyAuth panics if client initialization failed

func MustNewClientWithTokenAuth added in v1.19.0

func MustNewClientWithTokenAuth(ctx context.Context, cfg ...clients.TokenFlowConfig) *services.Services[clients.TokenFlowConfig]

MustNewClientWithTokenAuth panics if client initialization failed

func NewClientWithKeyAuth added in v1.19.0

func NewClientWithKeyAuth(ctx context.Context, cfg ...clients.KeyFlowConfig) (*services.Services[clients.KeyFlowConfig], error)

NewClientWithKeyAuth creates a new client that authenticates itself with STACKIT APIs using a service account key and a private RSA key this is the recommended way of authenticating to STACKIT API

func NewClientWithTokenAuth added in v1.19.0

func NewClientWithTokenAuth(ctx context.Context, cfg ...clients.TokenFlowConfig) (*services.Services[clients.TokenFlowConfig], error)

NewClientWithTokenAuth creates a new client that authenticates itself with STACKIT APIs using a service account token important: this approach is less secure, as the token has a long lifespan

Types

This section is empty.

Directories

Path Synopsis
examples
internal
contracts
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
env
services/argus/v1.0
Package argus provides primitives to interact with the openapi HTTP API.
Package argus provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/acl
Package acl provides primitives to interact with the openapi HTTP API.
Package acl provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/alert-config
Package alertconfig provides primitives to interact with the openapi HTTP API.
Package alertconfig provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/alert-groups
Package alertgroups provides primitives to interact with the openapi HTTP API.
Package alertgroups provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/alert-records
Package alertrecords provides primitives to interact with the openapi HTTP API.
Package alertrecords provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/alert-rules
Package alertrules provides primitives to interact with the openapi HTTP API.
Package alertrules provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/backup
Package backup provides primitives to interact with the openapi HTTP API.
Package backup provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/cert-check
Package certcheck provides primitives to interact with the openapi HTTP API.
Package certcheck provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/grafana-configs
Package grafanaconfigs provides primitives to interact with the openapi HTTP API.
Package grafanaconfigs provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/http-check
Package httpcheck provides primitives to interact with the openapi HTTP API.
Package httpcheck provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/instances
Package instances provides primitives to interact with the openapi HTTP API.
Package instances provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/logs
Package logs provides primitives to interact with the openapi HTTP API.
Package logs provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/metrics-storage-retention
Package metricsstorageretention provides primitives to interact with the openapi HTTP API.
Package metricsstorageretention provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/network-check
Package networkcheck provides primitives to interact with the openapi HTTP API.
Package networkcheck provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/ping-check
Package pingcheck provides primitives to interact with the openapi HTTP API.
Package pingcheck provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/plans
Package plans provides primitives to interact with the openapi HTTP API.
Package plans provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/scrape-config
Package scrapeconfig provides primitives to interact with the openapi HTTP API.
Package scrapeconfig provides primitives to interact with the openapi HTTP API.
services/argus/v1.0/traces
Package traces provides primitives to interact with the openapi HTTP API.
Package traces provides primitives to interact with the openapi HTTP API.
services/costs/v1.0
Package costs provides primitives to interact with the openapi HTTP API.
Package costs provides primitives to interact with the openapi HTTP API.
services/costs/v2.0
Package costs provides primitives to interact with the openapi HTTP API.
Package costs provides primitives to interact with the openapi HTTP API.
services/data-services/v1.0
Package dataservices provides primitives to interact with the openapi HTTP API.
Package dataservices provides primitives to interact with the openapi HTTP API.
services/data-services/v1.0/credentials
Package credentials provides primitives to interact with the openapi HTTP API.
Package credentials provides primitives to interact with the openapi HTTP API.
services/data-services/v1.0/instances
Package instances provides primitives to interact with the openapi HTTP API.
Package instances provides primitives to interact with the openapi HTTP API.
services/data-services/v1.0/offerings
Package offerings provides primitives to interact with the openapi HTTP API.
Package offerings provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.0
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/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/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/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/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/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/membership/v2.0
Package membership provides primitives to interact with the openapi HTTP API.
Package membership provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0
Package mongodbflex provides primitives to interact with the openapi HTTP API.
Package mongodbflex provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0/backup
Package backup provides primitives to interact with the openapi HTTP API.
Package backup provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0/flavors
Package flavors provides primitives to interact with the openapi HTTP API.
Package flavors provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0/instance
Package instance provides primitives to interact with the openapi HTTP API.
Package instance provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0/user
Package user provides primitives to interact with the openapi HTTP API.
Package user provides primitives to interact with the openapi HTTP API.
services/mongodb-flex/v1.0/versions
Package versions provides primitives to interact with the openapi HTTP API.
Package versions provides primitives to interact with the openapi HTTP API.
services/object-storage/v1.0.1
Package objectstorage provides primitives to interact with the openapi HTTP API.
Package objectstorage provides primitives to interact with the openapi HTTP API.
services/object-storage/v1.0.1/access-key
Package accesskey provides primitives to interact with the openapi HTTP API.
Package accesskey provides primitives to interact with the openapi HTTP API.
services/object-storage/v1.0.1/bucket
Package bucket provides primitives to interact with the openapi HTTP API.
Package bucket provides primitives to interact with the openapi HTTP API.
services/object-storage/v1.0.1/credentials-group
Package credentialsgroup provides primitives to interact with the openapi HTTP API.
Package credentialsgroup provides primitives to interact with the openapi HTTP API.
services/object-storage/v1.0.1/project
Package project provides primitives to interact with the openapi HTTP API.
Package project provides primitives to interact with the openapi HTTP API.
services/postgres-flex/v1.0
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/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/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/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/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/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/versions
Package versions provides primitives to interact with the openapi HTTP API.
Package versions provides primitives to interact with the openapi HTTP API.
services/resource-management/v2.0
Package resourcemanagement provides primitives to interact with the openapi HTTP API.
Package resourcemanagement provides primitives to interact with the openapi HTTP API.
services/service-accounts/v2.0
Package serviceaccounts provides primitives to interact with the openapi HTTP API.
Package serviceaccounts 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