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

Function triggerEventStreamCmd

internal/cli/event_streams.go:415–494  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

413}
414
415func triggerEventStreamCmd(cli *cli) *cobra.Command {
416 var inputs struct {
417 ID string
418 EventType string
419 Payload string
420 }
421
422 cmd := &cobra.Command{
423 Use: "trigger <event-id>",
424 Args: cobra.MaximumNArgs(1),
425 Short: "Trigger a test event for an event stream",
426 Long: "Manually trigger a test event for a specific Event Stream.\n\n" +
427 "Use this to simulate an event like `user.created` or `user.updated`.\n" +
428 "You can optionally provide a JSON payload from a file to simulate request content.",
429 Example: ` auth0 event-streams trigger <event-id> --type user.created
430 auth0 event-streams trigger <event-id> --type user.updated --payload ./test-event.json`,
431 RunE: func(cmd *cobra.Command, args []string) error {
432 if len(args) > 0 {
433 inputs.ID = args[0]
434 } else {
435 if err := eventStreamID.Pick(cmd, &inputs.ID, cli.eventStreamPickerOptions); err != nil {
436 return err
437 }
438 }
439
440 if inputs.EventType == "" {
441 var stream *management.EventStream
442 if err := ansi.Waiting(func() (err error) {
443 stream, err = cli.api.EventStream.Read(cmd.Context(), inputs.ID)
444 return err
445 }); err != nil {
446 return fmt.Errorf("failed to fetch stream details for ID %q: %w", inputs.ID, err)
447 }
448
449 var eventTypeOptions []string
450 for _, s := range stream.GetSubscriptions() {
451 eventTypeOptions = append(eventTypeOptions, s.GetEventStreamSubscriptionType())
452 }
453
454 if err := eventStreamType.Select(cmd, &inputs.EventType, eventTypeOptions, nil); err != nil {
455 return err
456 }
457 }
458
459 var payload map[string]interface{}
460
461 if inputs.Payload != "" {
462 data, err := os.ReadFile(inputs.Payload)
463 if err != nil {
464 return fmt.Errorf("failed to read payload file %q: %w", inputs.Payload, err)
465 }
466 if err := json.Unmarshal(data, &payload); err != nil {
467 return fmt.Errorf("invalid JSON in payload file: %w", err)
468 }
469 }
470
471 testEvent := &management.TestEvent{
472 EventType: auth0.String(inputs.EventType),

Callers 1

eventStreamsCmdFunction · 0.85

Calls 8

WaitingFunction · 0.92
FaintFunction · 0.92
ErrorfMethod · 0.80
SelectMethod · 0.80
InfofMethod · 0.80
ReadMethod · 0.65
TestMethod · 0.65
PickMethod · 0.45

Tested by

no test coverage detected