rig

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

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 24 Imported by: 25

README

Rig Golang SDK

Overview

Rig provides the tools, modules and infrastructure you need to develop and manage applications on Kubernetes. The Rig Golang SDK enables access to Rig services from privileged environments (such as servers or cloud) in Golang.

For more information, visit the Rig Golang SDK setup guide.

Installation

The Rig Golang SDK can be installed using the go install utility:

# Install the latest version:
go get github.com/rigdev/rig-go-sdk@latest

# Or install a specific version:
go get github.com/rigdev/rig-go-sdk@x.x.x

Setup the Client

To setup the client use the rig.NewClient method:

package main

import (
	"context"
	"fmt"
	"log"

	"connectrpc.com/connect"
	rig "github.com/rigdev/rig-go-sdk"
	"github.com/rigdev/rig-go-api/api/v1/user"
)

func main() {
	client := rig.NewClient()

	// you can now make requests to Rig
	if _, err := client.User().Create(context.Background(), connect.NewRequest(&user.CreateRequest{
		Initializers: []*user.Update{},
	})); err != nil {
		log.Fatal(err)
	}

	fmt.Println("success")
}
Host

By default, the SDK will connect to http://localhost:4747. To change this, use the rig.WithHost(...) option:

	client := rig.NewClient(rig.WithHost("my-rig:4747"))
Credentials

By default, the SDK will use the environment variables RIG_CLIENT_ID and RIG_CLIENT_SECRET to read the credentials. To explicitly set the credentials, use rig.WithClientCredentials(...) option:

	client := rig.NewClient(rig.WithClientCredentials(rig.ClientCredential{
		ClientID:     "your-client-id",
		ClientSecret: "your-client-secret",
	}))

Documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Authentication service for logging in and registering new users.
	// If you are using OAuth Client Credentials for, see `WithClientCredential`.
	Authentication() authenticationconnect.ServiceClient
	// User service for managing users.
	User() userconnect.ServiceClient
	// UserSettings service for managing settings for the entire User module.
	UserSettings() usersettingsconnect.ServiceClient
	// ServiceAccount service for creating and maintaining OAuth2 Service Accounts.
	ServiceAccount() service_accountconnect.ServiceClient
	// Group service for managing groups and associating users to them.
	Group() groupconnect.ServiceClient
	// Capsule API for managing the lifecycle of Capsules.
	Capsule() capsuleconnect.ServiceClient
	// Project API for configuring the overall settings of the project.
	Project() projectconnect.ServiceClient
	// ProjectSettings service for managing settings of projects
	ProjectSettings() projectsettingsconnect.ServiceClient
	// Cluster service for managing the Rig cluster
	Cluster() clusterconnect.ServiceClient

	Image() imageconnect.ServiceClient

	Environment() environmentconnect.ServiceClient

	// Set the access- and refresh token pair. This will use the underlying SessionManager.
	// The client will refresh the tokens in the background as needed.
	SetAccessToken(accessToken, refreshToken string)
}

Client for interacting with the Rig APIs. Each of the services are available as a `connect.build` Client, allowing for a variety of communication options, such as gRPC, connect.build, HTTP/JSON.

func NewClient

func NewClient(opts ...Option) Client

type ClientCredential

type ClientCredential struct {
	ClientID     string
	ClientSecret string
}

ClientCredential to use for authenticating with the backend using the OAuth2 Client Credentials flow. Use `WithClientCredentials` when creating a new client, to set them. The client will automatically register a ClientCredential if the `RIG_CLIENT_ID` and `RIG_CLIENT_SECRET` environment variables are set.

type Interceptor

type Interceptor = connect.Interceptor

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithBasicAuthOption

func WithBasicAuthOption(cc ClientCredential) Option

func WithClient

func WithClient(client *http.Client) Option

func WithClientCredentials

func WithClientCredentials(cc ClientCredential) Option

func WithHost

func WithHost(host string) Option

func WithInterceptors

func WithInterceptors(ics ...Interceptor) Option

func WithSessionManager

func WithSessionManager(sm SessionManager) Option

type SessionManager

type SessionManager interface {
	GetAccessToken() string
	GetRefreshToken() string

	SetAccessToken(accessToken, refreshToken string)
}

SessionManager is used by the Client to help maintain the access and refresh tokens. By default, an in-memory version will be used. A custom implementation can be provided using `WithSessionManager`, if the tokens should be stored e.g. in a config file.

type WithBasicAuth

type WithBasicAuth struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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