taikungoclient

package module
v0.0.0-...-f9845d5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 28

README

Taikun Go Client

This repository contains a testing version of the Taikun Go client - a generated Go library that is used to connect to the Taikun APIs by:

Generated client

An opensource tool called openapi-generator takes a JSON API specification as input and produces a library that helps to use that API inside a programming language. This process is done twice (for the Taikun WebAPI and Taikun Showback API).

Manually it would be done like this:

# Generate client
openapi-generator-cli generate -i ./swagger-taikun.json \
-g go \
--additional-properties=packageName=taikuncore \
--additional-properties=enumClassPrefix=true \
--git-user-id=Smidra \
--git-repo-id=taikungoclient/client \
-o ./client

openapi-generator-cli generate -i ./swagger-showback.json \
-g go \
--additional-properties=packageName=taikunshowback  \
--additional-properties=enumClassPrefix=true \
--git-user-id=Smidra \
--git-repo-id=taikungoclient/showbackclient \
-o ./showbackclient
Workflow

The repository is configured to do the generation automatically with GitHub Actions. Every midnight, the branches dev, staging and main get regenerated to correspond with the latest API.

Enviroment variables

The recognised environment variables are:

  • TAIKUN_API_HOST
    • Chosen endpoint of Taikun API
  • TAIKUN_AUTH_MODE
    • Define the authentication mode you wish to use
      • default (same as empty, use email+pass)
      • token (using user tokens generated from Taikun)
      • keycloak
      • autoscaler
  • TAIKUN_EMAIL
    • Used only in default authmode
  • TAIKUN_PASSWORD
    • Used only in default authmode
  • TAIKUN_ACCESS_KEY
    • Used in all other authmodes
  • TAIKUN_SECRET_KEY
    • Used in all other authmodes
Usage

Import this repository as a go module inside your go project. Use the exported function NewClient() to create an authenticated client to both client and showback client APIs. Use the exported function CreateError() to manage error messages in the API responses.

import (
	tk "github.com/itera-io/taikungoclient"
)

// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

// Execute a query into the API + graceful exit
data, response, err := myApiClient.Client.UsersAPI.UsersUserInfo(context.TODO()).Execute()
if err != nil {
	return tk.CreateError(response, err)
}

// Manipulate the gathered data
username := data.Data.GetUsername()
fmt.Printf("%s\n", username)

Import client packages to structure your queries.

import (
	taikuncore "github.com/itera-io/taikungoclient/client"
	taikunshowback "github.com/itera-io/taikungoclient/showbackclient"
)
API endpoints

The Taikun API is open for everyone to inspect. The API is a valid OpenAPI 3 specification. You can download the specification as swagger.json in the documentation. The documentation is available at api.taikun.cloud for the production API documentation

Taikun exposes 3 different APIs. You can look at them in the exposed swagger UI. Swagger APIs in Taikun are the ones most up to date.

Older versions

An older version of this library was generated by a different tool - go-swagger. Since Taikun API is at OpenAPI version 3 it no longer meets our needs because it only supports v2. At one point Taikun Terraform provider was made to use a temporary repository.

Documentation

Index

Constants

View Source
const TaikunAccessKey = "TAIKUN_ACCESS_KEY"
View Source
const TaikunApiHostEnvVar = "TAIKUN_API_HOST"
View Source
const TaikunAuthMode = "TAIKUN_AUTH_MODE"
View Source
const TaikunEmailEnvVar = "TAIKUN_EMAIL"

Enviroment variables which can be read from the command line evn.

View Source
const TaikunPasswordEnvVar = "TAIKUN_PASSWORD"
View Source
const TaikunSecretKey = "TAIKUN_SECRET_KEY"

Variables

This section is empty.

Functions

func CreateError

func CreateError(resp *http.Response, err error) error

CreateError is a helper function to convert an unsuccessful HTTP response to a taikunError struct. Function is exported because it is used by the Terraform taikun provider and Taikun CLI to show errors.

Types

type Client

type Client struct {
	// Set by the program
	Client          *taikuncore.APIClient
	ShowbackClient  *taikunshowback.APIClient
	CustomTransport *customTransport
	// contains filtered or unexported fields
}

Client is a struct representing an authenticated connection to simultaneously both Taikun Web API and Showback client

func NewClient

func NewClient() *Client

NewClient returns a client authenticated based on your environment variables defined above. It is intended to be called by other modules or packages.

func NewClientFromCredentials

func NewClientFromCredentials(email string, password string, accessKey string, secretKey string, authMode string, apiHost string) *Client

NewClientFromCredentials is a helper function not intended to be used by the user. It returns a client based on the authMode and provided credentials

func NewClientFromToken

func NewClientFromToken(token string, apiHost string) *Client

NewClientFromToken is a helper function not intended to be used by the user. It returns a client based on the token provided.

func (*Client) GetToken

func (c *Client) GetToken() string

Getter for token (Used in CLI usertoken get-bearer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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