Skip to content

Commit c6a776a

Browse files
authored
hide password in JSON output by default (#287)
1 parent 0b621e4 commit c6a776a

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

internal/cmd/logme/credentials/create/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client"
1515
logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/logme"
@@ -124,6 +125,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl
124125
func outputResult(p *print.Printer, model *inputModel, instanceLabel string, resp *logme.CredentialsResponse) error {
125126
switch model.OutputFormat {
126127
case print.JSONOutputFormat:
128+
if !model.ShowPassword {
129+
resp.Raw.Credentials.Password = utils.Ptr("hidden")
130+
}
127131
details, err := json.MarshalIndent(resp, "", " ")
128132
if err != nil {
129133
return fmt.Errorf("marshal LogMe credentials: %w", err)

internal/cmd/mariadb/credentials/create/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client"
1515
mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/mariadb"
@@ -124,6 +125,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API
124125
func outputResult(p *print.Printer, model *inputModel, instanceLabel string, resp *mariadb.CredentialsResponse) error {
125126
switch model.OutputFormat {
126127
case print.JSONOutputFormat:
128+
if !model.ShowPassword {
129+
resp.Raw.Credentials.Password = utils.Ptr("hidden")
130+
}
127131
details, err := json.MarshalIndent(resp, "", " ")
128132
if err != nil {
129133
return fmt.Errorf("marshal MariaDB credentials: %w", err)

internal/cmd/opensearch/credentials/create/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client"
1515
opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
@@ -124,6 +125,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch.
124125
func outputResult(p *print.Printer, model *inputModel, instanceLabel string, resp *opensearch.CredentialsResponse) error {
125126
switch model.OutputFormat {
126127
case print.JSONOutputFormat:
128+
if !model.ShowPassword {
129+
resp.Raw.Credentials.Password = utils.Ptr("hidden")
130+
}
127131
details, err := json.MarshalIndent(resp, "", " ")
128132
if err != nil {
129133
return fmt.Errorf("marshal OpenSearch credentials: %w", err)

internal/cmd/rabbitmq/credentials/create/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client"
1515
rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/rabbitmq"
@@ -124,6 +125,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP
124125
func outputResult(p *print.Printer, model *inputModel, instanceLabel string, resp *rabbitmq.CredentialsResponse) error {
125126
switch model.OutputFormat {
126127
case print.JSONOutputFormat:
128+
if !model.ShowPassword {
129+
resp.Raw.Credentials.Password = utils.Ptr("hidden")
130+
}
127131
details, err := json.MarshalIndent(resp, "", " ")
128132
if err != nil {
129133
return fmt.Errorf("marshal RabbitMQ credentials: %w", err)

internal/cmd/redis/credentials/create/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client"
1515
redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/redis"
@@ -124,6 +125,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl
124125
func outputResult(p *print.Printer, model *inputModel, instanceLabel string, resp *redis.CredentialsResponse) error {
125126
switch model.OutputFormat {
126127
case print.JSONOutputFormat:
128+
if !model.ShowPassword {
129+
resp.Raw.Credentials.Password = utils.Ptr("hidden")
130+
}
127131
details, err := json.MarshalIndent(resp, "", " ")
128132
if err != nil {
129133
return fmt.Errorf("marshal Redis credentials: %w", err)

0 commit comments

Comments
 (0)