-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: event-streams: create, update, list, delete
- Loading branch information
Showing
13 changed files
with
360 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"gopls": { | ||
"formatting.local": "github.com/ory", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package eventstreams | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/cli/cmd/cloudx/client" | ||
cloud "github.com/ory/client-go" | ||
"github.com/ory/x/cmdx" | ||
"github.com/ory/x/flagx" | ||
) | ||
|
||
func NewCreateEventStreamCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "event-stream [--project=PROJECT_ID] --type=sns --aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole --aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic", | ||
Short: "Create a new event stream", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
h, err := client.NewCommandHelper(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectID, err := client.ProjectOrDefault(cmd, h) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
stream, err := h.CreateEventStream(projectID, cloud.CreateEventStreamBody{ | ||
Type: flagx.MustGetString(cmd, "type"), | ||
RoleArn: flagx.MustGetString(cmd, "aws-iam-role-arn"), | ||
TopicArn: flagx.MustGetString(cmd, "aws-sns-topic-arn"), | ||
}) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
_, _ = fmt.Fprintln(h.VerboseErrWriter, "Event stream created successfully!") | ||
cmdx.PrintRow(cmd, output(*stream)) | ||
return nil | ||
}, | ||
} | ||
|
||
client.RegisterProjectFlag(cmd.Flags()) | ||
cmdx.RegisterFormatFlags(cmd.Flags()) | ||
cmd.Flags().String("type", "", `The type of the event stream destination. Only "sns" is supported at the moment.`) | ||
cmd.Flags().String("aws-iam-role-arn", "", "The ARN of the AWS IAM role to assume when publishing messages to the SNS topic.") | ||
cmd.Flags().String("aws-sns-topic-arn", "", "The ARN of the AWS SNS topic.") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package eventstreams | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/cli/cmd/cloudx/client" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewDeleteEventStream() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "event-stream id [--project=PROJECT_ID]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Delete the event stream with the given ID", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
h, err := client.NewCommandHelper(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectID, err := client.ProjectOrDefault(cmd, h) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
streamID := args[0] | ||
|
||
err = h.DeleteEventStream(projectID, streamID) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
_, _ = fmt.Fprintln(h.VerboseErrWriter, "Event stream deleted successfully!") | ||
return nil | ||
}, | ||
} | ||
|
||
client.RegisterProjectFlag(cmd.Flags()) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package eventstreams | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/cli/cmd/cloudx/client" | ||
"github.com/ory/x/cmdx" | ||
) | ||
|
||
func NewListEventStreamsCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "event-streams", | ||
Args: cobra.NoArgs, | ||
Short: "List your event streams", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
h, err := client.NewCommandHelper(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id, err := client.ProjectOrDefault(cmd, h) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
streams, err := h.ListEventStreams(id) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
cmdx.PrintTable(cmd, outputList(*streams)) | ||
return nil | ||
}, | ||
} | ||
|
||
client.RegisterProjectFlag(cmd.Flags()) | ||
cmdx.RegisterFormatFlags(cmd.Flags()) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package eventstreams | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
client "github.com/ory/client-go" | ||
) | ||
|
||
type ( | ||
outputList client.ListEventStreams | ||
output client.EventStream | ||
) | ||
|
||
func (output) Header() []string { | ||
return []string{"ID", "TYPE", "IAM_ROLE_ARN", "SNS_TOPIC_ARN"} | ||
} | ||
|
||
func (o output) Columns() []string { | ||
return []string{ | ||
*o.Id, | ||
*o.Type, | ||
*o.RoleArn, | ||
*o.TopicArn, | ||
} | ||
} | ||
|
||
func (o output) Interface() interface{} { | ||
return o | ||
} | ||
|
||
func (outputList) Header() []string { | ||
return new(output).Header() | ||
} | ||
|
||
func (o outputList) Table() [][]string { | ||
rows := make([][]string, len(o.EventStreams)) | ||
for i, stream := range o.EventStreams { | ||
rows[i] = (output)(stream).Columns() | ||
} | ||
return rows | ||
} | ||
|
||
func (o outputList) Interface() interface{} { | ||
return o | ||
} | ||
|
||
func (o outputList) Len() int { | ||
return len(o.EventStreams) | ||
} | ||
|
||
func (o outputList) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(o.EventStreams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package eventstreams | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/cli/cmd/cloudx/client" | ||
cloud "github.com/ory/client-go" | ||
|
||
"github.com/ory/x/cmdx" | ||
"github.com/ory/x/flagx" | ||
) | ||
|
||
func NewUpdateEventStreamCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "event-stream id [--project=PROJECT_ID] [--type=sns] [--aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole] [--aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Update the event stream with the given ID", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
h, err := client.NewCommandHelper(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectID, err := client.ProjectOrDefault(cmd, h) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
streamID := args[0] | ||
|
||
stream, err := h.UpdateEventStream(projectID, streamID, cloud.SetEventStreamBody{ | ||
Type: flagx.MustGetString(cmd, "type"), | ||
RoleArn: flagx.MustGetString(cmd, "aws-iam-role-arn"), | ||
TopicArn: flagx.MustGetString(cmd, "aws-sns-topic-arn"), | ||
}) | ||
if err != nil { | ||
return cmdx.PrintOpenAPIError(cmd, err) | ||
} | ||
|
||
_, _ = fmt.Fprintln(h.VerboseErrWriter, "Event stream updated successfully!") | ||
cmdx.PrintRow(cmd, output(*stream)) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().String("type", "", `The type of the event stream destination. Only "sns" is supported at the moment.`) | ||
cmd.Flags().String("aws-iam-role-arn", "", "The ARN of the AWS IAM role to assume when publishing messages to the SNS topic.") | ||
cmd.Flags().String("aws-sns-topic-arn", "", "The ARN of the AWS SNS topic.") | ||
client.RegisterProjectFlag(cmd.Flags()) | ||
cmdx.RegisterFormatFlags(cmd.Flags()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.