Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: actions download #64

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
62 changes: 62 additions & 0 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))

Expand Down Expand Up @@ -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 <actionid> --version <versionid | draft>`,
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 {
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
2 changes: 1 addition & 1 deletion vendor/gopkg.in/auth0.v5/management/actions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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