scopes

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "scopes",
	Short: "Show Synthient scopes and whether the current key has them",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if !slices.Contains(formats, flags.format) {
			timber.FatalMsgf("invalid output format %q; valid formats: %s", flags.format, strings.Join(formats, "|"))
		}

		granted := []string{}
		config, err := conf.Read()
		if err == nil {
			client, clientErr := auth.SynthientClient(config)
			if clientErr == nil {
				config.ApplyToClient(&client)
				account, accountErr := client.GetAccount(nil)
				if accountErr == nil {
					granted = account.Scopes
				}
			}
		}

		rows := []Row{}
		for _, scope := range access.Scopes {
			rows = append(rows, Row{
				Scope:   scope.Scope,
				Grants:  scope.Grants,
				Granted: access.Has(granted, scope.Scope),
			})
		}

		out, closeOut := output.Open(flags.output)
		defer closeOut()
		switch flags.format {
		case "text":
			writeText(out, rows)
		case "json":
			output.JSON(out, rows)
		case "csv":
			writer := csv.NewWriter(out)
			err := writer.Write([]string{"scope", "grants", "granted"})
			if err != nil {
				app.Fatal(err, "failed to write csv header")
			}
			for _, row := range rows {
				err = writer.Write([]string{row.Scope, row.Grants, fmt.Sprint(row.Granted)})
				if err != nil {
					app.Fatal(err, "failed to write csv row")
				}
			}
			writer.Flush()
		}
	},
}

Functions

This section is empty.

Types

type Row

type Row struct {
	Scope   string `json:"scope"`
	Grants  string `json:"grants"`
	Granted bool   `json:"granted"`
}

Jump to

Keyboard shortcuts

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