Skip to content

Commit

Permalink
Move commands out from "enclave" sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Sep 14, 2020
1 parent 151da6d commit c629d2c
Show file tree
Hide file tree
Showing 19 changed files with 1,427 additions and 865 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
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: "List Enclave 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", "", "enclave project (e.g. backend)")

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

configsCreateCmd.Flags().StringP("project", "p", "", "enclave 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", "", "enclave project (e.g. backend)")
configsUpdateCmd.Flags().StringP("config", "c", "", "enclave 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", "", "enclave project (e.g. backend)")
configsDeleteCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
configsDeleteCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsDeleteCmd)

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

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

rootCmd.AddCommand(configsCmd)
}
Loading

0 comments on commit c629d2c

Please sign in to comment.