auth

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "auth",
	Short: "Login using a Synthient API key",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		currentKey, err := ReadKeyring()
		if err != nil && !errors.Is(err, keyring.ErrNotFound) {
			timber.Fatal(err, "unexpected error when checking for existing key")
		}
		if flags.logout {
			if currentKey == "" {
				timber.Warning("user is not logged in, no credentials to remove")
			} else {
				err := StoreApiKey("")
				if err != nil {
					timber.Fatal(err, "failed to reset api key")
				}
				timber.Done("successfully logged out")
			}
			return
		}
		if currentKey != "" {
			var overwrite bool
			err = huh.NewConfirm().
				Title("API key already saved. Do you want to overwrite?").
				Value(&overwrite).
				WithTheme(output.HuhTheme).
				Run()
			if err != nil {
				timber.Fatal(err, "failed to confirm overwriting api key")
			}
			if !overwrite {
				return
			}
		}

		fmt.Print("Please provide Synthient API key: ")
		var key string
		err = huh.NewInput().
			EchoMode(huh.EchoModePassword).
			Title("Synthient API key").
			Value(&key).
			WithTheme(output.HuhTheme).
			Run()
		if err != nil {
			timber.Fatal(err, "reading user input failed")
		}

		key = strings.TrimSpace(strings.Trim(key, "\n"))
		if key == "" {
			timber.FatalMsg("Please provide valid key.")
		}

		err = StoreApiKey(key)
		if err != nil {
			timber.Fatal(err, "failed to store API key")
		}
		timber.Done("Stored API key encrypted in system's keychain")
	},
}

Functions

func ReadKeyring

func ReadKeyring() (string, error)

func StoreApiKey

func StoreApiKey(key string) error

func SynthientClient

func SynthientClient(config conf.Config) (synthient.Client, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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