Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ go.work.sum
# GoReleaser output
dist/

# Local build of the CLI
/requesty

# Editor/IDE
.idea/
# .vscode/
213 changes: 183 additions & 30 deletions README.md

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions cmd/access_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
accessListYesFlag = "yes"
)

func newAccessListsCommand(env environment) *cobra.Command {
func newAccessListsCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "access-lists",
Aliases: []string{"access-list"},
Expand All @@ -27,6 +27,7 @@ func newAccessListsCommand(env environment) *cobra.Command {
"the list are allowed, whatever their kind, so a list with only chat models\n" +
"blocks embeddings, images and audio too. Models are grouped by modality:\n" +
"chat, embedding, image, transcription or speech.",
PersistentPreRunE: env.requireProfile,
}

cmd.PersistentFlags().Bool(jsonFlag, false, "print JSON instead of a table")
Expand All @@ -42,13 +43,13 @@ func newAccessListsCommand(env environment) *cobra.Command {
return cmd
}

func newAccessListsListCommand(env environment) *cobra.Command {
func newAccessListsListCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List the access lists in your organization",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
lists, err := env.apiv2Client.AccessLists(cmd.Context())
lists, err := env.session.client.AccessLists(cmd.Context())
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +86,7 @@ func newAccessListsListCommand(env environment) *cobra.Command {
}
}

func newAccessListsShowCommand(env environment) *cobra.Command {
func newAccessListsShowCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "show <id>",
Short: "Show one access list and the models it allows",
Expand All @@ -96,7 +97,7 @@ func newAccessListsShowCommand(env environment) *cobra.Command {
return err
}

list, err := env.apiv2Client.AccessList(cmd.Context(), id)
list, err := env.session.client.AccessList(cmd.Context(), id)
if err != nil {
return err
}
Expand Down Expand Up @@ -136,7 +137,7 @@ func newAccessListsShowCommand(env environment) *cobra.Command {
}
}

func newAccessListsCreateCommand(env environment) *cobra.Command {
func newAccessListsCreateCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Create an access list",
Expand Down Expand Up @@ -180,7 +181,7 @@ func newAccessListsCreateCommand(env environment) *cobra.Command {
input.Transcription = models[client.ModalityTranscription]
input.Speech = models[client.ModalitySpeech]

created, err := env.apiv2Client.CreateAccessList(cmd.Context(), input)
created, err := env.session.client.CreateAccessList(cmd.Context(), input)
if err != nil {
return err
}
Expand Down Expand Up @@ -226,7 +227,7 @@ func exampleModel(modality client.Modality) string {
}
}

func newAccessListsSetCommand(env environment) *cobra.Command {
func newAccessListsSetCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "set",
Short: "Set a property on an access list",
Expand All @@ -240,7 +241,7 @@ func newAccessListsSetCommand(env environment) *cobra.Command {
return cmd
}

func newAccessListsSetNameCommand(env environment) *cobra.Command {
func newAccessListsSetNameCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "name <id> <name>",
Short: "Rename an access list",
Expand All @@ -256,7 +257,7 @@ func newAccessListsSetNameCommand(env environment) *cobra.Command {
return errors.New("missing name")
}

if err := env.apiv2Client.UpdateAccessListName(cmd.Context(), id, name); err != nil {
if err := env.session.client.UpdateAccessListName(cmd.Context(), id, name); err != nil {
return err
}

Expand All @@ -265,7 +266,7 @@ func newAccessListsSetNameCommand(env environment) *cobra.Command {
}
}

func newAccessListsSetAutoApproveCommand(env environment) *cobra.Command {
func newAccessListsSetAutoApproveCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "auto-approve <id>",
Short: "Approve new models matching an access list automatically",
Expand All @@ -278,7 +279,7 @@ func newAccessListsSetAutoApproveCommand(env environment) *cobra.Command {
return err
}

if err := env.apiv2Client.UpdateAccessListAutoApprove(cmd.Context(), id, true); err != nil {
if err := env.session.client.UpdateAccessListAutoApprove(cmd.Context(), id, true); err != nil {
return err
}

Expand All @@ -288,7 +289,7 @@ func newAccessListsSetAutoApproveCommand(env environment) *cobra.Command {
}
}

func newAccessListsSetModelsCommand(env environment) *cobra.Command {
func newAccessListsSetModelsCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "models <id> <modality> <model>...",
Short: "Set the models of one modality on an access list",
Expand Down Expand Up @@ -326,7 +327,7 @@ func newAccessListsSetModelsCommand(env environment) *cobra.Command {
return err
}

err = env.apiv2Client.UpdateAccessListModels(cmd.Context(), id, map[client.Modality][]string{modality: models})
err = env.session.client.UpdateAccessListModels(cmd.Context(), id, map[client.Modality][]string{modality: models})
if err != nil {
return err
}
Expand All @@ -338,7 +339,7 @@ func newAccessListsSetModelsCommand(env environment) *cobra.Command {
}
}

func newAccessListsClearCommand(env environment) *cobra.Command {
func newAccessListsClearCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "clear",
Short: "Clear a property on an access list",
Expand All @@ -351,7 +352,7 @@ func newAccessListsClearCommand(env environment) *cobra.Command {
return cmd
}

func newAccessListsClearAutoApproveCommand(env environment) *cobra.Command {
func newAccessListsClearAutoApproveCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "auto-approve <id>",
Short: "Stop approving new models on an access list automatically",
Expand All @@ -362,7 +363,7 @@ func newAccessListsClearAutoApproveCommand(env environment) *cobra.Command {
return err
}

if err := env.apiv2Client.UpdateAccessListAutoApprove(cmd.Context(), id, false); err != nil {
if err := env.session.client.UpdateAccessListAutoApprove(cmd.Context(), id, false); err != nil {
return err
}

Expand All @@ -372,7 +373,7 @@ func newAccessListsClearAutoApproveCommand(env environment) *cobra.Command {
}
}

func newAccessListsClearModelsCommand(env environment) *cobra.Command {
func newAccessListsClearModelsCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "models <id> <modality>...",
Short: "Remove every model of one or more modalities from an access list",
Expand Down Expand Up @@ -409,7 +410,7 @@ func newAccessListsClearModelsCommand(env environment) *cobra.Command {
names = append(names, string(modality))
}

if err := env.apiv2Client.UpdateAccessListModels(cmd.Context(), id, cleared); err != nil {
if err := env.session.client.UpdateAccessListModels(cmd.Context(), id, cleared); err != nil {
return err
}

Expand All @@ -419,7 +420,7 @@ func newAccessListsClearModelsCommand(env environment) *cobra.Command {
}
}

func newAccessListsDeleteCommand(env environment) *cobra.Command {
func newAccessListsDeleteCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "delete <id>",
Short: "Delete an access list",
Expand Down Expand Up @@ -453,7 +454,7 @@ func newAccessListsDeleteCommand(env environment) *cobra.Command {
}
}

if err := env.apiv2Client.DeleteAccessList(cmd.Context(), id); err != nil {
if err := env.session.client.DeleteAccessList(cmd.Context(), id); err != nil {
return err
}

Expand Down
39 changes: 20 additions & 19 deletions cmd/api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ const (
apiKeyYesFlag = "yes"
)

func newAPIKeysCommand(env environment) *cobra.Command {
func newAPIKeysCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "api-keys",
Aliases: []string{"api-key", "keys"},
Short: "Manage the API keys in your organization",
Long: "Manage the API keys in your organization.\n\n" +
"The show command also takes " + client.SelfAPIKeyID +
" as the id, meaning the key this CLI is configured with.",
PersistentPreRunE: env.requireProfile,
}

cmd.PersistentFlags().Bool(jsonFlag, false, "print JSON instead of a table")
Expand All @@ -47,13 +48,13 @@ func newAPIKeysCommand(env environment) *cobra.Command {
return cmd
}

func newAPIKeysListCommand(env environment) *cobra.Command {
func newAPIKeysListCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List the API keys in your organization",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
keys, err := env.apiv2Client.APIKeys(cmd.Context())
keys, err := env.session.client.APIKeys(cmd.Context())
if err != nil {
return err
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func newAPIKeysListCommand(env environment) *cobra.Command {
}
}

func newAPIKeysShowCommand(env environment) *cobra.Command {
func newAPIKeysShowCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "show <id>",
Short: "Show one API key",
Expand All @@ -98,7 +99,7 @@ func newAPIKeysShowCommand(env environment) *cobra.Command {
return err
}

key, err := env.apiv2Client.APIKey(cmd.Context(), id)
key, err := env.session.client.APIKey(cmd.Context(), id)
if err != nil {
return err
}
Expand All @@ -122,7 +123,7 @@ func newAPIKeysShowCommand(env environment) *cobra.Command {
}
}

func newAPIKeysCreateCommand(env environment) *cobra.Command {
func newAPIKeysCreateCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Create an API key",
Expand Down Expand Up @@ -165,7 +166,7 @@ func newAPIKeysCreateCommand(env environment) *cobra.Command {
}
input.Permissions = permissions

created, err := env.apiv2Client.CreateAPIKey(cmd.Context(), input)
created, err := env.session.client.CreateAPIKey(cmd.Context(), input)
if err != nil {
return err
}
Expand Down Expand Up @@ -199,7 +200,7 @@ func newAPIKeysCreateCommand(env environment) *cobra.Command {
return cmd
}

func newAPIKeysSetCommand(env environment) *cobra.Command {
func newAPIKeysSetCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "set",
Short: "Set a property on an API key",
Expand All @@ -213,7 +214,7 @@ func newAPIKeysSetCommand(env environment) *cobra.Command {
return cmd
}

func newAPIKeysSetLimitCommand(env environment) *cobra.Command {
func newAPIKeysSetLimitCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "limit <id> <amount>",
Short: "Set the monthly spending cap of an API key",
Expand All @@ -231,7 +232,7 @@ func newAPIKeysSetLimitCommand(env environment) *cobra.Command {
return err
}

if err := env.apiv2Client.UpdateAPIKeyLimit(cmd.Context(), id, limit); err != nil {
if err := env.session.client.UpdateAPIKeyLimit(cmd.Context(), id, limit); err != nil {
return err
}

Expand All @@ -241,7 +242,7 @@ func newAPIKeysSetLimitCommand(env environment) *cobra.Command {
}
}

func newAPIKeysSetLabelsCommand(env environment) *cobra.Command {
func newAPIKeysSetLabelsCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "labels <id> <key=value>...",
Short: "Set the labels on an API key",
Expand Down Expand Up @@ -271,7 +272,7 @@ func newAPIKeysSetLabelsCommand(env environment) *cobra.Command {
return err
}

if err := env.apiv2Client.UpdateAPIKeyLabels(cmd.Context(), id, labels); err != nil {
if err := env.session.client.UpdateAPIKeyLabels(cmd.Context(), id, labels); err != nil {
return err
}

Expand All @@ -281,7 +282,7 @@ func newAPIKeysSetLabelsCommand(env environment) *cobra.Command {
}
}

func newAPIKeysClearCommand(env environment) *cobra.Command {
func newAPIKeysClearCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "clear",
Short: "Clear a property on an API key",
Expand All @@ -291,7 +292,7 @@ func newAPIKeysClearCommand(env environment) *cobra.Command {
return cmd
}

func newAPIKeysClearLabelsCommand(env environment) *cobra.Command {
func newAPIKeysClearLabelsCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "labels <id>",
Short: "Remove every label from an API key",
Expand All @@ -302,7 +303,7 @@ func newAPIKeysClearLabelsCommand(env environment) *cobra.Command {
return err
}

if err := env.apiv2Client.UpdateAPIKeyLabels(cmd.Context(), id, nil); err != nil {
if err := env.session.client.UpdateAPIKeyLabels(cmd.Context(), id, nil); err != nil {
return err
}

Expand All @@ -311,7 +312,7 @@ func newAPIKeysClearLabelsCommand(env environment) *cobra.Command {
}
}

func newAPIKeysSetExpiryCommand(env environment) *cobra.Command {
func newAPIKeysSetExpiryCommand(env *environment) *cobra.Command {
return &cobra.Command{
Use: "expiry <id> <time|" + util.NeverExpires + ">",
Short: "Set when an API key stops working",
Expand All @@ -334,7 +335,7 @@ func newAPIKeysSetExpiryCommand(env environment) *cobra.Command {
expiresAt = &parsed
}

if err := env.apiv2Client.UpdateAPIKeyExpiry(cmd.Context(), id, expiresAt); err != nil {
if err := env.session.client.UpdateAPIKeyExpiry(cmd.Context(), id, expiresAt); err != nil {
return err
}

Expand All @@ -348,7 +349,7 @@ func newAPIKeysSetExpiryCommand(env environment) *cobra.Command {
}
}

func newAPIKeysDeleteCommand(env environment) *cobra.Command {
func newAPIKeysDeleteCommand(env *environment) *cobra.Command {
cmd := &cobra.Command{
Use: "delete <id>",
Short: "Delete an API key",
Expand Down Expand Up @@ -381,7 +382,7 @@ func newAPIKeysDeleteCommand(env environment) *cobra.Command {
}
}

if err := env.apiv2Client.DeleteAPIKey(cmd.Context(), id); err != nil {
if err := env.session.client.DeleteAPIKey(cmd.Context(), id); err != nil {
return err
}

Expand Down
Loading
Loading