DopplerHQ / cli

The official CLI for interacting with your Doppler secrets and configuration.
https://docs.doppler.com
Apache License 2.0
218 stars 44 forks source link

Support setting secrets via stdin #262

Closed Piccirello closed 2 years ago

Piccirello commented 2 years ago

This PR adds support for setting secrets via stdin. It has two different modes:

Piping in data

$ echo -e 'my\nsecret\nvalue' | doppler secrets set A
┌──────┬────────┐
│ NAME │ VALUE  │
├──────┼────────┤
│ A    │ my     │
│      │ secret │
│      │ value  │
└──────┴────────┘

Interactive mode

$ doppler secrets set A
Enter your secret value
When finished, type a newline followed by a period
Run 'doppler secrets set --help' for more information
———————————————————— START INPUT ————————————————————
my
secret
value

.
————————————————————— END INPUT —————————————————————
┌──────┬────────┐
│ NAME │ VALUE  │
├──────┼────────┤
│ A    │ my     │
│      │ secret │
│      │ value  │
└──────┴────────┘

Updated help text

$ doppler secrets set --help
Set the value of one or more secrets.

There are several methods for setting secrets:

1) stdin (recommended)
$ echo -e 'multiline\nvalue' | doppler secrets set CERT

2) interactive stdin (recommended)
$ doppler secrets set CERT
multiline
value

.

3) one secret
$ doppler secrets set API_KEY '123'

4) multiple secrets
$ doppler secrets set API_KEY='123' DATABASE_URL='postgres:random@127.0.0.1:5432'

Usage:
  doppler secrets set [secrets] [flags]

Flags:
  -c, --config string    config (e.g. dev)
  -h, --help             help for set
      --no-prompt        do not allow entering secret value via interactive mode
  -p, --project string   project (e.g. backend)
      --raw              print the raw secret value without processing variables

Global Flags:
      --api-host string                 The host address for the Doppler API (default "https://api.doppler.com")
      --configuration string            config file (default "/Users/doppler/.doppler/.doppler.yaml")
      --dashboard-host string           The host address for the Doppler Dashboard (default "https://dashboard.doppler.com")
      --debug                           output additional information
      --dns-resolver-address string     address to use for DNS resolution (default "1.1.1.1:53")
      --dns-resolver-proto string       protocol to use for DNS resolution (default "udp")
      --dns-resolver-timeout duration   max dns lookup duration (default 5s)
      --enable-dns-resolver             bypass the OS's default DNS resolver
      --json                            output json
      --no-check-version                disable checking for Doppler CLI updates
      --no-read-env                     do not read config from the environment
      --no-timeout                      disable http timeout
      --no-verify-tls                   do not verify the validity of TLS certificates on HTTP requests (not recommended)
      --print-config                    output active configuration
      --scope string                    the directory to scope your config to (default ".")
      --silent                          disable output of info messages
      --timeout duration                max http request duration (default 10s)
  -t, --token string                    doppler token

Closes ENG-2351.

rgmvisser commented 2 years ago

@Piccirello can we remove the dismiss stale review for this repo? I feel like I have approved this 3 times now :P

Piccirello commented 2 years ago

This repo accepts PRs from the public, so the dismissal helps us ensure that a PR isn't maliciously modified after it's approved. In this case, the third approval shouldn't have been needed, but I didn't properly test my change 😬