From 17e72c8e0de30ce61e92dd6ba59959e73d2fca15 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 3 Jan 2023 16:00:52 -0500 Subject: [PATCH] use strings.Cut --- command/agent/csi_endpoint.go | 5 ++--- command/volume_delete.go | 5 ++--- command/volume_snapshot_create.go | 10 ++++------ command/volume_snapshot_delete.go | 5 ++--- command/volume_snapshot_list.go | 5 ++--- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/command/agent/csi_endpoint.go b/command/agent/csi_endpoint.go index 22184478d60..fb71bfd9576 100644 --- a/command/agent/csi_endpoint.go +++ b/command/agent/csi_endpoint.go @@ -409,9 +409,8 @@ func parseCSISecrets(req *http.Request) structs.CSISecrets { secrets := map[string]string{} secretkvs := strings.Split(secretsHeader, ",") for _, secretkv := range secretkvs { - kv := strings.SplitN(secretkv, "=", 2) - if len(kv) == 2 { - secrets[kv[0]] = kv[1] + if key, value, found := strings.Cut(secretkv, "="); found { + secrets[key] = value } } if len(secrets) == 0 { diff --git a/command/volume_delete.go b/command/volume_delete.go index c48e974cc80..12e8c832a0b 100644 --- a/command/volume_delete.go +++ b/command/volume_delete.go @@ -104,9 +104,8 @@ func (c *VolumeDeleteCommand) Run(args []string) int { secrets := api.CSISecrets{} for _, kv := range secretsArgs { - s := strings.SplitN(kv, "=", 2) - if len(s) == 2 { - secrets[s[0]] = s[1] + if key, value, found := strings.Cut(kv, "="); found { + secrets[key] = value } else { c.Ui.Error("Secret must be in the format: -secret key=value") return 1 diff --git a/command/volume_snapshot_create.go b/command/volume_snapshot_create.go index 9ec8210c6e5..c145bb85b9a 100644 --- a/command/volume_snapshot_create.go +++ b/command/volume_snapshot_create.go @@ -117,9 +117,8 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int { secrets := api.CSISecrets{} for _, kv := range secretsArgs { - s := strings.SplitN(kv, "=", 2) - if len(s) == 2 { - secrets[s[0]] = s[1] + if key, value, found := strings.Cut(kv, "="); found { + secrets[key] = value } else { c.Ui.Error("Secret must be in the format: -secret key=value") return 1 @@ -128,9 +127,8 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int { params := map[string]string{} for _, kv := range parametersArgs { - p := strings.SplitN(kv, "=", 2) - if len(p) == 2 { - params[p[0]] = p[1] + if key, value, found := strings.Cut(kv, "="); found { + params[key] = value } } diff --git a/command/volume_snapshot_delete.go b/command/volume_snapshot_delete.go index 18af79ad234..63cad502f36 100644 --- a/command/volume_snapshot_delete.go +++ b/command/volume_snapshot_delete.go @@ -94,9 +94,8 @@ func (c *VolumeSnapshotDeleteCommand) Run(args []string) int { secrets := api.CSISecrets{} for _, kv := range secretsArgs { - s := strings.SplitN(kv, "=", 2) - if len(s) == 2 { - secrets[s[0]] = s[1] + if key, value, found := strings.Cut(kv, "="); found { + secrets[key] = value } else { c.Ui.Error("Secret must be in the format: -secret key=value") return 1 diff --git a/command/volume_snapshot_list.go b/command/volume_snapshot_list.go index c95c07720ee..bef018b1dae 100644 --- a/command/volume_snapshot_list.go +++ b/command/volume_snapshot_list.go @@ -140,9 +140,8 @@ func (c *VolumeSnapshotListCommand) Run(args []string) int { secrets := api.CSISecrets{} for _, kv := range secretsArgs { - s := strings.SplitN(kv, "=", 2) - if len(s) == 2 { - secrets[s[0]] = s[1] + if key, value, found := strings.Cut(kv, "="); found { + secrets[key] = value } else { c.Ui.Error("Secret must be in the format: -secret key=value") return 1