diff --git a/.gitignore b/.gitignore index a660dbc373..fcab7d25dc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ node_modules # Local release artifacts dist/ scw-cli-v2-version + +# To avoid having differences in case you use a different shell than bash while recording the goldens +docs/commands/autocomplete.md diff --git a/cmd/scw/testdata/test-all-usage-mnq-nats-create-context-usage.golden b/cmd/scw/testdata/test-all-usage-mnq-nats-create-context-usage.golden new file mode 100644 index 0000000000..afca5ed2a7 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-mnq-nats-create-context-usage.golden @@ -0,0 +1,27 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +This command help you configure your nats cli +Contexts should are stored in $HOME/.config/nats/context +Credentials and context file are saved in your nats context folder with 0600 permissions + +USAGE: + scw mnq nats create-context [arg=value ...] + +EXAMPLES: + Create a context in your nats server + scw mnq nats create-context credentials-name= region=fr-par + +ARGS: + [nats-account-id] ID of the NATS account + [name] Name of the saved context, defaults to account name + [credentials-name] Name of the created credentials + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par) + +FLAGS: + -h, --help help for create-context + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-mnq-nats-usage.golden b/cmd/scw/testdata/test-all-usage-mnq-nats-usage.golden index f0f1cff6a0..ce8170e984 100644 --- a/cmd/scw/testdata/test-all-usage-mnq-nats-usage.golden +++ b/cmd/scw/testdata/test-all-usage-mnq-nats-usage.golden @@ -16,6 +16,9 @@ AVAILABLE COMMANDS: list-credentials List NATS credentials update-account Update the name of a NATS account +WORKFLOW COMMANDS: + create-context Create a new context for natscli + FLAGS: -h, --help help for nats diff --git a/docs/commands/mnq.md b/docs/commands/mnq.md index 7647a88119..27c7a4cc34 100644 --- a/docs/commands/mnq.md +++ b/docs/commands/mnq.md @@ -4,6 +4,7 @@ Messaging and Queuing APIs. - [MnQ NATS commands](#mnq-nats-commands) - [Create a NATS account](#create-a-nats-account) + - [Create a new context for natscli](#create-a-new-context-for-natscli) - [Create NATS credentials](#create-nats-credentials) - [Delete a NATS account](#delete-a-nats-account) - [Delete NATS credentials](#delete-nats-credentials) @@ -58,6 +59,40 @@ scw mnq nats create-account [arg=value ...] +### Create a new context for natscli + +This command help you configure your nats cli +Contexts should are stored in $HOME/.config/nats/context +Credentials and context file are saved in your nats context folder with 0600 permissions + +**Usage:** + +``` +scw mnq nats create-context [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| nats-account-id | | ID of the NATS account | +| name | | Name of the saved context, defaults to account name | +| credentials-name | | Name of the created credentials | +| region | Default: `fr-par`
One of: `fr-par` | Region to target. If none is passed will use default region from the config | + + +**Examples:** + + +Create a context in your nats server +``` +scw mnq nats create-context credentials-name= region=fr-par +``` + + + + ### Create NATS credentials Create a set of credentials for a NATS account, specified by its NATS account ID. diff --git a/internal/namespaces/mnq/v1beta1/custom.go b/internal/namespaces/mnq/v1beta1/custom.go index 583aa620ba..2ac896f7ae 100644 --- a/internal/namespaces/mnq/v1beta1/custom.go +++ b/internal/namespaces/mnq/v1beta1/custom.go @@ -11,5 +11,9 @@ func GetCommands() *core.Commands { human.RegisterMarshalerFunc(mnq.SnsInfoStatus(""), human.EnumMarshalFunc(mnqSqsInfoStatusMarshalSpecs)) + cmds.Merge(core.NewCommands( + createContextCommand(), + )) + return cmds } diff --git a/internal/namespaces/mnq/v1beta1/custom_nats.go b/internal/namespaces/mnq/v1beta1/custom_nats.go new file mode 100644 index 0000000000..8552b4687c --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/custom_nats.go @@ -0,0 +1,93 @@ +package mnq + +import ( + "context" + "fmt" + "reflect" + + "github.com/scaleway/scaleway-cli/v2/internal/core" + mnq "github.com/scaleway/scaleway-sdk-go/api/mnq/v1beta1" + "github.com/scaleway/scaleway-sdk-go/scw" +) + +type natsContext struct { + Description string `json:"description"` + URL string `json:"url"` + + // CredentialsPath is a path to file containing credentials + CredentialsPath string `json:"creds"` +} + +type CreateContextRequest struct { + NatsAccountID string + ContextName string + CredentialsName string + Region scw.Region +} + +func createContextCommand() *core.Command { + return &core.Command{ + Short: "Create a new context for natscli", + Namespace: "mnq", + Resource: "nats", + Verb: "create-context", + Groups: []string{"workflow"}, + Long: `This command help you configure your nats cli +Contexts should are stored in $HOME/.config/nats/context +Credentials and context file are saved in your nats context folder with 0600 permissions`, + Examples: []*core.Example{ + { + Short: "Create a context in your nats server", + Raw: `scw mnq nats create-context credentials-name= region=fr-par`, + }, + }, + ArgSpecs: core.ArgSpecs{ + { + Name: "nats-account-id", + Short: "ID of the NATS account", + }, + { + Name: "name", + Short: "Name of the saved context, defaults to account name", + }, + { + Name: "credentials-name", + Short: "Name of the created credentials", + }, + core.RegionArgSpec((*mnq.NatsAPI)(nil).Regions()...), + }, + ArgsType: reflect.TypeOf(CreateContextRequest{}), + Run: func(ctx context.Context, argsI interface{}) (interface{}, error) { + args := argsI.(*CreateContextRequest) + api := mnq.NewNatsAPI(core.ExtractClient(ctx)) + natsAccount, err := getNatsAccountID(ctx, args, api) + if err != nil { + return nil, err + } + + var credentialsName string + if args.CredentialsName != "" { + credentialsName = args.CredentialsName + } else { + credentialsName = natsAccount.Name + core.GetRandomName("creds") + } + credentials, err := api.CreateNatsCredentials(&mnq.NatsAPICreateNatsCredentialsRequest{ + Region: args.Region, + NatsAccountID: natsAccount.ID, + Name: credentialsName, + }, scw.WithContext(ctx)) + if err != nil { + return nil, err + } + contextPath, err := saveNATSCredentials(ctx, credentials, natsAccount) + if err != nil { + return nil, err + } + return &core.SuccessResult{ + Message: "Nats context successfully created", + Details: fmt.Sprintf("%s nats credentials was created\nSelect context using `nats context select %s`", credentials.Name, natsAccount.Name), + Resource: contextPath, + }, nil + }, + } +} diff --git a/internal/namespaces/mnq/v1beta1/custom_nats_helpers.go b/internal/namespaces/mnq/v1beta1/custom_nats_helpers.go new file mode 100644 index 0000000000..dde8875eee --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/custom_nats_helpers.go @@ -0,0 +1,136 @@ +package mnq + +import ( + "context" + "encoding/json" + "fmt" + "os" + "path/filepath" + + "github.com/scaleway/scaleway-cli/v2/internal/core" + "github.com/scaleway/scaleway-cli/v2/internal/interactive" + mnq "github.com/scaleway/scaleway-sdk-go/api/mnq/v1beta1" + "github.com/scaleway/scaleway-sdk-go/scw" +) + +type NatsEntity struct { + Name string + Content []byte +} + +func makeDirectoryIfNotExists(path string) error { + if _, err := os.Stat(path); os.IsNotExist(err) { + return os.MkdirAll(path, os.ModeDir|0755) + } + return nil +} + +func wrapError(err error, message, name, path string) error { + return &core.CliError{ + Err: err, + Message: fmt.Sprintf("%s into file %q", message, path), + Details: fmt.Sprintf("You may want to delete created credentials %q", name), + Code: 1, + } +} + +func fileExists(filePath string) bool { + _, err := os.Stat(filePath) + return !os.IsNotExist(err) +} + +func natsContextFrom(account *mnq.NatsAccount, credsPath string) []byte { + ctx := &natsContext{ + Description: "Nats context created by Scaleway CLI", + URL: account.Endpoint, + CredentialsPath: credsPath, + } + b, _ := json.Marshal(ctx) + return b +} + +func writeFile(ctx context.Context, dir string, entity *NatsEntity, extension string) (string, error) { + path := filepath.Join(dir, entity.Name+"."+extension) + if err := makeDirectoryIfNotExists(dir); err != nil { + return "", wrapError(err, "Failed to create directory", entity.Name, path) + } + if fileExists(path) { + overWrite, err := promptOverWriteFile(ctx, path) + if err != nil { + return "", wrapError(err, "Failed to prompt for overwrite", entity.Name, path) + } + if !overWrite { + return "", wrapError(nil, "File already exists", entity.Name, path) + } + } + if err := os.WriteFile(path, entity.Content, 0600); err != nil { + return "", wrapError(err, "Failed to write file", entity.Name, path) + } + _, _ = interactive.Println(entity.Name + " file has been successfully written to " + path) + return path, nil +} + +func getNATSContextDir(ctx context.Context) (string, error) { + xdgConfigHome := core.ExtractEnv(ctx, "XDG_CONFIG_HOME") + interactive.Println("xdgConfigHome:", xdgConfigHome) + if xdgConfigHome == "" { + homeDir := core.ExtractEnv(ctx, "HOME") + if homeDir == "" { + return "", fmt.Errorf("both XDG_CONFIG_HOME and HOME are not set") + } + return filepath.Join(homeDir, ".config", "nats", "context"), nil + } + return xdgConfigHome, nil +} + +func saveNATSCredentials(ctx context.Context, creds *mnq.NatsCredentials, natsAccount *mnq.NatsAccount) (string, error) { + natsContextDir, err := getNATSContextDir(ctx) + if err != nil { + return "", err + } + credsEntity := &NatsEntity{ + Name: creds.Name, + Content: []byte(creds.Credentials.Content), + } + credsPath, err := writeFile(ctx, natsContextDir, credsEntity, "creds") + if err != nil { + return "", err + } + + contextEntity := &NatsEntity{ + Name: natsAccount.Name, + Content: natsContextFrom(natsAccount, credsPath), + } + + contextPath, err := writeFile(ctx, natsContextDir, contextEntity, "json") + if err != nil { + return "", err + } + return contextPath, nil +} + +func getNatsAccountID(ctx context.Context, args *CreateContextRequest, api *mnq.NatsAPI) (*mnq.NatsAccount, error) { + var natsAccount *mnq.NatsAccount + if args.NatsAccountID == "" { + natsAccountsResp, err := api.ListNatsAccounts(&mnq.NatsAPIListNatsAccountsRequest{ + Region: args.Region, + }) + if err != nil { + return nil, fmt.Errorf("failed to list nats account: %w", err) + } + natsAccount, err = promptNatsAccounts(ctx, natsAccountsResp.NatsAccounts, natsAccountsResp.TotalCount) + if err != nil { + return nil, fmt.Errorf("failed to list nats account: %w", err) + } + } else { + var err error + natsAccount, err = api.GetNatsAccount(&mnq.NatsAPIGetNatsAccountRequest{ + Region: args.Region, + NatsAccountID: args.NatsAccountID, + }, scw.WithContext(ctx)) + if err != nil { + return nil, fmt.Errorf("failed to get nats account: %w", err) + } + } + return natsAccount, nil +} diff --git a/internal/namespaces/mnq/v1beta1/custom_nats_prompt.go b/internal/namespaces/mnq/v1beta1/custom_nats_prompt.go new file mode 100644 index 0000000000..2c6cddbfe8 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/custom_nats_prompt.go @@ -0,0 +1,53 @@ +package mnq + +import ( + "context" + "fmt" + + "github.com/scaleway/scaleway-cli/v2/internal/interactive" + mnq "github.com/scaleway/scaleway-sdk-go/api/mnq/v1beta1" +) + +func promptNatsAccounts(ctx context.Context, natsAccounts []*mnq.NatsAccount, totalCount uint64) (*mnq.NatsAccount, error) { + if totalCount == 0 { + return nil, fmt.Errorf("no nats account found, please create a NATS account with 'scw mnq nats create-account'") + } + + if !interactive.IsInteractive { + return nil, fmt.Errorf("failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode") + } + if totalCount == 1 { + return natsAccounts[0], nil + } + + defaultIndex := 0 + natsAccountsName := make([]string, len(natsAccounts)) + for i := range natsAccounts { + natsAccountsName[i] = fmt.Sprintf("%s %s", natsAccounts[i].Name, natsAccounts[i].Region) + } + prompt := interactive.ListPrompt{ + Prompt: "Choose your nats account", + Choices: natsAccountsName, + DefaultIndex: defaultIndex, + } + _, _ = interactive.Println() + index, err := prompt.Execute(ctx) + if err != nil { + return nil, err + } + return natsAccounts[index], nil +} + +func promptOverWriteFile(ctx context.Context, filePath string) (bool, error) { + if !interactive.IsInteractive { + return false, fmt.Errorf("file Exist") + } + + config := interactive.PromptBoolConfig{ + Ctx: ctx, + Prompt: "The file " + filePath + " already exists. Do you want to overwrite it?", + DefaultValue: true, + } + overWrite, _ := interactive.PromptBoolWithConfig(&config) + return overWrite, nil +} diff --git a/internal/namespaces/mnq/v1beta1/custom_nats_test.go b/internal/namespaces/mnq/v1beta1/custom_nats_test.go new file mode 100644 index 0000000000..6636e4a7cc --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/custom_nats_test.go @@ -0,0 +1,88 @@ +package mnq + +import ( + "os" + "regexp" + "testing" + + "github.com/scaleway/scaleway-cli/v2/internal/core" +) + +func Test_CreateContext(t *testing.T) { + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + BeforeFunc: createNATSAccount("NATS"), + Cmd: "scw mnq nats create-context nats-account-id={{ .NATS.ID }}", + Check: core.TestCheckCombine( + core.TestCheckGoldenAndReplacePatterns( + core.GoldenReplacement{ + Pattern: regexp.MustCompile(`cli[\w-]*creds[\w-]*`), + Replacement: "credential-placeholder", + }, + core.GoldenReplacement{ + Pattern: regexp.MustCompile("(Select context using `nats context select )cli[\\w-]*`"), + Replacement: "Select context using `nats context select context-placeholder`", + }, + ), + core.TestCheckExitCode(0), + func(t *testing.T, ctx *core.CheckFuncCtx) { + result := ctx.Result.(*core.SuccessResult) + expectedContextFile := result.Resource + if !fileExists(expectedContextFile) { + t.Errorf("Expected credentials file not found expected [%s] ", expectedContextFile) + } else { + ctx.Meta["deleteFiles"] = []string{expectedContextFile} + } + }, + ), + AfterFunc: core.AfterFuncCombine(deleteNATSAccount("NATS"), func(ctx *core.AfterFuncCtx) error { + if ctx.Meta["deleteFiles"] == nil { + return nil + } + filesToDelete := ctx.Meta["deleteFiles"].([]string) + for _, file := range filesToDelete { + err := os.Remove(file) + if err != nil { + t.Errorf("Failed to delete the file : %s", err) + } + } + return nil + }, + ), + })) +} + +func Test_CreateContextWithWrongId(t *testing.T) { + t.Run("Wrong Account ID", core.Test(&core.TestConfig{ + Commands: GetCommands(), + Cmd: "scw mnq nats create-context nats-account-id=Wrong-id", + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(1), + ), + })) +} + +func Test_CreateContextWithNoAccount(t *testing.T) { + t.Run("With No Nats Account", core.Test(&core.TestConfig{ + Commands: GetCommands(), + Cmd: "scw mnq nats create-context", + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(1), + ), + })) +} + +func Test_CreateContextNoInteractiveTermAndMultiAccount(t *testing.T) { + t.Run("Multi Nats Account and no ID", core.Test(&core.TestConfig{ + Commands: GetCommands(), + BeforeFunc: core.BeforeFuncCombine(createNATSAccount("NATS"), createNATSAccount("NATS2")), + Cmd: "scw mnq nats create-context", + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(1), + ), + AfterFunc: core.AfterFuncCombine(deleteNATSAccount("NATS"), deleteNATSAccount("NATS2")), + })) +} diff --git a/internal/namespaces/mnq/v1beta1/helpers_test.go b/internal/namespaces/mnq/v1beta1/helpers_test.go new file mode 100644 index 0000000000..c818a2c8c3 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/helpers_test.go @@ -0,0 +1,15 @@ +package mnq + +import ( + "github.com/scaleway/scaleway-cli/v2/internal/core" +) + +func createNATSAccount(metaKey string) core.BeforeFunc { + return core.ExecStoreBeforeCmd( + metaKey, + "scw mnq nats create-account") +} + +func deleteNATSAccount(metaKey string) core.AfterFunc { + return core.ExecAfterCmd("scw mnq nats delete-account {{ ." + metaKey + ".ID }}") +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml new file mode 100644 index 0000000000..a889a6f906 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml @@ -0,0 +1,211 @@ +--- +version: 1 +interactions: +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:40.034465840Z", "updated_at":"2024-02-19T15:12:40.034465840Z", + "id":"ABDLXG3FVXGC4NOWTCLQ6WKPVP3ZVL7FUKWCRH6V5R3FDMHZH5SSLXRJ", "name":"cli-mnq-confident-elion", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:40.034465840Z", "updated_at":"2024-02-19T15:12:40.034465840Z", + "id":"ABDLXG3FVXGC4NOWTCLQ6WKPVP3ZVL7FUKWCRH6V5R3FDMHZH5SSLXRJ", "name":"cli-mnq-confident-elion", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "320" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:40 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 734a7fd5-8fd1-4f87-934b-56c068e25ca0 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:40.139064899Z", "updated_at":"2024-02-19T15:12:40.139064899Z", + "id":"AAWVS4I5P67K2SEI3PDB2Q7KI772VYT5WFQZSDARYJMDIIFPC4DKES4I", "name":"cli-mnq-elegant-poincare", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:40.139064899Z", "updated_at":"2024-02-19T15:12:40.139064899Z", + "id":"AAWVS4I5P67K2SEI3PDB2Q7KI772VYT5WFQZSDARYJMDIIFPC4DKES4I", "name":"cli-mnq-elegant-poincare", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "321" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:40 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 755e7808-2737-487c-a87a-654f8613fdbf + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"total_count":6, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:48:46.687350Z", "updated_at":"2024-02-19T09:48:46.687350Z", + "id":"ABURI34PBZXAB7VDGHGK7LJX4SFBDA6PHUDR3Y2XU42QIOGHD3GKN6RS", "name":"cli-mnq-competent-moser", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:49:15.694622Z", "updated_at":"2024-02-19T09:49:15.694622Z", + "id":"ACQBLIGB4MNGFZ3RQJCI223YMJ6G3BLZ4TD32A6E56KKZT75XWEVJZKJ", "name":"cli-mnq-zealous-curie", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:24:39.062406Z", "updated_at":"2024-02-19T13:24:39.062406Z", + "id":"AAULS6BP6AZ3YFJOXBWYTCEMS35NTJ4K5GUMVKM5M4N764IJDP3SMKSS", "name":"cli-mnq-vibrant-gates", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:59:22.353551Z", "updated_at":"2024-02-19T13:59:22.353551Z", + "id":"AAMRPEMQWUCBKJ2HTGAESWJ7ITP4QFNSBYFVE5JPBLETC4TQAO3GOLKD", "name":"cli-mnq-keen-meninsky", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T15:12:40.034465Z", "updated_at":"2024-02-19T15:12:40.034465Z", + "id":"ABDLXG3FVXGC4NOWTCLQ6WKPVP3ZVL7FUKWCRH6V5R3FDMHZH5SSLXRJ", "name":"cli-mnq-confident-elion", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T15:12:40.139064Z", "updated_at":"2024-02-19T15:12:40.139064Z", + "id":"AAWVS4I5P67K2SEI3PDB2Q7KI772VYT5WFQZSDARYJMDIIFPC4DKES4I", "name":"cli-mnq-elegant-poincare", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts?order_by=created_at_asc + method: GET + response: + body: '{"total_count":6, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:48:46.687350Z", "updated_at":"2024-02-19T09:48:46.687350Z", + "id":"ABURI34PBZXAB7VDGHGK7LJX4SFBDA6PHUDR3Y2XU42QIOGHD3GKN6RS", "name":"cli-mnq-competent-moser", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:49:15.694622Z", "updated_at":"2024-02-19T09:49:15.694622Z", + "id":"ACQBLIGB4MNGFZ3RQJCI223YMJ6G3BLZ4TD32A6E56KKZT75XWEVJZKJ", "name":"cli-mnq-zealous-curie", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:24:39.062406Z", "updated_at":"2024-02-19T13:24:39.062406Z", + "id":"AAULS6BP6AZ3YFJOXBWYTCEMS35NTJ4K5GUMVKM5M4N764IJDP3SMKSS", "name":"cli-mnq-vibrant-gates", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:59:22.353551Z", "updated_at":"2024-02-19T13:59:22.353551Z", + "id":"AAMRPEMQWUCBKJ2HTGAESWJ7ITP4QFNSBYFVE5JPBLETC4TQAO3GOLKD", "name":"cli-mnq-keen-meninsky", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T15:12:40.034465Z", "updated_at":"2024-02-19T15:12:40.034465Z", + "id":"ABDLXG3FVXGC4NOWTCLQ6WKPVP3ZVL7FUKWCRH6V5R3FDMHZH5SSLXRJ", "name":"cli-mnq-confident-elion", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T15:12:40.139064Z", "updated_at":"2024-02-19T15:12:40.139064Z", + "id":"AAWVS4I5P67K2SEI3PDB2Q7KI772VYT5WFQZSDARYJMDIIFPC4DKES4I", "name":"cli-mnq-elegant-poincare", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + headers: + Content-Length: + - "1926" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:40 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 4e074529-8975-4246-8bc2-05ba6846fbc8 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ABDLXG3FVXGC4NOWTCLQ6WKPVP3ZVL7FUKWCRH6V5R3FDMHZH5SSLXRJ + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:40 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 906c4f88-d167-488f-9bd4-e3113b4cb8f4 + status: 204 No Content + code: 204 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/AAWVS4I5P67K2SEI3PDB2Q7KI772VYT5WFQZSDARYJMDIIFPC4DKES4I + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:40 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 502e796b-dbee-4fd5-9550-073c63cfb1d7 + status: 204 No Content + code: 204 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.golden new file mode 100644 index 0000000000..dc8545a5b7 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-multi-nats-account-and-no-id.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to list nats account: failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to list nats account: failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.cassette.yaml new file mode 100644 index 0000000000..b5cf39c08a --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.cassette.yaml @@ -0,0 +1,187 @@ +--- +version: 1 +interactions: +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T10:55:37.801029198Z", "updated_at":"2024-02-12T10:55:37.801029198Z", + "id":"ACWHDNNUTFG4T5TWGFVIU2J7TT5VLV2O3CAT4UXO2MCBUMJ3PXLQ56BQ", "name":"cli-mnq-great-shamir", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T10:55:37.801029198Z", "updated_at":"2024-02-12T10:55:37.801029198Z", + "id":"ACWHDNNUTFG4T5TWGFVIU2J7TT5VLV2O3CAT4UXO2MCBUMJ3PXLQ56BQ", "name":"cli-mnq-great-shamir", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "317" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:55:37 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 7a73152a-ed0b-4693-8aa3-3fdd4c8bf6c2 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T10:55:37.917806216Z", "updated_at":"2024-02-12T10:55:37.917806216Z", + "id":"AD3KXVE3JUQPXXPT7I5LXGVJUPNNMSMIE3PGG2HWCHJXLRWPXXLB3DAC", "name":"cli-mnq-condescending-blackwell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T10:55:37.917806216Z", "updated_at":"2024-02-12T10:55:37.917806216Z", + "id":"AD3KXVE3JUQPXXPT7I5LXGVJUPNNMSMIE3PGG2HWCHJXLRWPXXLB3DAC", "name":"cli-mnq-condescending-blackwell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "328" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:55:37 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 400e6de2-f18e-444e-99e5-14befe03e614 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"total_count":2, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T10:55:37.801029Z", "updated_at":"2024-02-12T10:55:37.801029Z", + "id":"ACWHDNNUTFG4T5TWGFVIU2J7TT5VLV2O3CAT4UXO2MCBUMJ3PXLQ56BQ", "name":"cli-mnq-great-shamir", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T10:55:37.917806Z", "updated_at":"2024-02-12T10:55:37.917806Z", + "id":"AD3KXVE3JUQPXXPT7I5LXGVJUPNNMSMIE3PGG2HWCHJXLRWPXXLB3DAC", "name":"cli-mnq-condescending-blackwell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts?order_by=created_at_asc + method: GET + response: + body: '{"total_count":2, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T10:55:37.801029Z", "updated_at":"2024-02-12T10:55:37.801029Z", + "id":"ACWHDNNUTFG4T5TWGFVIU2J7TT5VLV2O3CAT4UXO2MCBUMJ3PXLQ56BQ", "name":"cli-mnq-great-shamir", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T10:55:37.917806Z", "updated_at":"2024-02-12T10:55:37.917806Z", + "id":"AD3KXVE3JUQPXXPT7I5LXGVJUPNNMSMIE3PGG2HWCHJXLRWPXXLB3DAC", "name":"cli-mnq-condescending-blackwell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + headers: + Content-Length: + - "672" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:55:38 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 313fd025-841d-45a7-9ae3-3abf2d510690 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ACWHDNNUTFG4T5TWGFVIU2J7TT5VLV2O3CAT4UXO2MCBUMJ3PXLQ56BQ + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:55:38 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - ad314b07-ef53-4b50-be3e-4c5588ccd7bf + status: 204 No Content + code: 204 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/AD3KXVE3JUQPXXPT7I5LXGVJUPNNMSMIE3PGG2HWCHJXLRWPXXLB3DAC + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:55:38 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - e5f8ad64-0e66-4b5b-bdbb-bd4656b3b84d + status: 204 No Content + code: 204 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.golden new file mode 100644 index 0000000000..d893068a31 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-no-interactive-term-and-multi-account-simple.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to list nats account: Failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode. +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to list nats account: Failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode." +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.cassette.yaml new file mode 100644 index 0000000000..89b14ae202 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.cassette.yaml @@ -0,0 +1,161 @@ +--- +version: 1 +interactions: +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:39.555584178Z", "updated_at":"2024-02-19T15:12:39.555584178Z", + "id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", "name":"cli-mnq-quizzical-cohen", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:39.555584178Z", "updated_at":"2024-02-19T15:12:39.555584178Z", + "id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", "name":"cli-mnq-quizzical-cohen", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "320" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 02726b14-abc1-40f9-8a7e-eaea69798acd + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:39.555584Z", "updated_at":"2024-02-19T15:12:39.555584Z", + "id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", "name":"cli-mnq-quizzical-cohen", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF + method: GET + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-19T15:12:39.555584Z", "updated_at":"2024-02-19T15:12:39.555584Z", + "id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", "name":"cli-mnq-quizzical-cohen", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "314" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - a7ace7ab-46cb-44ca-a938-61ad1aba8b45 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"nats_account_id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", + "created_at":"2024-02-19T15:12:39.696556593Z", "updated_at":null, "id":"37c3611f-59cd-486d-a8c9-38b4f7209fe4", + "name":"cli-mnq-quizzical-cohencli-creds-epic-brattain", "credentials":{"name":"user.creds", + "content":"-----BEGIN NATS USER JWT-----\neyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiIzQkJGSENVSzQzWDJIWUlMNjVYWEZXMkxXQlU1Tk9JRFc3TktUVEpVTldFU0NJWDZIMkRRIiwiaWF0IjoxNzA4MzU1NTU5LCJpc3MiOiJBRFhMUlY3N1lTUUVaMlZUTFBVTVFYVkhENktDNFVYSVJWTFE2RTZDN0dVVFBVRlBTQVFZU05OTCIsIm5hbWUiOiJjbGktbW5xLXF1aXp6aWNhbC1jb2hlbmNsaS1jcmVkcy1lcGljLWJyYXR0YWluIiwic3ViIjoiVURMRFJRWUdFQldQNjJLNE5FWEJTWVNINFA2TlFNSFlUTUtOTUpWUUFRSVRVTlpWS0ZIWElKVlIiLCJuYXRzIjp7InB1YiI6e30sInN1YiI6e30sInN1YnMiOi0xLCJkYXRhIjotMSwicGF5bG9hZCI6LTEsImlzc3Vlcl9hY2NvdW50IjoiQUJIQ0lZVVlUVjdaVVBENDc2WEJDNDNURkhCQVFMUVhDM0dPRzNTR09OV0pEQ0NHUTNESEpTS0YiLCJ0eXBlIjoidXNlciIsInZlcnNpb24iOjJ9fQ.443N3kVkp5YAyZfNCqEgUVhQTlhgjybAkeCz63wYD3p9TzSUojH9pEKgNm_wMVB3RZOjlPZnoKvAsvrlOgGvCw\n------END + NATS USER JWT------\n\n************************* IMPORTANT *************************\nNKEY + Seed printed below can be used to sign and prove identity.\nNKEYs are sensitive + and should be treated as secrets.\n\n-----BEGIN USER NKEY SEED-----\nSUAPLJ5ZIVQTS5HW5PKHHBCDZVGDHGN7CZSA25VGINAGBJCGKGJB2NMTEM\n------END + USER NKEY SEED------\n\n*************************************************************\n"}, + "checksum":"9270fbc1dad1e000a96a2dc0b805f2c4ae1a0871"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-credentials + method: POST + response: + body: '{"nats_account_id":"ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF", + "created_at":"2024-02-19T15:12:39.696556593Z", "updated_at":null, "id":"37c3611f-59cd-486d-a8c9-38b4f7209fe4", + "name":"cli-mnq-quizzical-cohencli-creds-epic-brattain", "credentials":{"name":"user.creds", + "content":"-----BEGIN NATS USER JWT-----\neyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiIzQkJGSENVSzQzWDJIWUlMNjVYWEZXMkxXQlU1Tk9JRFc3TktUVEpVTldFU0NJWDZIMkRRIiwiaWF0IjoxNzA4MzU1NTU5LCJpc3MiOiJBRFhMUlY3N1lTUUVaMlZUTFBVTVFYVkhENktDNFVYSVJWTFE2RTZDN0dVVFBVRlBTQVFZU05OTCIsIm5hbWUiOiJjbGktbW5xLXF1aXp6aWNhbC1jb2hlbmNsaS1jcmVkcy1lcGljLWJyYXR0YWluIiwic3ViIjoiVURMRFJRWUdFQldQNjJLNE5FWEJTWVNINFA2TlFNSFlUTUtOTUpWUUFRSVRVTlpWS0ZIWElKVlIiLCJuYXRzIjp7InB1YiI6e30sInN1YiI6e30sInN1YnMiOi0xLCJkYXRhIjotMSwicGF5bG9hZCI6LTEsImlzc3Vlcl9hY2NvdW50IjoiQUJIQ0lZVVlUVjdaVVBENDc2WEJDNDNURkhCQVFMUVhDM0dPRzNTR09OV0pEQ0NHUTNESEpTS0YiLCJ0eXBlIjoidXNlciIsInZlcnNpb24iOjJ9fQ.443N3kVkp5YAyZfNCqEgUVhQTlhgjybAkeCz63wYD3p9TzSUojH9pEKgNm_wMVB3RZOjlPZnoKvAsvrlOgGvCw\n------END + NATS USER JWT------\n\n************************* IMPORTANT *************************\nNKEY + Seed printed below can be used to sign and prove identity.\nNKEYs are sensitive + and should be treated as secrets.\n\n-----BEGIN USER NKEY SEED-----\nSUAPLJ5ZIVQTS5HW5PKHHBCDZVGDHGN7CZSA25VGINAGBJCGKGJB2NMTEM\n------END + USER NKEY SEED------\n\n*************************************************************\n"}, + "checksum":"9270fbc1dad1e000a96a2dc0b805f2c4ae1a0871"}' + headers: + Content-Length: + - "1496" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - da6fa7b2-8e75-434c-b68e-445ab2cb4118 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ABHCIYUYTV7ZUPD476XBC43TFHBAQLQXC3GOG3SGONWJDCCGQ3DHJSKF + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - b6d8fe4b-60d7-4cca-8402-fad6b4e9f8c1 + status: 204 No Content + code: 204 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.golden new file mode 100644 index 0000000000..fd84f10544 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-simple.golden @@ -0,0 +1,10 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 STDOUT️ 🟩🟩🟩️ +βœ… Nats context successfully created. + credential-placeholder nats credentials was created + Select context using `nats context select context-placeholder` +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +{ + "message": "Nats context successfully created", + "details": "credential-placeholder nats credentials was created\nSelect context using `nats context select context-placeholder`" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml new file mode 100644 index 0000000000..e22f965c6b --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.cassette.yaml @@ -0,0 +1,243 @@ +--- +version: 1 +interactions: +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T13:42:48.844046546Z", "updated_at":"2024-02-12T13:42:48.844046546Z", + "id":"ABLNZ3RSOHFP4AJCQX73P5YAYBYUNTFM344LBLNPW27S6HFG3D3TKW6V", "name":"cli-mnq-infallible-montalcini", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T13:42:48.844046546Z", "updated_at":"2024-02-12T13:42:48.844046546Z", + "id":"ABLNZ3RSOHFP4AJCQX73P5YAYBYUNTFM344LBLNPW27S6HFG3D3TKW6V", "name":"cli-mnq-infallible-montalcini", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "326" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:42:48 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - b8fe05c5-1d93-41e7-a805-4c6dc430a6ec + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T13:42:48.957989820Z", "updated_at":"2024-02-12T13:42:48.957989820Z", + "id":"ACM2EJVC7HCHBIP52VCO6FXDQYXWP4UBZSD7D7KGFN43IXRBSZFYLKRR", "name":"cli-mnq-objective-bell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts + method: POST + response: + body: '{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", "region":"fr-par", + "created_at":"2024-02-12T13:42:48.957989820Z", "updated_at":"2024-02-12T13:42:48.957989820Z", + "id":"ACM2EJVC7HCHBIP52VCO6FXDQYXWP4UBZSD7D7KGFN43IXRBSZFYLKRR", "name":"cli-mnq-objective-bell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}' + headers: + Content-Length: + - "319" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:42:49 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 3bdb2950-3458-4f04-9fdb-a17feb12ac21 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"total_count":3, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T12:39:25.258881Z", "updated_at":"2024-02-12T12:39:25.258881Z", + "id":"AAGTOGPZBDUUIXX5O3NYON6PSJZZYDWJNXMEL4BV5AZ7U62BDWBRWWHI", "name":"cli-mnq-strange-rhodes", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T13:42:48.844046Z", "updated_at":"2024-02-12T13:42:48.844046Z", + "id":"ABLNZ3RSOHFP4AJCQX73P5YAYBYUNTFM344LBLNPW27S6HFG3D3TKW6V", "name":"cli-mnq-infallible-montalcini", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T13:42:48.957989Z", "updated_at":"2024-02-12T13:42:48.957989Z", + "id":"ACM2EJVC7HCHBIP52VCO6FXDQYXWP4UBZSD7D7KGFN43IXRBSZFYLKRR", "name":"cli-mnq-objective-bell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts?order_by=created_at_asc + method: GET + response: + body: '{"total_count":3, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T12:39:25.258881Z", "updated_at":"2024-02-12T12:39:25.258881Z", + "id":"AAGTOGPZBDUUIXX5O3NYON6PSJZZYDWJNXMEL4BV5AZ7U62BDWBRWWHI", "name":"cli-mnq-strange-rhodes", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T13:42:48.844046Z", "updated_at":"2024-02-12T13:42:48.844046Z", + "id":"ABLNZ3RSOHFP4AJCQX73P5YAYBYUNTFM344LBLNPW27S6HFG3D3TKW6V", "name":"cli-mnq-infallible-montalcini", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-12T13:42:48.957989Z", "updated_at":"2024-02-12T13:42:48.957989Z", + "id":"ACM2EJVC7HCHBIP52VCO6FXDQYXWP4UBZSD7D7KGFN43IXRBSZFYLKRR", "name":"cli-mnq-objective-bell", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + headers: + Content-Length: + - "987" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:42:55 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - a692af79-7978-4465-a136-a17ac68d6698 + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"nats_account_id":"AAGTOGPZBDUUIXX5O3NYON6PSJZZYDWJNXMEL4BV5AZ7U62BDWBRWWHI", + "created_at":"2024-02-12T13:42:56.513495645Z", "updated_at":null, "id":"9b7c780a-f007-4b96-ba1e-1ada829fa1fc", + "name":"cli-mnq-naughty-maxwell", "credentials":{"name":"user.creds", "content":"-----BEGIN + NATS USER JWT-----\neyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiI0NEFKNE1JMzJJQVczRFFQSVVONlc3SVhaVVJJQ0VQV1BNRVFYR1FYRFY1QUZOUlhPQTJBIiwiaWF0IjoxNzA3NzQ1Mzc2LCJpc3MiOiJBRDJTR0dHWTdRTVcyTUxPTE40RUxWT0kyUjVQNTVDVUZITVozQ1oyUjM3VFlCM1pPVkdVT1BBVCIsIm5hbWUiOiJjbGktbW5xLW5hdWdodHktbWF4d2VsbCIsInN1YiI6IlVCMkgyQUNJRlI0QURIM0RVMldOSFBSRERUUkNXRzcyWFk0QjZPNlhUU1dBWVU2QTRaU01IRUZHIiwibmF0cyI6eyJwdWIiOnt9LCJzdWIiOnt9LCJzdWJzIjotMSwiZGF0YSI6LTEsInBheWxvYWQiOi0xLCJpc3N1ZXJfYWNjb3VudCI6IkFBR1RPR1BaQkRVVUlYWDVPM05ZT042UFNKWlpZRFdKTlhNRUw0QlY1QVo3VTYyQkRXQlJXV0hJIiwidHlwZSI6InVzZXIiLCJ2ZXJzaW9uIjoyfX0.5arZE7L18mTu02b5q60hZKr7DbIOcywBAEDIn9TNIisUVtkEAuicIFPuNF1VM1WyMxCMLJEFoXU3D2w3rpBrAQ\n------END + NATS USER JWT------\n\n************************* IMPORTANT *************************\nNKEY + Seed printed below can be used to sign and prove identity.\nNKEYs are sensitive + and should be treated as secrets.\n\n-----BEGIN USER NKEY SEED-----\nSUAC7PU433GSVN4RLV4M5FD6IZOCCLL6XFQNYBFCDBUVFNVH2K2R33FMTU\n------END + USER NKEY SEED------\n\n*************************************************************\n"}, + "checksum":"0a66d4814617c9fddc3c2d60f901d12a4896ecce"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-credentials + method: POST + response: + body: '{"nats_account_id":"AAGTOGPZBDUUIXX5O3NYON6PSJZZYDWJNXMEL4BV5AZ7U62BDWBRWWHI", + "created_at":"2024-02-12T13:42:56.513495645Z", "updated_at":null, "id":"9b7c780a-f007-4b96-ba1e-1ada829fa1fc", + "name":"cli-mnq-naughty-maxwell", "credentials":{"name":"user.creds", "content":"-----BEGIN + NATS USER JWT-----\neyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiI0NEFKNE1JMzJJQVczRFFQSVVONlc3SVhaVVJJQ0VQV1BNRVFYR1FYRFY1QUZOUlhPQTJBIiwiaWF0IjoxNzA3NzQ1Mzc2LCJpc3MiOiJBRDJTR0dHWTdRTVcyTUxPTE40RUxWT0kyUjVQNTVDVUZITVozQ1oyUjM3VFlCM1pPVkdVT1BBVCIsIm5hbWUiOiJjbGktbW5xLW5hdWdodHktbWF4d2VsbCIsInN1YiI6IlVCMkgyQUNJRlI0QURIM0RVMldOSFBSRERUUkNXRzcyWFk0QjZPNlhUU1dBWVU2QTRaU01IRUZHIiwibmF0cyI6eyJwdWIiOnt9LCJzdWIiOnt9LCJzdWJzIjotMSwiZGF0YSI6LTEsInBheWxvYWQiOi0xLCJpc3N1ZXJfYWNjb3VudCI6IkFBR1RPR1BaQkRVVUlYWDVPM05ZT042UFNKWlpZRFdKTlhNRUw0QlY1QVo3VTYyQkRXQlJXV0hJIiwidHlwZSI6InVzZXIiLCJ2ZXJzaW9uIjoyfX0.5arZE7L18mTu02b5q60hZKr7DbIOcywBAEDIn9TNIisUVtkEAuicIFPuNF1VM1WyMxCMLJEFoXU3D2w3rpBrAQ\n------END + NATS USER JWT------\n\n************************* IMPORTANT *************************\nNKEY + Seed printed below can be used to sign and prove identity.\nNKEYs are sensitive + and should be treated as secrets.\n\n-----BEGIN USER NKEY SEED-----\nSUAC7PU433GSVN4RLV4M5FD6IZOCCLL6XFQNYBFCDBUVFNVH2K2R33FMTU\n------END + USER NKEY SEED------\n\n*************************************************************\n"}, + "checksum":"0a66d4814617c9fddc3c2d60f901d12a4896ecce"}' + headers: + Content-Length: + - "1442" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:42:56 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - d1031e49-1bc5-4738-9a12-c9134dbec80a + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ABLNZ3RSOHFP4AJCQX73P5YAYBYUNTFM344LBLNPW27S6HFG3D3TKW6V + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:43:04 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - b57481a8-f31d-4f7c-b164-4010accb6bc7 + status: 204 No Content + code: 204 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/ACM2EJVC7HCHBIP52VCO6FXDQYXWP4UBZSD7D7KGFN43IXRBSZFYLKRR + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 13:43:04 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 3c165ade-049a-47f5-9410-a41afacd6070 + status: 204 No Content + code: 204 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.golden new file mode 100644 index 0000000000..5e8cf12f47 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-interative-term-and-multi-account-multi-nats-account-and-no-id.golden @@ -0,0 +1,12 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to write context into file "/Users/jonathan-remy/.config/nats/context/cli-mnq-strange-rhodes.json" + +Details: +You may want to delete created credentials "cli-mnq-strange-rhodes" +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "message": "Failed to write context into file \"/Users/jonathan-remy/.config/nats/context/cli-mnq-strange-rhodes.json\"", + "error": {}, + "details": "You may want to delete created credentials \"cli-mnq-strange-rhodes\"" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.cassette.yaml new file mode 100644 index 0000000000..b589906fda --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.cassette.yaml @@ -0,0 +1,35 @@ +--- +version: 1 +interactions: +- request: + body: '{"total_count":0, "nats_accounts":[]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts?order_by=created_at_asc + method: GET + response: + body: '{"total_count":0, "nats_accounts":[]}' + headers: + Content-Length: + - "37" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:52:18 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 972cbf89-623c-4f02-b8f7-273bd0d75dfa + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.golden new file mode 100644 index 0000000000..127dd36d16 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-simple.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to list nats account: No NATS account found, please create a NATS account with 'scw mnq nats create-account' +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to list nats account: No NATS account found, please create a NATS account with 'scw mnq nats create-account'" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.cassette.yaml new file mode 100644 index 0000000000..bcc55de778 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.cassette.yaml @@ -0,0 +1,59 @@ +--- +version: 1 +interactions: +- request: + body: '{"total_count":4, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:48:46.687350Z", "updated_at":"2024-02-19T09:48:46.687350Z", + "id":"ABURI34PBZXAB7VDGHGK7LJX4SFBDA6PHUDR3Y2XU42QIOGHD3GKN6RS", "name":"cli-mnq-competent-moser", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:49:15.694622Z", "updated_at":"2024-02-19T09:49:15.694622Z", + "id":"ACQBLIGB4MNGFZ3RQJCI223YMJ6G3BLZ4TD32A6E56KKZT75XWEVJZKJ", "name":"cli-mnq-zealous-curie", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:24:39.062406Z", "updated_at":"2024-02-19T13:24:39.062406Z", + "id":"AAULS6BP6AZ3YFJOXBWYTCEMS35NTJ4K5GUMVKM5M4N764IJDP3SMKSS", "name":"cli-mnq-vibrant-gates", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:59:22.353551Z", "updated_at":"2024-02-19T13:59:22.353551Z", + "id":"AAMRPEMQWUCBKJ2HTGAESWJ7ITP4QFNSBYFVE5JPBLETC4TQAO3GOLKD", "name":"cli-mnq-keen-meninsky", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts?order_by=created_at_asc + method: GET + response: + body: '{"total_count":4, "nats_accounts":[{"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:48:46.687350Z", "updated_at":"2024-02-19T09:48:46.687350Z", + "id":"ABURI34PBZXAB7VDGHGK7LJX4SFBDA6PHUDR3Y2XU42QIOGHD3GKN6RS", "name":"cli-mnq-competent-moser", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T09:49:15.694622Z", "updated_at":"2024-02-19T09:49:15.694622Z", + "id":"ACQBLIGB4MNGFZ3RQJCI223YMJ6G3BLZ4TD32A6E56KKZT75XWEVJZKJ", "name":"cli-mnq-zealous-curie", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:24:39.062406Z", "updated_at":"2024-02-19T13:24:39.062406Z", + "id":"AAULS6BP6AZ3YFJOXBWYTCEMS35NTJ4K5GUMVKM5M4N764IJDP3SMKSS", "name":"cli-mnq-vibrant-gates", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}, {"project_id":"46fd79d8-1a35-4548-bfb8-03df51a0ebae", + "region":"fr-par", "created_at":"2024-02-19T13:59:22.353551Z", "updated_at":"2024-02-19T13:59:22.353551Z", + "id":"AAMRPEMQWUCBKJ2HTGAESWJ7ITP4QFNSBYFVE5JPBLETC4TQAO3GOLKD", "name":"cli-mnq-keen-meninsky", + "endpoint":"nats://nats.mnq.fr-par.scaleway.com:4222"}]}' + headers: + Content-Length: + - "1293" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - dfdaeee9-0098-451d-a44f-f07f5d65456e + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.golden new file mode 100644 index 0000000000..dc8545a5b7 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-no-account-with-no-nats-account.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to list nats account: failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to list nats account: failed to create NATS context: Multiple NATS accounts found. Please provide an account ID explicitly as the command is not running in interactive mode" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.cassette.yaml new file mode 100644 index 0000000000..8342d1a972 --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.cassette.yaml @@ -0,0 +1,37 @@ +--- +version: 1 +interactions: +- request: + body: '{"details":[{"argument_name":"nats_account_id","help_message":"value length + must be 56 runes","reason":"constraint"}],"message":"invalid argument(s)","type":"invalid_arguments"}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/Wrong-id + method: GET + response: + body: '{"details":[{"argument_name":"nats_account_id","help_message":"value length + must be 56 runes","reason":"constraint"}],"message":"invalid argument(s)","type":"invalid_arguments"}' + headers: + Content-Length: + - "177" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 10:44:07 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 5073ccf9-bb40-4a8e-9094-50fcb493144f + status: 400 Bad Request + code: 400 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.golden new file mode 100644 index 0000000000..abee95815f --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrond-id-simple.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to get nats account: scaleway-sdk-go: invalid argument(s): nats_account_id does not respect constraint, value length must be 56 runes +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to get nats account: scaleway-sdk-go: invalid argument(s): nats_account_id does not respect constraint, value length must be 56 runes" +} diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.cassette.yaml b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.cassette.yaml new file mode 100644 index 0000000000..e98d195abc --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.cassette.yaml @@ -0,0 +1,37 @@ +--- +version: 1 +interactions: +- request: + body: '{"details":[{"argument_name":"nats_account_id","help_message":"value length + must be 56 runes","reason":"constraint"}],"message":"invalid argument(s)","type":"invalid_arguments"}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/Wrong-id + method: GET + response: + body: '{"details":[{"argument_name":"nats_account_id","help_message":"value length + must be 56 runes","reason":"constraint"}],"message":"invalid argument(s)","type":"invalid_arguments"}' + headers: + Content-Length: + - "177" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 19 Feb 2024 15:12:39 GMT + Server: + - Scaleway API Gateway (fr-par-2;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 7b4bd821-0e52-4e51-99ff-3cef37828c02 + status: 400 Bad Request + code: 400 + duration: "" diff --git a/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.golden b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.golden new file mode 100644 index 0000000000..abee95815f --- /dev/null +++ b/internal/namespaces/mnq/v1beta1/testdata/test-create-context-with-wrong-id-wrong-account-id.golden @@ -0,0 +1,7 @@ +🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Failed to get nats account: scaleway-sdk-go: invalid argument(s): nats_account_id does not respect constraint, value length must be 56 runes +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{ + "error": "failed to get nats account: scaleway-sdk-go: invalid argument(s): nats_account_id does not respect constraint, value length must be 56 runes" +}