Skip to content

Commit

Permalink
Merge pull request #125 from DopplerHQ/tom_flatten_enclave
Browse files Browse the repository at this point in the history
Deprecate Enclave from the CLI
  • Loading branch information
Piccirello authored Sep 15, 2020
2 parents ac0c4e5 + 8a9c425 commit e8324bb
Show file tree
Hide file tree
Showing 28 changed files with 1,883 additions and 1,125 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ brews:
email: [email protected]
folder: Formula
homepage: "https://doppler.com"
description: "The official Doppler CLI for managing your Enclave secrets"
description: "The official Doppler CLI for managing your secrets"
test: |
system "#{bin}/doppler --version"
Expand All @@ -180,7 +180,7 @@ scoop:
name: "Doppler Bot"
email: [email protected]
homepage: "https://doppler.com"
description: "The official Doppler CLI for managing your Enclave secrets"
description: "The official Doppler CLI for managing your secrets"
license: Apache-2.0

nfpms:
Expand All @@ -189,7 +189,7 @@ nfpms:
386: i386
homepage: "https://doppler.com"
maintainer: Doppler Bot <[email protected]>
description: "The official Doppler CLI for managing your Enclave secrets"
description: "The official Doppler CLI for managing your secrets"
license: Apache-2.0
bindir: /usr/bin
formats:
Expand Down
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Note: In the goreleaser output, it will state that artifact signing is disabled.

#### Generate a GPG key

Store the keys and passphrase in your enclave config
Store the keys and passphrase in your Doppler config

