contextstate

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigFilename = ".tcloud"
	DefaultAPIURL         = "https://api.thalassa.cloud"
)
View Source
const (
	ThalassaConfigEnvVar  = "THALASSA_CONFIG"
	ThalassaCConfigEnvVar = "THALASSACONFIG"

	ThalassaAccessTokenEnvVar         = "THALASSA_ACCESS_TOKEN"
	ThalassaPersonalAccessTokenEnvVar = "THALASSA_PERSONAL_ACCESS_TOKEN"
	ThalassaOIDCClientIDEnvVar        = "THALASSA_CLIENT_ID"
	ThalassaOIDCClientSecretEnvVar    = "THALASSA_CLIENT_SECRET"
	ThalassaOrganisationIDEnvVar      = "THALASSA_ORGANISATION_ID"

	ThalassaAPIEndpointEnvVar = "THALASSA_API_ENDPOINT"
)

Variables

View Source
var (
	OrganisationFlag        string
	EndpointFlag            string
	PersonalAccessTokenFlag string

	AccessTokenFlag string

	OidcClientIDFlag     string
	OidcClientSecretFlag string

	DebugFlag   bool
	ContextFlag string
)
View Source
var (
	ErrContextNotFound = errors.New("context not found")
)

Functions

func AccessToken added in v0.9.0

func AccessToken() string

func Clear

func Clear() error

func ClientId added in v0.2.0

func ClientId() string

func ClientIdOrFlag added in v0.2.0

func ClientIdOrFlag() string

func ClientSecret added in v0.2.0

func ClientSecret() string

func ClientSecretOrFlag added in v0.2.0

func ClientSecretOrFlag() string

func CombineConfigContext

func CombineConfigContext(context Context) error

func Debug added in v0.4.0

func Debug() bool

func Init

func Init()

func Load

func Load() error

func Login

func Login(ctx context.Context, token string) error

func LoginWithAPIEndpoint

func LoginWithAPIEndpoint(ctx context.Context, token, apiEndpoint string) error

func LoginWithAPIEndpointOidc added in v0.2.0

func LoginWithAPIEndpointOidc(ctx context.Context, clientID, clientSecret, apiEndpoint string) error

func LoginWithAccessToken added in v0.9.1

func LoginWithAccessToken(ctx context.Context, accessToken, apiEndpoint string) error

func Logout

func Logout() error

func Organisation

func Organisation() string

func PersonalAccessToken added in v0.9.0

func PersonalAccessToken() string

func Save

func Save() error

func Server

func Server() string

func Set

func Set(name string) error

Types

type API

type API struct {
	Server string `yaml:"server"`
}

type Config

type Config struct {
	ConfigVersion  string             `yaml:"configVersion"`
	Contexts       []ContextReference `yaml:"contexts"`
	CurrentContext string             `yaml:"current-context"`
	Servers        []Servers          `yaml:"servers"`
	Users          []Users            `yaml:"users"`
}

type ConfigManager

type ConfigManager interface {
	// Get returns the current context.
	// It returns an error if there is an issue retrieving the context.
	Get() (Context, error)

	// Set sets the current context to the one specified by name.
	// It returns an error if there is an issue setting the context.
	Set(name string) error

	// AddOrMergeContext adds a new context or merges it with an existing one.
	// It returns an error if there is an issue adding or merging the context.
	AddOrMergeContext(context Context) error

	// Load loads the context configuration from a persistent storage.
	// It returns an error if there is an issue loading the configuration.
	Load() error

	// Save saves the current context configuration to a persistent storage.
	// It returns an error if there is an issue saving the configuration.
	Save() error

	// RemoveContext removes a context from the configuration.
	// It returns an error if there is an issue removing the context.
	RemoveContext(name string) error

	// RemoveContextUser removes a user from the configuration.
	// It returns an error if there is an issue removing the user.
	RemoveContextUser(name string) error

	// RemoveContextServer removes a server from the configuration.
	// It returns an error if there is an issue removing the server.
	RemoveContextServer(name string) error

	// Config returns the current configuration.
	Config() Config
}

ConfigManager defines an interface for managing contexts within the application. It provides methods to get, set, and manipulate contexts, as well as to load and save configurations.

func GlobalConfigManager

func GlobalConfigManager() ConfigManager

func NewConfigFileContextManager

func NewConfigFileContextManager(filename string) ConfigManager

NewConfigFileContextManager creates a new context manager with the given filename.

type Context

type Context struct {
	Name         string
	Organisation string
	Servers      Servers
	Users        Users
}

func GetContext added in v0.2.0

func GetContext() (Context, error)

func GetContextConfiguration

func GetContextConfiguration() (Context, error)

type ContextRef

type ContextRef struct {
	API          string `yaml:"api"`
	User         string `yaml:"user"`
	Organisation string `yaml:"organisation"`
}

type ContextReference

type ContextReference struct {
	Name    string     `yaml:"name"`
	Context ContextRef `yaml:"context"`
}

type Servers

type Servers struct {
	Name string `yaml:"name"`
	API  API    `yaml:"api"`
}

type User

type User struct {
	Token        string `yaml:"token,omitempty"`
	AccessToken  string `yaml:"accessToken,omitempty"`
	ClientID     string `yaml:"clientID,omitempty"`
	ClientSecret string `yaml:"clientSecret,omitempty"`
}

type Users

type Users struct {
	Name string `yaml:"name"`
	User User   `yaml:"user"`
}

Jump to

Keyboard shortcuts

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