/taikungoclient

Taikun Go Client

Primary LanguageGoApache License 2.0Apache-2.0

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.