(cli *cli)
| 284 | } |
| 285 | |
| 286 | func updateActionCmd(cli *cli) *cobra.Command { |
| 287 | var inputs struct { |
| 288 | ID string |
| 289 | Name string |
| 290 | Code string |
| 291 | Dependencies map[string]string |
| 292 | Secrets map[string]string |
| 293 | Runtime string |
| 294 | } |
| 295 | |
| 296 | cmd := &cobra.Command{ |
| 297 | Use: "update", |
| 298 | Args: cobra.MaximumNArgs(1), |
| 299 | Short: "Update an action", |
| 300 | Long: "Update an action.\n\n" + |
| 301 | "To update interactively, use `auth0 actions update` with no arguments.\n\n" + |
| 302 | "To update non-interactively, supply the action id, name, code, secrets and " + |
| 303 | "dependencies through the flags.", |
| 304 | Example: ` auth0 actions update <action-id> |
| 305 | auth0 actions update <action-id> --runtime node18 |
| 306 | auth0 actions update <action-id> --name myaction --runtime node18 |
| 307 | auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js) --r node18" |
| 308 | auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" |
| 309 | auth0 actions update <action-id> --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" |
| 310 | 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" |
| 311 | 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 |
| 312 | 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-compact`, |
| 313 | RunE: func(cmd *cobra.Command, args []string) error { |
| 314 | if len(args) > 0 { |
| 315 | inputs.ID = args[0] |
| 316 | } else { |
| 317 | if err := actionID.Pick(cmd, &inputs.ID, cli.actionPickerOptions); err != nil { |
| 318 | return err |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | var oldAction *management.Action |
| 323 | err := ansi.Waiting(func() (err error) { |
| 324 | oldAction, err = cli.api.Action.Read(cmd.Context(), inputs.ID) |
| 325 | return err |
| 326 | }) |
| 327 | if err != nil { |
| 328 | return fmt.Errorf("failed to read action with ID %q: %w", inputs.ID, err) |
| 329 | } |
| 330 | |
| 331 | if err := actionName.AskU(cmd, &inputs.Name, oldAction.Name); err != nil { |
| 332 | return err |
| 333 | } |
| 334 | |
| 335 | if err := actionCode.OpenEditorU( |
| 336 | cmd, |
| 337 | &inputs.Code, |
| 338 | oldAction.GetCode(), |
| 339 | inputs.Name+".*.js", |
| 340 | ); err != nil { |
| 341 | return fmt.Errorf("failed to capture input from the editor: %w", err) |
| 342 | } |
| 343 |
no test coverage detected