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

Function createEventStreamCmd

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

Source from the content-addressed store, hash-verified

173}
174
175func createEventStreamCmd(cli *cli) *cobra.Command {
176 var inputs struct {
177 Name string
178 Type string
179 Subscriptions []string
180 Configuration string
181 }
182
183 cmd := &cobra.Command{
184 Use: "create",
185 Args: cobra.NoArgs,
186 Short: "Create a new event stream",
187 Long: "Create a new event stream.\n\n" +
188 "To create interactively, use `auth0 event-streams create` with no flags.\n\n" +
189 "To create non-interactively, supply the event stream name, type, subscriptions and configuration through the flags. \n" +
190 "Only deployed actions can be used for action configuration",
191 Example: ` auth0 event-streams create
192 auth0 event-streams create --name my-event-stream --type eventbridge --subscriptions "user.created,user.updated" --configuration '{"aws_account_id":"325235643634","aws_region":"us-east-2"}'
193 auth0 event-streams create --name my-event-stream --type webhook --subscriptions "user.created,user.deleted" --configuration '{"webhook_endpoint":"https://mywebhook.net","webhook_authorization":{"method":"bearer","token":"123456789"}}'
194 auth0 event-streams create --name my-event-stream --type action --subscriptions "user.created" --configuration '{"action_id":"b053e4ca-8b14-4233-b615-bd3bdb353977"}'
195 auth0 event-streams create -n my-event-stream -t webhook -s "user.created,user.deleted" -c '{"webhook_endpoint":"https://mywebhook.net","webhook_authorization":{"method":"bearer","token":"123456789"}}'`,
196 RunE: func(cmd *cobra.Command, args []string) error {
197 if err := eventStreamName.Ask(cmd, &inputs.Name, nil); err != nil {
198 return err
199 }
200 if err := eventStreamType.Ask(cmd, &inputs.Type, nil); err != nil {
201 return err
202 }
203
204 if err := eventStreamSubscriptions.AskMany(cmd, &inputs.Subscriptions, nil); err != nil {
205 return err
206 }
207
208 var configuration map[string]interface{}
209
210 if err := eventStreamConfig.Ask(cmd, &inputs.Configuration, auth0.String("{}")); err != nil {
211 return err
212 }
213
214 if err := json.Unmarshal([]byte(inputs.Configuration), &configuration); err != nil {
215 return fmt.Errorf("provider: %s event stream config invalid JSON: %w", inputs.Name, err)
216 }
217
218 if len(inputs.Configuration) == 0 {
219 return fmt.Errorf("must provider configuration for event stream")
220 }
221
222 var subscriptions []management.EventStreamSubscription
223 for _, sub := range inputs.Subscriptions {
224 subscriptions = append(subscriptions, management.EventStreamSubscription{
225 EventStreamSubscriptionType: &sub,
226 })
227 }
228 eventStream := &management.EventStream{
229 Name: &inputs.Name,
230 Subscriptions: &subscriptions,
231 Destination: &management.EventStreamDestination{
232 EventStreamDestinationType: &inputs.Type,

Callers 1

eventStreamsCmdFunction · 0.85

Calls 8

WaitingFunction · 0.92
AskManyMethod · 0.80
ErrorfMethod · 0.80
EventStreamCreateMethod · 0.80
RegisterStringMethod · 0.80
RegisterStringSliceMethod · 0.80
CreateMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected