stackit

package module
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 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

⚠️ Currently, setting up Key flow requires a slightly more technical approach as it is not yet available in the portal UI.

  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 serivce account in one of your STACKIT projects & make sure to assign permissions to it

  3. Get your access token from the portal (from the developer tools, network tab)

  4. Create a service account key:

    • Create a file called create_sa_key.go and put it in the same directory as the RSA key pair

    • Copy the contents of examples/service-accounts/create_sa_key.go to create_sa_key.go and fill out the constants

    • Run with:

      go run create_sa_key.go
      
    • a file called sa_key.json will be created

  5. Set environment variables:

    export STACKIT_SERVICE_ACCOUNT_KEY_PATH="sa_key.json"
    export STACKIT_PRIVATE_KEY_PATH="private_key.pem"
    
  6. Configure the client

    package main
    
    import (
        "context"
        stackit "github.com/SchwarzIT/community-stackit-go-client"
    )
    
    func main() {
        ctx := context.Background()
        c := stackit.MustNewClientWithKeyAuth(ctx)
        // ...
    }
    
Token flow
  1. Create a serivce account in one of your STACKIT projects & make sure to assign permissions to it

  2. Set the following environment variables:

    export STACKIT_SERVICE_ACCOUNT_EMAIL=email
    export STACKIT_SERVICE_ACCOUNT_TOKEN=token
    
  3. Configure the client

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

 

Working with non-prod environments

For each service package there's an overriding environment variable for the base URL

they are defined for every service in service.go according to the specified package name

the pattern is STACKIT_${package}_BASEURL

example: STACKIT_KUBERNETES_BASEURL or STACKIT_LOGME_BASEURL

Key authentication for non-prod

for token API set STACKIT_TOKEN_BASEURL

and for jwks.json url set STACKIT_JWKS_BASEURL

 

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

MustNewClientWithKeyAuth panics if client initialization failed

func MustNewClientWithTokenAuth added in v1.19.0

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

MustNewClientWithTokenAuth panics if client initialization failed

func NewClientWithKeyAuth added in v1.19.0

func NewClientWithKeyAuth(ctx context.Context, cfg ...clients.KeyFlowConfig) (*services.Services, 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, 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
pkg
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
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/iaas-api/v1
Package iaas provides primitives to interact with the openapi HTTP API.
Package iaas provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/area
Package area provides primitives to interact with the openapi HTTP API.
Package area provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/backups
Package backups provides primitives to interact with the openapi HTTP API.
Package backups provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/flavors
Package flavors provides primitives to interact with the openapi HTTP API.
Package flavors provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/images
Package images provides primitives to interact with the openapi HTTP API.
Package images provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/keypairs
Package keypairs provides primitives to interact with the openapi HTTP API.
Package keypairs provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/network
Package network provides primitives to interact with the openapi HTTP API.
Package network provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/probes
Package probes provides primitives to interact with the openapi HTTP API.
Package probes provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/project
Package project provides primitives to interact with the openapi HTTP API.
Package project provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/request
Package request provides primitives to interact with the openapi HTTP API.
Package request provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1/servers
Package servers provides primitives to interact with the openapi HTTP API.
Package servers provides primitives to interact with the openapi HTTP API.
services/iaas-api/v1alpha
Package iaas provides primitives to interact with the openapi HTTP API.
Package iaas provides primitives to interact with the openapi HTTP API.
services/kubernetes/v1.1
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.1/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.1/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.1/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.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/kubernetes/v1.1/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/load-balancer/1.3.0
Package loadbalancer provides primitives to interact with the openapi HTTP API.
Package loadbalancer provides primitives to interact with the openapi HTTP API.
services/load-balancer/1.3.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/load-balancer/1.3.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/load-balancer/1beta.0.0
Package loadbalancer provides primitives to interact with the openapi HTTP API.
Package loadbalancer provides primitives to interact with the openapi HTTP API.
services/load-balancer/1beta.0.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/load-balancer/1beta.0.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/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/secrets-manager/v1.1.0
Package secretsmanager provides primitives to interact with the openapi HTTP API.
Package secretsmanager provides primitives to interact with the openapi HTTP API.
services/secrets-manager/v1.1.0/acls
Package acls provides primitives to interact with the openapi HTTP API.
Package acls provides primitives to interact with the openapi HTTP API.
services/secrets-manager/v1.1.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/secrets-manager/v1.1.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/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.
services/service-enablement/v1
Package serviceenablement provides primitives to interact with the openapi HTTP API.
Package serviceenablement 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