diff --git a/go.mod b/go.mod index 44c92913e..c3dd7c13c 100644 --- a/go.mod +++ b/go.mod @@ -26,4 +26,4 @@ require ( // replace gopkg.in/auth0.v5 => ../auth0 -replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a +replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127040011-acb7c665d062 diff --git a/go.sum b/go.sum index 4c9f4bf0a..3b3a7ff89 100644 --- a/go.sum +++ b/go.sum @@ -88,6 +88,8 @@ github.com/go-auth0/auth0 v1.3.1-0.20210126214458-2807092480f8 h1:x5rbuD/ay7ieXn github.com/go-auth0/auth0 v1.3.1-0.20210126214458-2807092480f8/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk= github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a h1:TAnbIrM2gdxfqT4pdPso61aO74mS+mNuIbRDYhfSNKI= github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk= +github.com/go-auth0/auth0 v1.3.1-0.20210127040011-acb7c665d062 h1:WOCTdmjxtCBWcSL34/v0lzvyqGvlPlH76ns86EUuF98= +github.com/go-auth0/auth0 v1.3.1-0.20210127040011-acb7c665d062/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= diff --git a/internal/cli/actions.go b/internal/cli/actions.go index 86570915f..f87b33e97 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -8,6 +8,7 @@ import ( "github.com/auth0/auth0-cli/internal/ansi" "github.com/auth0/auth0-cli/internal/auth0" + "github.com/auth0/auth0-cli/internal/prompt" "github.com/auth0/auth0-cli/internal/validators" "github.com/spf13/cobra" "gopkg.in/auth0.v5/management" @@ -24,6 +25,7 @@ func actionsCmd(cli *cli) *cobra.Command { cmd.AddCommand(testActionCmd(cli)) cmd.AddCommand(createActionCmd(cli)) cmd.AddCommand(deployActionCmd(cli)) + cmd.AddCommand(downloadActionCmd(cli)) cmd.AddCommand(listActionVersionsCmd(cli)) cmd.AddCommand(triggersCmd(cli)) @@ -162,6 +164,66 @@ func deployActionCmd(cli *cli) *cobra.Command { return cmd } +func downloadActionCmd(cli *cli) *cobra.Command { + var actionId string + var versionId string + var path string + + cmd := &cobra.Command{ + Use: "download", + Short: "Download the action version", + Long: `$ auth0 actions download --name --version `, + RunE: func(cmd *cobra.Command, args []string) error { + cli.renderer.Infof("It will overwrite files in %s", path) + if confirmed := prompt.Confirm("Do you wish to proceed?"); !confirmed { + return nil + } + + var version *management.ActionVersion + err := ansi.Spinner(fmt.Sprintf("Downloading action: %s, version: %s", actionId, versionId), func() (err error) { + if version, err = cli.api.ActionVersion.Read(actionId, versionId); err != nil { + return err + } + + if version.ID == "" { + version.ID = "draft" + } + return nil + }) + + if err != nil { + return err + } + + cli.renderer.Infof("Code downloaded to %s/code.js", path) + + if err := ioutil.WriteFile(path+"/code.js", []byte(version.Code), 0644); err != nil { + return err + } + + version.Code = "" + metadata, err := json.MarshalIndent(version, "", " ") + if err != nil { + return err + } + + if err := ioutil.WriteFile(path+"/metadata.json", metadata, 0644); err != nil { + return err + } + + return nil + }, + } + + cmd.Flags().StringVar(&actionId, "name", "", "Action ID to deploy") + cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to deploy or draft, default: draft") + cmd.Flags().StringVarP(&path, "path", "p", "./", "Path to save the action content") + + mustRequireFlags(cmd, "name") + + return cmd +} + func listActionVersionsCmd(cli *cli) *cobra.Command { var actionId string diff --git a/vendor/gopkg.in/auth0.v5/management/actions.go b/vendor/gopkg.in/auth0.v5/management/actions.go index 20daa8d33..f65d537fe 100644 --- a/vendor/gopkg.in/auth0.v5/management/actions.go +++ b/vendor/gopkg.in/auth0.v5/management/actions.go @@ -40,7 +40,7 @@ const ( type ActionVersion struct { ID string `json:"id,omitempty"` Action *Action `json:"action,omitempty"` - Code string `json:"code"` + Code string `json:"code,omitempty"` Dependencies []Dependency `json:"dependencies,omitempty"` Runtime string `json:"runtime,omitempty"` Status VersionStatus `json:"status,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index ce40a8c49..5589291a0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -138,7 +138,7 @@ google.golang.org/protobuf/reflect/protoreflect google.golang.org/protobuf/reflect/protoregistry google.golang.org/protobuf/runtime/protoiface google.golang.org/protobuf/runtime/protoimpl -# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a +# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210127040011-acb7c665d062 ## explicit gopkg.in/auth0.v5 gopkg.in/auth0.v5/internal/client @@ -149,4 +149,4 @@ gopkg.in/auth0.v5/management # gopkg.in/yaml.v2 v2.2.8 ## explicit gopkg.in/yaml.v2 -# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a +# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127040011-acb7c665d062