Documentation
¶
Overview ¶
Example ¶
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/ttab/clitools"
)
func main() {
// SampleConf - any addional configuration you want to store.
type SampleConf struct {
SomeSetting string `json:"some_setting"`
}
env := clitools.EnvStage
println("Sample application that demonstrates logging in to elephant from a CLI tool\n")
app, err := clitools.NewConfigurationHandler[SampleConf]("clitools", "elephant-cli")
if err != nil {
panic(fmt.Errorf("create configuration handler: %w", err))
}
token, err := app.GetAccessToken(context.Background(), env, []string{
"doc_read",
})
if err != nil {
panic(fmt.Errorf("authenticate: %w", err))
}
app.SetConfiguration(SampleConf{
SomeSetting: "that we want to track",
})
err = app.Save()
if err != nil {
panic(fmt.Errorf("save configuration: %w", err))
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
println("Current token:")
_ = enc.Encode(token)
}
Index ¶
- Constants
- type AccessToken
- type ConfigurationHandler
- func (ac *ConfigurationHandler[T]) GetAccessToken(ctx context.Context, environment string, scopes []string) (_ AccessToken, outErr error)
- func (ac *ConfigurationHandler[T]) GetConfiguration() T
- func (ac *ConfigurationHandler[T]) RegisterEnvironment(ctx context.Context, name string, configURL string) error
- func (ac *ConfigurationHandler[T]) Save() error
- func (ac *ConfigurationHandler[T]) SetConfiguration(conf T)
Examples ¶
Constants ¶
View Source
const ( EnvLocal = "local" EnvStage = "stage" EnvProd = "prod" StageOIDCConfigURL = "https://login.stage.tt.se/realms/elephant/.well-known/openid-configuration" ProdOIDCConfigURL = "https://login.tt.se/realms/elephant/.well-known/openid-configuration" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type ConfigurationHandler ¶
type ConfigurationHandler[T any] struct { // contains filtered or unexported fields }
func NewConfigurationHandler ¶
func NewConfigurationHandler[T any](name string, clientID string) (*ConfigurationHandler[T], error)
func (*ConfigurationHandler[T]) GetAccessToken ¶
func (ac *ConfigurationHandler[T]) GetAccessToken( ctx context.Context, environment string, scopes []string, ) (_ AccessToken, outErr error)
func (*ConfigurationHandler[T]) GetConfiguration ¶
func (ac *ConfigurationHandler[T]) GetConfiguration() T
func (*ConfigurationHandler[T]) RegisterEnvironment ¶
func (*ConfigurationHandler[T]) Save ¶
func (ac *ConfigurationHandler[T]) Save() error
func (*ConfigurationHandler[T]) SetConfiguration ¶
func (ac *ConfigurationHandler[T]) SetConfiguration(conf T)
Click to show internal directories.
Click to hide internal directories.