Skip to content

Commit

Permalink
Merge pull request #239 from DopplerHQ/clone-config
Browse files Browse the repository at this point in the history
Support specifying new config name when cloning config
  • Loading branch information
Piccirello authored Jul 9, 2021
2 parents 7b1d305 + 7f66782 commit ab52196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/cmd/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func unlockConfigs(cmd *cobra.Command, args []string) {
func cloneConfigs(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON
localConfig := configuration.LocalConfig(cmd)
name := cmd.Flag("name").Value.String()

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

Expand All @@ -292,7 +293,7 @@ func cloneConfigs(cmd *cobra.Command, args []string) {
config = args[0]
}

configInfo, err := http.CloneConfig(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, config)
configInfo, err := http.CloneConfig(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)
}
Expand Down Expand Up @@ -387,6 +388,7 @@ func init() {

configsCloneCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsCloneCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsCloneCmd.Flags().String("name", "", "new config name")
configsCmd.AddCommand(configsCloneCmd)

rootCmd.AddCommand(configsCmd)
Expand Down
10 changes: 8 additions & 2 deletions pkg/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,18 @@ func UnlockConfig(host string, verifyTLS bool, apiKey string, project string, co
}

// CloneConfig clone a config
func CloneConfig(host string, verifyTLS bool, apiKey string, project string, config string) (models.ConfigInfo, Error) {
func CloneConfig(host string, verifyTLS bool, apiKey string, project string, config string, name string) (models.ConfigInfo, Error) {
postBody := map[string]interface{}{"name": name}
body, err := json.Marshal(postBody)
if err != nil {
return models.ConfigInfo{}, Error{Err: err, Message: "Invalid config info"}
}

var params []queryParam
params = append(params, queryParam{Key: "project", Value: project})
params = append(params, queryParam{Key: "config", Value: config})

statusCode, _, response, err := PostRequest(host, verifyTLS, apiKeyHeader(apiKey), "/v3/configs/config/clone", params, nil)
statusCode, _, response, err := PostRequest(host, verifyTLS, apiKeyHeader(apiKey), "/v3/configs/config/clone", params, body)
if err != nil {
return models.ConfigInfo{}, Error{Err: err, Message: "Unable to clone config", Code: statusCode}
}
Expand Down

0 comments on commit ab52196

Please sign in to comment.