MCPcopy Create free account
hub / github.com/auth0/auth0-cli / createActionCmd

Function createActionCmd

internal/cli/actions.go:185–284  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

183}
184
185func createActionCmd(cli *cli) *cobra.Command {
186 var inputs struct {
187 Name string
188 Trigger string
189 Code string
190 Dependencies map[string]string
191 Secrets map[string]string
192 Runtime string
193 }
194
195 cmd := &cobra.Command{
196 Use: "create",
197 Args: cobra.NoArgs,
198 Short: "Create a new action",
199 Long: "Create a new action.\n\n" +
200 "To create interactively, use `auth0 actions create` with no flags.\n\n" +
201 "To create non-interactively, supply the action name, trigger, code, secrets and dependencies through the flags.",
202 Example: ` auth0 actions create
203 auth0 actions create --name myaction
204 auth0 actions create --name myaction --trigger post-login
205 auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --runtime node18
206 auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0"
207 auth0 actions create --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"
208 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"
209 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
210 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-compact`,
211 RunE: func(cmd *cobra.Command, args []string) error {
212 if err := actionName.Ask(cmd, &inputs.Name, nil); err != nil {
213 return err
214 }
215
216 triggers, err := getCurrentTriggers(cmd.Context(), cli)
217 if err != nil {
218 return fmt.Errorf("failed to retrieve available triggers: %w", err)
219 }
220
221 triggerIDs := make([]string, 0)
222 for _, t := range triggers {
223 triggerIDs = append(triggerIDs, t.GetID())
224 }
225
226 if err := actionTrigger.Select(cmd, &inputs.Trigger, triggerIDs, nil); err != nil {
227 return err
228 }
229
230 if err := actionCode.OpenEditor(
231 cmd,
232 &inputs.Code,
233 actionTemplate(inputs.Trigger),
234 inputs.Name+".*.js",
235 cli.actionEditorHint,
236 ); err != nil {
237 return err
238 }
239
240 var version string
241 for _, t := range triggers {
242 if t.GetID() == inputs.Trigger {

Callers 1

actionsCmdFunction · 0.85

Calls 13

WaitingFunction · 0.92
getCurrentTriggersFunction · 0.85
actionTemplateFunction · 0.85
ErrorfMethod · 0.80
SelectMethod · 0.80
OpenEditorMethod · 0.80
ActionCreateMethod · 0.80
RegisterStringMethod · 0.80
RegisterStringMapMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected