Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25.4-alpine AS build
FROM golang:1.25.5-alpine AS build

WORKDIR /go/src/github.com/segmentio/chamber
COPY . .
Expand Down
6 changes: 3 additions & 3 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
func delete(cmd *cobra.Command, args []string) error {
service := utils.NormalizeService(args[0])
if err := validateService(service); err != nil {
return fmt.Errorf("Failed to validate service: %w", err)
return fmt.Errorf("Failed to validate service: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

key := args[1]
Expand All @@ -36,7 +36,7 @@ func delete(cmd *cobra.Command, args []string) error {
}

if err := validateKey(key); err != nil {
return fmt.Errorf("Failed to validate key: %w", err)
return fmt.Errorf("Failed to validate key: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if analyticsEnabled && analyticsClient != nil {
Expand All @@ -53,7 +53,7 @@ func delete(cmd *cobra.Command, args []string) error {
}
secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
secretId := store.SecretId{
Service: service,
Expand Down
10 changes: 5 additions & 5 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"strings"

"github.com/alessio/shellescape"
"al.essio.dev/pkg/shellescape"
analytics "github.com/segmentio/analytics-go/v3"
"github.com/segmentio/chamber/v3/utils"

Expand Down Expand Up @@ -62,17 +62,17 @@ func env(cmd *cobra.Command, args []string) error {
func exportEnv(cmd *cobra.Command, args []string) ([]string, error) {
service := utils.NormalizeService(args[0])
if err := validateService(service); err != nil {
return nil, fmt.Errorf("Failed to validate service: %w", err)
return nil, fmt.Errorf("Failed to validate service: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return nil, fmt.Errorf("Failed to get secret store: %w", err)
return nil, fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

rawSecrets, err := secretStore.ListRaw(cmd.Context(), service)
if err != nil {
return nil, fmt.Errorf("Failed to list store contents: %w", err)
return nil, fmt.Errorf("Failed to list store contents: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if analyticsEnabled && analyticsClient != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func doubleQuoteEscape(line string) string {
if c == '\r' {
toReplace = `\r`
}
line = strings.Replace(line, string(c), toReplace, -1)
line = strings.Replace(line, string(c), toReplace, -1) //nolint:staticcheck // QF1004 pre-existing
}
return line
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ func execRun(cmd *cobra.Command, args []string) error {

for _, service := range services {
if err := validateServiceWithLabel(service); err != nil {
return fmt.Errorf("Failed to validate service: %w", err)
return fmt.Errorf("Failed to validate service: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
}

secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if pristine {
Expand All @@ -120,7 +120,7 @@ func execRun(cmd *cobra.Command, args []string) error {
// TODO: these interfaces should look the same as Strict*, so move pristine in there
err := env.Load(cmd.Context(), secretStore, service, &collisions)
if err != nil {
return fmt.Errorf("Failed to list store contents: %w", err)
return fmt.Errorf("Failed to list store contents: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

for _, c := range collisions {
Expand Down
24 changes: 12 additions & 12 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func runExport(cmd *cobra.Command, args []string) error {
for _, service := range args {
service = utils.NormalizeService(service)
if err := validateService(service); err != nil {
return fmt.Errorf("Failed to validate service %s: %w", service, err)
return fmt.Errorf("Failed to validate service %s: %w", service, err) //nolint:staticcheck // ST1005 pre-existing
}

rawSecrets, err := secretStore.ListRaw(cmd.Context(), service)
if err != nil {
return fmt.Errorf("Failed to list store contents for service %s: %w", service, err)
return fmt.Errorf("Failed to list store contents for service %s: %w", service, err) //nolint:staticcheck // ST1005 pre-existing
}
for _, rawSecret := range rawSecrets {
k := key(rawSecret.Key)
Expand All @@ -79,14 +79,14 @@ func runExport(cmd *cobra.Command, args []string) error {
file := os.Stdout
if exportOutput != "" {
if file, err = os.OpenFile(exportOutput, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
return fmt.Errorf("Failed to open output file for writing: %w", err)
return fmt.Errorf("Failed to open output file for writing: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
// TODO: check for errors flushing, syncing, or closing
defer file.Close()
defer file.Sync()
defer file.Close() //nolint:errcheck // pre-existing
defer file.Sync() //nolint:errcheck // pre-existing
}
w := bufio.NewWriter(file)
defer w.Flush()
defer w.Flush() //nolint:errcheck // pre-existing

switch strings.ToLower(exportFormat) {
case "json":
Expand All @@ -104,11 +104,11 @@ func runExport(cmd *cobra.Command, args []string) error {
case "tfvars":
err = exportAsTFvars(params, w)
default:
err = fmt.Errorf("Unsupported export format: %s", exportFormat)
err = fmt.Errorf("Unsupported export format: %s", exportFormat) //nolint:staticcheck // ST1005 pre-existing
}

if err != nil {
return fmt.Errorf("Unable to export parameters: %w", err)
return fmt.Errorf("Unable to export parameters: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

return nil
Expand All @@ -130,7 +130,7 @@ func exportAsEnvFile(params map[string]string, w io.Writer) error {
}

for i := range out {
_, err := w.Write([]byte(fmt.Sprintln(out[i])))
_, err := w.Write([]byte(fmt.Sprintln(out[i]))) //nolint:staticcheck // QF1012 pre-existing
if err != nil {
return err
}
Expand All @@ -144,7 +144,7 @@ func exportAsTFvars(params map[string]string, w io.Writer) error {
for _, k := range sortedKeys(params) {
key := sanitizeKey(strings.TrimPrefix(k, "tf_var_"))

_, err := w.Write([]byte(fmt.Sprintf(`%s = "%s"`+"\n", key, doubleQuoteEscape(params[k]))))
_, err := w.Write([]byte(fmt.Sprintf(`%s = "%s"`+"\n", key, doubleQuoteEscape(params[k])))) //nolint:staticcheck // QF1012 pre-existing
if err != nil {
return fmt.Errorf("failed to write variable with key %s: %v", k, err)
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func exportAsCsv(params map[string]string, w io.Writer) error {
defer csvWriter.Flush()
for _, k := range sortedKeys(params) {
if err := csvWriter.Write([]string{k, params[k]}); err != nil {
return fmt.Errorf("Failed to write param %q to CSV file: %w", k, err)
return fmt.Errorf("Failed to write param %q to CSV file: %w", k, err) //nolint:staticcheck // ST1005 pre-existing
}
}
return nil
Expand All @@ -205,7 +205,7 @@ func exportAsTsv(params map[string]string, w io.Writer) error {
defer tsvWriter.Flush()
for _, k := range sortedKeys(params) {
if err := tsvWriter.Write([]string{k, params[k]}); err != nil {
return fmt.Errorf("Failed to write param %q to TSV file: %w", k, err)
return fmt.Errorf("Failed to write param %q to TSV file: %w", k, err) //nolint:staticcheck // ST1005 pre-existing
}
}
return nil
Expand Down
18 changes: 9 additions & 9 deletions cmd/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func find(cmd *cobra.Command, args []string) error {

secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
services, err := secretStore.ListServices(cmd.Context(), blankService, includeSecrets)
if err != nil {
return fmt.Errorf("Failed to list store contents: %w", err)
return fmt.Errorf("Failed to list store contents: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if byValue {
Expand All @@ -60,20 +60,20 @@ func find(cmd *cobra.Command, args []string) error {
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprint(w, "Service")
fmt.Fprint(w, "Service") //nolint:errcheck // pre-existing
if byValue {
fmt.Fprint(w, "\tKey")
fmt.Fprint(w, "\tKey") //nolint:errcheck // pre-existing
}
fmt.Fprintln(w, "")
fmt.Fprintln(w, "") //nolint:errcheck // pre-existing

for _, match := range matches {
fmt.Fprintf(w, "%s", match.Service)
fmt.Fprintf(w, "%s", match.Service) //nolint:errcheck // pre-existing
if byValue {
fmt.Fprintf(w, "\t%s", match.Key)
fmt.Fprintf(w, "\t%s", match.Key) //nolint:errcheck // pre-existing
}
fmt.Fprintln(w, "")
fmt.Fprintln(w, "") //nolint:errcheck // pre-existing
}
w.Flush()
w.Flush() //nolint:errcheck // pre-existing

return nil
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func init() {
func history(cmd *cobra.Command, args []string) error {
service := utils.NormalizeService(args[0])
if err := validateService(service); err != nil {
return fmt.Errorf("Failed to validate service: %w", err)
return fmt.Errorf("Failed to validate service: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

key := utils.NormalizeKey(args[1])
if err := validateKey(key); err != nil {
return fmt.Errorf("Failed to validate key: %w", err)
return fmt.Errorf("Failed to validate key: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if analyticsEnabled && analyticsClient != nil {
Expand All @@ -49,7 +49,7 @@ func history(cmd *cobra.Command, args []string) error {

secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
secretId := store.SecretId{
Service: service,
Expand All @@ -58,19 +58,19 @@ func history(cmd *cobra.Command, args []string) error {

events, err := secretStore.History(cmd.Context(), secretId)
if err != nil {
return fmt.Errorf("Failed to get history: %w", err)
return fmt.Errorf("Failed to get history: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprintln(w, "Event\tVersion\tDate\tUser")
fmt.Fprintln(w, "Event\tVersion\tDate\tUser") //nolint:errcheck // pre-existing
for _, event := range events {
fmt.Fprintf(w, "%s\t%d\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%d\t%s\t%s\n", //nolint:errcheck // pre-existing
event.Type,
event.Version,
event.Time.Local().Format(ShortTimeFormat),
event.User,
)
}
w.Flush()
w.Flush() //nolint:errcheck // pre-existing
return nil
}
12 changes: 6 additions & 6 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
func importRun(cmd *cobra.Command, args []string) error {
service := utils.NormalizeService(args[0])
if err := validateService(service); err != nil {
return fmt.Errorf("Failed to validate service: %w", err)
return fmt.Errorf("Failed to validate service: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

var in io.Reader
Expand All @@ -42,15 +42,15 @@ func importRun(cmd *cobra.Command, args []string) error {
} else {
in, err = os.Open(file)
if err != nil {
return fmt.Errorf("Failed to open file: %w", err)
return fmt.Errorf("Failed to open file: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
}

var toBeImported map[string]string

decoder := yaml.NewDecoder(in)
if err := decoder.Decode(&toBeImported); err != nil {
return fmt.Errorf("Failed to decode input as json: %w", err)
return fmt.Errorf("Failed to decode input as json: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

if analyticsEnabled && analyticsClient != nil {
Expand All @@ -67,7 +67,7 @@ func importRun(cmd *cobra.Command, args []string) error {

secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

for key, value := range toBeImported {
Expand All @@ -79,10 +79,10 @@ func importRun(cmd *cobra.Command, args []string) error {
Key: key,
}
if err := secretStore.Write(cmd.Context(), secretId, value); err != nil {
return fmt.Errorf("Failed to write secret: %w", err)
return fmt.Errorf("Failed to write secret: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
}

fmt.Fprintf(os.Stdout, "Successfully imported %d secrets\n", len(toBeImported))
fmt.Fprintf(os.Stdout, "Successfully imported %d secrets\n", len(toBeImported)) //nolint:errcheck // pre-existing
return nil
}
14 changes: 7 additions & 7 deletions cmd/list-services.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ func listServices(cmd *cobra.Command, args []string) error {
}
secretStore, err := getSecretStore(cmd.Context())
if err != nil {
return fmt.Errorf("Failed to get secret store: %w", err)
return fmt.Errorf("Failed to get secret store: %w", err) //nolint:staticcheck // ST1005 pre-existing
}
secrets, err := secretStore.ListServices(cmd.Context(), service, includeSecretName)
if err != nil {
return fmt.Errorf("Failed to list store contents: %w", err)
return fmt.Errorf("Failed to list store contents: %w", err) //nolint:staticcheck // ST1005 pre-existing
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprint(w, "Service")
fmt.Fprintln(w, "")
fmt.Fprint(w, "Service") //nolint:errcheck // pre-existing
fmt.Fprintln(w, "") //nolint:errcheck // pre-existing

sort.Strings(secrets)

for _, secret := range secrets {
fmt.Fprintf(w, "%s",
fmt.Fprintf(w, "%s", //nolint:errcheck // pre-existing
secret)
fmt.Fprintln(w, "")
fmt.Fprintln(w, "") //nolint:errcheck // pre-existing
}
w.Flush()
w.Flush() //nolint:errcheck // pre-existing
return nil
}
Loading