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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ linters:
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
Expand Down
16 changes: 12 additions & 4 deletions internal/namespaces/mnq/v1beta1/custom_nats_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ func FileExists(filePath string) bool {
return !os.IsNotExist(err)
}

func natsContextFrom(account *mnq.NatsAccount, credsPath string) []byte {
func natsContextFrom(account *mnq.NatsAccount, credsPath string) ([]byte, error) {
ctx := &natsContext{
Description: "Nats context created by Scaleway CLI",
URL: account.Endpoint,
CredentialsPath: credsPath,
}
b, _ := json.Marshal(ctx)
return b
b, err := json.Marshal(ctx)
if err != nil {
return nil, err
}
return b, nil
}

func writeFile(ctx context.Context, dir string, entity *NatsEntity, extension string) (string, error) {
Expand Down Expand Up @@ -97,9 +100,14 @@ func saveNATSCredentials(ctx context.Context, creds *mnq.NatsCredentials, natsAc
return "", err
}

natsContent, err := natsContextFrom(natsAccount, credsPath)
if err != nil {
return "", err
}

contextEntity := &NatsEntity{
Name: natsAccount.Name,
Content: natsContextFrom(natsAccount, credsPath),
Content: natsContent,
}

contextPath, err := writeFile(ctx, natsContextDir, contextEntity, "json")
Expand Down
Loading