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

Add support to set runtime for create/update actions #1131

Merged
merged 1 commit into from
Jan 28, 2025
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
5 changes: 3 additions & 2 deletions docs/auth0_actions_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ auth0 actions create [flags]
auth0 actions create
auth0 actions create --name myaction
auth0 actions create --name myaction --trigger post-login
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js) --runtime node18
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value"
auth0 actions create -n myaction -t post-login -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json
auth0 actions create -n myaction -t post-login -c "$(cat path/to/code.js)" -r node18 -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json
```


Expand All @@ -37,6 +37,7 @@ auth0 actions create [flags]
-d, --dependency stringToString Third party npm module, and its version, that the action depends on. (default [])
--json Output in json format.
-n, --name string Name of the action.
-r, --runtime string Runtime to be used in the action.
-s, --secret stringToString Secrets to be used in the action. (default [])
-t, --trigger string Trigger of the action. At this time, an action can only target a single trigger at a time.
```
Expand Down
10 changes: 6 additions & 4 deletions docs/auth0_actions_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ auth0 actions update [flags]
## Examples

```
auth0 actions update <action-id>
auth0 actions update <action-id> --name myaction
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)"
auth0 actions update <action-id>
auth0 actions update <action-id> --runtime node18
auth0 actions update <action-id> --name myaction --runtime node18
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js) --r node18"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value"
auth0 actions update <action-id> -n myaction -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json
auth0 actions update <action-id> -n myaction -c "$(cat path/to/code.js)" -r node18 -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json
```


Expand All @@ -37,6 +38,7 @@ auth0 actions update [flags]
--force Skip confirmation.
--json Output in json format.
-n, --name string Name of the action.
-r, --runtime string Runtime to be used in the action.
-s, --secret stringToString Secrets to be used in the action. (default [])
```

Expand Down
29 changes: 23 additions & 6 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ var (
Help: "Secrets to be used in the action.",
}

actionRuntime = Flag{
Name: "Runtime",
LongForm: "runtime",
ShortForm: "r",
Help: "Runtime to be used in the action.",
}

actionTemplates = map[string]string{
"post-login": actionTemplatePostLogin,
"credentials-exchange": actionTemplateCredentialsExchange,
Expand Down Expand Up @@ -173,6 +180,7 @@ func createActionCmd(cli *cli) *cobra.Command {
Code string
Dependencies map[string]string
Secrets map[string]string
Runtime string
}

cmd := &cobra.Command{
Expand All @@ -185,11 +193,11 @@ func createActionCmd(cli *cli) *cobra.Command {
Example: ` auth0 actions create
auth0 actions create --name myaction
auth0 actions create --name myaction --trigger post-login
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js) --runtime node18
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"
auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value"
auth0 actions create -n myaction -t post-login -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json`,
auth0 actions create -n myaction -t post-login -c "$(cat path/to/code.js)" -r node18 -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := actionName.Ask(cmd, &inputs.Name, nil); err != nil {
return err
Expand Down Expand Up @@ -235,6 +243,7 @@ func createActionCmd(cli *cli) *cobra.Command {
Version: &version,
},
},
Runtime: &inputs.Runtime,
Code: &inputs.Code,
Dependencies: inputDependenciesToActionDependencies(inputs.Dependencies),
Secrets: inputSecretsToActionSecrets(inputs.Secrets),
Expand All @@ -258,6 +267,7 @@ func createActionCmd(cli *cli) *cobra.Command {
actionCode.RegisterString(cmd, &inputs.Code, "")
actionDependency.RegisterStringMap(cmd, &inputs.Dependencies, nil)
actionSecret.RegisterStringMap(cmd, &inputs.Secrets, nil)
actionRuntime.RegisterString(cmd, &inputs.Runtime, "")

return cmd
}
Expand All @@ -269,6 +279,7 @@ func updateActionCmd(cli *cli) *cobra.Command {
Code string
Dependencies map[string]string
Secrets map[string]string
Runtime string
}

cmd := &cobra.Command{
Expand All @@ -279,13 +290,14 @@ func updateActionCmd(cli *cli) *cobra.Command {
"To update interactively, use `auth0 actions update` with no arguments.\n\n" +
"To update non-interactively, supply the action id, name, code, secrets and " +
"dependencies through the flags.",
Example: ` auth0 actions update <action-id>
auth0 actions update <action-id> --name myaction
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)"
Example: ` auth0 actions update <action-id>
auth0 actions update <action-id> --runtime node18
auth0 actions update <action-id> --name myaction --runtime node18
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js) --r node18"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"
auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value"
auth0 actions update <action-id> -n myaction -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json`,
auth0 actions update <action-id> -n myaction -c "$(cat path/to/code.js)" -r node18 -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
inputs.ID = args[0]
Expand Down Expand Up @@ -343,6 +355,10 @@ func updateActionCmd(cli *cli) *cobra.Command {
updatedAction.Secrets = inputSecretsToActionSecrets(inputs.Secrets)
}

if inputs.Runtime != "" {
updatedAction.Runtime = &inputs.Runtime
}

if err = ansi.Waiting(func() error {
return cli.api.Action.Update(cmd.Context(), oldAction.GetID(), updatedAction)
}); err != nil {
Expand All @@ -361,6 +377,7 @@ func updateActionCmd(cli *cli) *cobra.Command {
actionCode.RegisterStringU(cmd, &inputs.Code, "")
actionDependency.RegisterStringMapU(cmd, &inputs.Dependencies, nil)
actionSecret.RegisterStringMapU(cmd, &inputs.Secrets, nil)
actionRuntime.RegisterStringU(cmd, &inputs.Runtime, "")

return cmd
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/actions-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests:
exactly: "[]"

003 - it successfully creates an action:
command: auth0 actions create -n "integration-test-action1" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value"
command: auth0 actions create -n "integration-test-action1" -r node18 -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value"
exit-code: 0
stdout:
contains:
Expand All @@ -42,7 +42,7 @@ tests:
- DEPLOYED

005 - it successfully creates an action and outputs in json:
command: auth0 actions create -n "integration-test-action2" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value" --json
command: auth0 actions create -n "integration-test-action2" -r node18 -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value" --json
exit-code: 0
stdout:
json:
Expand Down Expand Up @@ -84,7 +84,7 @@ tests:
secrets.0.name: "SECRET"

008 - given a test action, it successfully updates the action's details:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET2=newValue"
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -r node18 -n "integration-test-action-updated" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET2=newValue"
exit-code: 0
stdout:
contains:
Expand All @@ -98,7 +98,7 @@ tests:
- "CODE function() {console.log()}"

009 - given a test action, it successfully updates the action's details and outputs in json:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated-again" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET3=newValue" --json
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -r node18 -n "integration-test-action-updated-again" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET3=newValue" --json
exit-code: 0
stdout:
json:
Expand Down
Loading