Skip to content
Merged
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
11 changes: 0 additions & 11 deletions internal/aiven/permission.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/debug/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Run(workloadName, team, environment string, flags *flag.Debug, out *naistri
return err
}

dg := Setup(clientSet, flags.DebugSticky, workloadName, debugImageDefault, flags.ByPod, out)
dg := Setup(clientSet, flags, workloadName, debugImageDefault, flags.ByPod, out)
if err := dg.Debug(); err != nil {
return fmt.Errorf("debugging instance: %w", err)
}
Expand Down
4 changes: 1 addition & 3 deletions internal/debug/command/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
)

func Debug(parentFlags *flags.GlobalFlags) *naistrix.Command {
stickyFlags := &flag.DebugSticky{GlobalFlags: parentFlags}
debugFlags := &flag.Debug{DebugSticky: stickyFlags}
debugFlags := &flag.Debug{GlobalFlags: parentFlags}
return &naistrix.Command{
Name: "debug",
Title: "Create and attach to a debug container.",
Expand All @@ -28,7 +27,6 @@ func Debug(parentFlags *flags.GlobalFlags) *naistrix.Command {
{Name: "app_name"},
},
Flags: debugFlags,
StickyFlags: stickyFlags,
ValidateFunc: validation.RequireTeamAndEnvironment(debugFlags),
RunFunc: func(ctx context.Context, args *naistrix.Arguments, out *naistrix.OutputWriter) error {
return debug.Run(args.Get("app_name"), debugFlags.Team, string(debugFlags.Environment), debugFlags, out)
Expand Down
18 changes: 3 additions & 15 deletions internal/debug/command/flag/flag.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
package flag

import (
"github.com/nais/cli/internal/flags"
)

type (
DebugSticky struct {
*flags.GlobalFlags
Copy bool `name:"copy" usage:"Create a copy of the pod with a debug container. The original pod remains running and unaffected."`
}
)
import "github.com/nais/cli/internal/flags"

type Debug struct {
*DebugSticky
*flags.GlobalFlags
Copy bool `name:"copy" usage:"Create a copy of the pod with a debug container. The original pod remains running and unaffected."`
ByPod bool `name:"by-pod" short:"b" usage:"Attach to a specific |BY-POD| in a workload."`
}

type DebugTidy struct {
*DebugSticky
}
4 changes: 2 additions & 2 deletions internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const (
type Debug struct {
ctx context.Context
client kubernetes.Interface
flags *flag.DebugSticky
flags *flag.Debug
workloadName string
debugImage string
byPod bool
out *naistrix.OutputWriter
}

func Setup(client kubernetes.Interface, flags *flag.DebugSticky, workloadName, debugImage string, byPod bool, out *naistrix.OutputWriter) *Debug {
func Setup(client kubernetes.Interface, flags *flag.Debug, workloadName, debugImage string, byPod bool, out *naistrix.OutputWriter) *Debug {
return &Debug{
ctx: context.Background(),
client: client,
Expand Down
1,209 changes: 899 additions & 310 deletions internal/naisapi/gql/generated.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/opensearch/command/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package command
import (
"context"
"fmt"
"slices"
"strconv"

"github.com/nais/cli/internal/aiven"
"github.com/nais/cli/internal/naisapi/gql"
"github.com/nais/cli/internal/opensearch"
"github.com/nais/cli/internal/opensearch/command/flag"
Expand All @@ -30,8 +30,8 @@ func credentials(parentFlags *flag.OpenSearch) *naistrix.Command {
if flags.Permission == "" {
return fmt.Errorf("permission is required, set using --permission/-p flag (READ, WRITE, READWRITE, ADMIN)")
}
if !aiven.IsValidPermission(gql.CredentialPermission(flags.Permission)) {
return fmt.Errorf("invalid permission %q, must be one of: %v", flags.Permission, gql.AllCredentialPermission)
if !slices.Contains(gql.AllOpenSearchPermission, gql.OpenSearchPermission(flags.Permission)) {
return fmt.Errorf("invalid permission %q, must be one of: %v", flags.Permission, gql.AllOpenSearchPermission)
}
if flags.TTL == "" {
return fmt.Errorf("ttl is required, set using --ttl flag (e.g. '1d', '7d')")
Expand All @@ -57,7 +57,7 @@ func credentials(parentFlags *flag.OpenSearch) *naistrix.Command {
flags.Team,
string(flags.Environment),
args.Get("name"),
gql.CredentialPermission(flags.Permission),
gql.OpenSearchPermission(flags.Permission),
flags.TTL,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/opensearch/command/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ type Permission string
var _ naistrix.FlagAutoCompleter = (*Permission)(nil)

func (p *Permission) AutoComplete(context.Context, *naistrix.Arguments, string, any) ([]string, string) {
perms := make([]string, 0, len(gql.AllCredentialPermission))
for _, perm := range gql.AllCredentialPermission {
perms = append(perms, string(perm))
perms := make([]string, len(gql.AllOpenSearchPermission))
for i, perm := range gql.AllOpenSearchPermission {
perms[i] = string(perm)
}
return perms, "Available permission levels."
}
4 changes: 2 additions & 2 deletions internal/opensearch/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"github.com/nais/cli/internal/naisapi/gql"
)

func CreateCredentials(ctx context.Context, teamSlug, environmentName, instanceName string, permission gql.CredentialPermission, ttl string) (*gql.CreateOpenSearchCredentialsCreateOpenSearchCredentialsCreateOpenSearchCredentialsPayloadCredentialsOpenSearchCredentials, error) {
func CreateCredentials(ctx context.Context, teamSlug, environmentName, instanceName string, permission gql.OpenSearchPermission, ttl string) (*gql.CreateOpenSearchCredentialsCreateOpenSearchCredentialsCreateOpenSearchCredentialsPayloadCredentialsOpenSearchCredentials, error) {
_ = `# @genqlient
mutation CreateOpenSearchCredentials(
$teamSlug: Slug!,
$environmentName: String!,
$instanceName: String!,
$permission: CredentialPermission!,
$permission: OpenSearchPermission!,
$ttl: String!,
) {
createOpenSearchCredentials(
Expand Down
8 changes: 4 additions & 4 deletions internal/valkey/command/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package command
import (
"context"
"fmt"
"slices"
"strconv"

"github.com/nais/cli/internal/aiven"
"github.com/nais/cli/internal/naisapi/gql"
"github.com/nais/cli/internal/validation"
"github.com/nais/cli/internal/valkey"
Expand All @@ -28,8 +28,8 @@ func credentials(parentFlags *flag.Valkey) *naistrix.Command {
if flags.Permission == "" {
return fmt.Errorf("permission is required, set using --permission/-p flag (READ, WRITE, READWRITE, ADMIN)")
}
if !aiven.IsValidPermission(gql.CredentialPermission(flags.Permission)) {
return fmt.Errorf("invalid permission %q, must be one of: %v", flags.Permission, gql.AllCredentialPermission)
if !slices.Contains(gql.AllValkeyPermission, gql.ValkeyPermission(flags.Permission)) {
return fmt.Errorf("invalid permission %q, must be one of: %v", flags.Permission, gql.AllValkeyPermission)
}
if flags.TTL == "" {
return fmt.Errorf("ttl is required, set using --ttl flag (e.g. '1d', '7d')")
Expand All @@ -55,7 +55,7 @@ func credentials(parentFlags *flag.Valkey) *naistrix.Command {
flags.Team,
string(flags.Environment),
args.Get("name"),
gql.CredentialPermission(flags.Permission),
gql.ValkeyPermission(flags.Permission),
flags.TTL,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/valkey/command/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ type Permission string
var _ naistrix.FlagAutoCompleter = (*Permission)(nil)

func (p *Permission) AutoComplete(context.Context, *naistrix.Arguments, string, any) ([]string, string) {
perms := make([]string, 0, len(gql.AllCredentialPermission))
for _, perm := range gql.AllCredentialPermission {
perms = append(perms, string(perm))
perms := make([]string, len(gql.AllValkeyPermission))
for i, perm := range gql.AllValkeyPermission {
perms[i] = string(perm)
}
return perms, "Available permission levels."
}
4 changes: 2 additions & 2 deletions internal/valkey/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"github.com/nais/cli/internal/naisapi/gql"
)

func CreateCredentials(ctx context.Context, teamSlug, environmentName, instanceName string, permission gql.CredentialPermission, ttl string) (*gql.CreateValkeyCredentialsCreateValkeyCredentialsCreateValkeyCredentialsPayloadCredentialsValkeyCredentials, error) {
func CreateCredentials(ctx context.Context, teamSlug, environmentName, instanceName string, permission gql.ValkeyPermission, ttl string) (*gql.CreateValkeyCredentialsCreateValkeyCredentialsCreateValkeyCredentialsPayloadCredentialsValkeyCredentials, error) {
_ = `# @genqlient
mutation CreateValkeyCredentials(
$teamSlug: Slug!,
$environmentName: String!,
$instanceName: String!,
$permission: CredentialPermission!,
$permission: ValkeyPermission!,
$ttl: String!,
) {
createValkeyCredentials(
Expand Down
Loading
Loading