```
$ gpg --full-generate-key
Expand Down
10 changes: 5 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Here's an example Dockerfile for a Node app:
FROM dopplerhq/cli:3-node

# doppler args must be passed at runtime
ENV DOPPLER_TOKEN="" ENCLAVE_PROJECT="" ENCLAVE_CONFIG=""
ENV DOPPLER_TOKEN="" DOPPLER_PROJECT="" DOPPLER_CONFIG=""

COPY . .

Expand All @@ -126,13 +126,13 @@ docker build -t mytestapp .

Then run the container:
```sh
docker run --rm -it -p 3000:3000 -e DOPPLER_TOKEN="" -e ENCLAVE_PROJECT="" -e ENCLAVE_CONFIG="" mytestapp
docker run --rm -it -p 3000:3000 -e DOPPLER_TOKEN="" -e DOPPLER_PROJECT="" -e DOPPLER_CONFIG="" mytestapp
```

To avoid hard-coding the values, you can use the cli's `configure` command:

```sh
docker run --rm -it -p 3000:3000 -e DOPPLER_TOKEN="$(doppler configure get token --plain)" -e ENCLAVE_PROJECT="$(doppler configure get enclave.project --plain)" -e ENCLAVE_CONFIG="$(doppler configure get enclave.config --plain)" mytestapp
docker run --rm -it -p 3000:3000 -e DOPPLER_TOKEN="$(doppler configure get token --plain)" -e DOPPLER_PROJECT="$(doppler configure get project --plain)" -e DOPPLER_CONFIG="$(doppler configure get config --plain)" mytestapp
```

Flags:
Expand All @@ -141,8 +141,8 @@ Flags:
- `-t` print output to this terminal
- `-p 3000:3000` the port your app uses to service requests, if any
- `-e DOPPLER_TOKEN=""` pass a token into the environment
- `-e ENCLAVE_PROJECT=""` pass an enclave project into the environment
- `-e ENCLAVE_CONFIG=""` pass an enclave config into the environment
- `-e DOPPLER_PROJECT=""` pass an project into the environment
- `-e DOPPLER_CONFIG=""` pass an config into the environment

## Other

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Doppler CLI

The Doppler CLI is the official tool for interacting with your Enclave secrets and configuration.
The Doppler CLI is the official tool for interacting with your Doppler secrets and configuration.

**You can:**

Expand Down Expand Up @@ -81,11 +81,11 @@ Setup should only take a minute (literally). You'll authorize the CLI to access

```sh
$ doppler login # generate auth credentials
$ doppler enclave setup # select your project and config
$ doppler setup # select your project and config
# optional
$ doppler configure --all # view local configuration
```

By default, `doppler login` scopes the auth token to the root directory (`--scope=/`). This means that the token will be accessible to projects using the Doppler CLI in any subdirectory. To limit this, specify the `scope` flag during login: `doppler login --scope=./` or `doppler login --scope ~/projects/backend`.

Enclave setup (i.e. `doppler enclave setup`) scopes the enclave project and config to the current directory (`--scope=./`). You can also modify this scope with the `scope` flag. Run `doppler help` for more information.
Setup (i.e. `doppler setup`) scopes the selected project and config to the current directory (`--scope=./`). You can also modify this scope with the `scope` flag. Run `doppler help` for more information.
293 changes: 293 additions & 0 deletions pkg/cmd/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
/*
Copyright © 2020 Doppler <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"errors"
"strings"

"github.com/DopplerHQ/cli/pkg/configuration"
"github.com/DopplerHQ/cli/pkg/http"
"github.com/DopplerHQ/cli/pkg/printer"
"github.com/DopplerHQ/cli/pkg/utils"
"github.com/spf13/cobra"
)

var configsCmd = &cobra.Command{
Use: "configs",
Short: "Manage configs",
Args: cobra.NoArgs,
Run: configs,
}

var configsGetCmd = &cobra.Command{
Use: "get [config]",
Short: "Get info for a config",
Args: cobra.MaximumNArgs(1),
Run: getConfigs,
}

var configsCreateCmd = &cobra.Command{
Use: "create [name]",
Short: "Create a config",
Args: cobra.MaximumNArgs(1),
Run: createConfigs,
}

var configsDeleteCmd = &cobra.Command{
Use: "delete [config]",
Short: "Delete a config",
Args: cobra.MaximumNArgs(1),
Run: deleteConfigs,
}

var configsUpdateCmd = &cobra.Command{
Use: "update [config]",
Short: "Update a config",
Args: cobra.MaximumNArgs(1),
Run: updateConfigs,
}

var configsLockCmd = &cobra.Command{
Use: "lock [config]",
Short: "Lock a config",
Args: cobra.MaximumNArgs(1),
Run: lockConfigs,
}

var configsUnlockCmd = &cobra.Command{
Use: "unlock [config]",
Short: "Unlock a config",
Args: cobra.MaximumNArgs(1),
Run: unlockConfigs,
}

func configs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

configs, err := http.GetConfigs(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

printer.ConfigsInfo(configs, jsonFlag)
}

func getConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

config := localConfig.EnclaveConfig.Value
if len(args) > 0 {
config = args[0]
}
utils.RequireValue("config", config)

configInfo, err := http.GetConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

printer.ConfigInfo(configInfo, jsonFlag)
}

func createConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
environment := cmd.Flag("environment").Value.String()
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

name := cmd.Flag("name").Value.String()
if len(args) > 0 {
name = args[0]
}

if name == "" {
utils.HandleError(errors.New("you must specify a name"))
}

if environment == "" && strings.Index(name, "_") != -1 {
environment = name[0:strings.Index(name, "_")]
}

if environment == "" {
utils.HandleError(errors.New("you must specify an environment"))
}

info, err := http.CreateConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, name, environment)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

if !utils.Silent {
printer.ConfigInfo(info, jsonFlag)
}
}

func deleteConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
yes := utils.GetBoolFlag(cmd, "yes")
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

config := localConfig.EnclaveConfig.Value
if len(args) > 0 {
config = args[0]
}
utils.RequireValue("config", config)

if yes || utils.ConfirmationPrompt("Delete config "+config, false) {
err := http.DeleteConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

if !utils.Silent {
configs, err := http.GetConfigs(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

printer.ConfigsInfo(configs, jsonFlag)
}
}
}

func updateConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
name := cmd.Flag("name").Value.String()
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)
utils.RequireValue("name", name)

config := localConfig.EnclaveConfig.Value
if len(args) > 0 {
config = args[0]
}
utils.RequireValue("config", config)

info, err := http.UpdateConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config, name)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

if !utils.Silent {
printer.ConfigInfo(info, jsonFlag)
}
}

func lockConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
yes := utils.GetBoolFlag(cmd, "yes")
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

config := localConfig.EnclaveConfig.Value
if len(args) > 0 {
config = args[0]
}
utils.RequireValue("config", config)

if yes || utils.ConfirmationPrompt("Lock config "+config, false) {
configInfo, err := http.LockConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

if !utils.Silent {
printer.ConfigInfo(configInfo, jsonFlag)
}
}
}

func unlockConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
yes := utils.GetBoolFlag(cmd, "yes")
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
utils.RequireValue("project", localConfig.EnclaveProject.Value)

config := localConfig.EnclaveConfig.Value
if len(args) > 0 {
config = args[0]
}
utils.RequireValue("config", config)

if yes || utils.ConfirmationPrompt("Unlock config "+config, false) {
configInfo, err := http.UnlockConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}

if !utils.Silent {
printer.ConfigInfo(configInfo, jsonFlag)
}
}
}

func init() {
configsCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")

configsGetCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsGetCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsCmd.AddCommand(configsGetCmd)

configsCreateCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsCreateCmd.Flags().String("name", "", "config name")
configsCreateCmd.Flags().StringP("environment", "e", "", "config environment")
configsCmd.AddCommand(configsCreateCmd)

configsUpdateCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsUpdateCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsUpdateCmd.Flags().String("name", "", "config name")
if err := configsUpdateCmd.MarkFlagRequired("name"); err != nil {
utils.HandleError(err)
}
configsCmd.AddCommand(configsUpdateCmd)

configsDeleteCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsDeleteCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsDeleteCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsDeleteCmd)

configsLockCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsLockCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsLockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsLockCmd)

configsUnlockCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsUnlockCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsUnlockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsUnlockCmd)

rootCmd.AddCommand(configsCmd)
}
Loading

0 comments on commit e8324bb

Please sign in to comment.