Skip to content

Commit 83a1866

Browse files
authored
feat: add HTTP event streams (#417)
1 parent 1c7be12 commit 83a1866

6 files changed

Lines changed: 54 additions & 19 deletions

File tree

cmd/cloudx/eventstreams/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewCreateEventStreamCmd() *cobra.Command {
1717
c := streamConfig{}
1818

1919
cmd := &cobra.Command{
20-
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",
20+
Use: "event-stream [--project=PROJECT_ID] --type={sns,https} {--aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole --aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic, --https-endpoint=https://example.com/webhook}",
2121
Short: "Create a new event stream",
2222
Args: cobra.NoArgs,
2323
RunE: func(cmd *cobra.Command, args []string) error {

cmd/cloudx/eventstreams/flags.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package eventstreams
55

66
import (
77
"fmt"
8+
"net/url"
89

910
"github.com/spf13/pflag"
1011

@@ -14,19 +15,45 @@ import (
1415
type streamConfig client.CreateEventStreamBody
1516

1617
func (c *streamConfig) Validate() error {
17-
switch "" {
18-
case c.Type:
18+
switch c.Type {
19+
case "":
1920
return fmt.Errorf("flag --type must be set")
20-
case c.RoleArn:
21-
return fmt.Errorf("flag --aws-iam-role-arn must be set")
22-
case c.TopicArn:
23-
return fmt.Errorf("flag --aws-sns-topic-arn must be set")
21+
case "sns":
22+
if c.RoleArn == nil || *c.RoleArn == "" {
23+
return fmt.Errorf("flag --aws-iam-role-arn must be set")
24+
}
25+
if c.TopicArn == nil || *c.TopicArn == "" {
26+
return fmt.Errorf("flag --aws-sns-topic-arn must be set")
27+
}
28+
if c.HttpsEndpoint != nil && *c.HttpsEndpoint != "" {
29+
return fmt.Errorf("flag --https-endpoint cannot be set when type is sns")
30+
}
31+
case "https":
32+
if c.HttpsEndpoint == nil || *c.HttpsEndpoint == "" {
33+
return fmt.Errorf("flag --https-endpoint must be set")
34+
}
35+
e, err := url.Parse(*c.HttpsEndpoint)
36+
if err != nil {
37+
return fmt.Errorf("invalid URL for flag --https-endpoint: %w", err)
38+
}
39+
if e.Scheme != "https" {
40+
return fmt.Errorf("flag --https-endpoint must have https scheme")
41+
}
42+
if c.RoleArn != nil && *c.RoleArn != "" {
43+
return fmt.Errorf("flag --aws-iam-role-arn cannot be set when type is https")
44+
}
45+
if c.TopicArn != nil && *c.TopicArn != "" {
46+
return fmt.Errorf("flag --aws-sns-topic-arn cannot be set when type is https")
47+
}
48+
default:
49+
return fmt.Errorf("unsupported event stream type: %s", c.Type)
2450
}
2551
return nil
2652
}
2753

2854
func registerStreamConfigFlags(f *pflag.FlagSet, c *streamConfig) {
29-
f.StringVar(&c.Type, "type", "", `The type of the event stream destination. Only "sns" is supported at the moment.`)
30-
f.StringVar(&c.RoleArn, "aws-iam-role-arn", "", "The ARN of the AWS IAM role to assume when publishing messages to the SNS topic.")
31-
f.StringVar(&c.TopicArn, "aws-sns-topic-arn", "", "The ARN of the AWS SNS topic.")
55+
f.StringVar(&c.Type, "type", "", `The type of the event stream destination. Supported values are "sns" for AWS SNS topics and "https" for generic HTTPS endpoints.`)
56+
c.RoleArn = f.String("aws-iam-role-arn", "", "The ARN of the AWS IAM role to assume when publishing messages to the SNS topic.")
57+
c.TopicArn = f.String("aws-sns-topic-arn", "", "The ARN of the AWS SNS topic.")
58+
c.HttpsEndpoint = f.String("https-endpoint", "", "The URL of the HTTPS endpoint.")
3259
}

cmd/cloudx/eventstreams/output.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ type (
1515
)
1616

1717
func (output) Header() []string {
18-
return []string{"ID", "TYPE", "IAM_ROLE_ARN", "SNS_TOPIC_ARN"}
18+
return []string{"ID", "TYPE", "IAM_ROLE_ARN", "SNS_TOPIC_ARN", "HTTPS_ENDPOINT"}
1919
}
2020

2121
func (o output) Columns() []string {
2222
return []string{
23-
*o.Id,
24-
*o.Type,
25-
*o.RoleArn,
26-
*o.TopicArn,
23+
coalesce(o.Id),
24+
coalesce(o.Type),
25+
coalesce(o.RoleArn),
26+
coalesce(o.TopicArn),
27+
coalesce(o.HttpsEndpoint.Get()),
2728
}
2829
}
2930

31+
func coalesce(s *string) string {
32+
if s == nil {
33+
return ""
34+
}
35+
return *s
36+
}
37+
3038
func (o output) Interface() interface{} {
3139
return o
3240
}

cmd/cloudx/eventstreams/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func NewUpdateEventStreamCmd() *cobra.Command {
1818
c := streamConfig{}
1919

2020
cmd := &cobra.Command{
21-
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]",
21+
Use: "event-stream id [--project=PROJECT_ID] --type={sns,https} {--aws-iam-role-arn=arn:aws:iam::123456789012:role/MyRole --aws-sns-topic-arn=arn:aws:sns:us-east-1:123456789012:MyTopic, --https-endpoint=https://example.com/webhook}",
2222
Args: cobra.ExactArgs(1),
2323
Short: "Update the event stream with the given ID",
2424
RunE: func(cmd *cobra.Command, args []string) error {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/gofrs/uuid/v3 v3.1.2
2222
github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6
2323
github.com/hashicorp/go-retryablehttp v0.7.8
24-
github.com/ory/client-go v1.22.26
24+
github.com/ory/client-go v1.22.32
2525
github.com/ory/gochimp3 v0.0.0-20200417124117-ccd242db3655
2626
github.com/ory/graceful v0.1.4-0.20230301144740-e222150c51d0
2727
github.com/ory/herodot v0.10.8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LD
554554
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
555555
github.com/ory/analytics-go/v5 v5.0.1 h1:LX8T5B9FN8KZXOtxgN+R3I4THRRVB6+28IKgKBpXmAM=
556556
github.com/ory/analytics-go/v5 v5.0.1/go.mod h1:lWCiCjAaJkKfgR/BN5DCLMol8BjKS1x+4jxBxff/FF0=
557-
github.com/ory/client-go v1.22.26 h1:BmkdtHswtZQ9/+3QBQDUuTPCpjYVYpXoMo/ZAzRF5Tg=
558-
github.com/ory/client-go v1.22.26/go.mod h1:7zxu6CcDaf5Khovhrs+eWxY4TVaCnGxlK2C/b48HgNg=
557+
github.com/ory/client-go v1.22.32 h1:31kLMk6DynhoyjXO7Gx6DRI9VX7RBdCQDxppfCiGtxg=
558+
github.com/ory/client-go v1.22.32/go.mod h1:G1f+5+m/PJVvl40bsRn0QuyVIcXe7EHiWeM7iWpIDjw=
559559
github.com/ory/dockertest/v4 v4.0.0-beta.4 h1:QcrNrobOP+5IjSDmS4//EuBtwiFuznQhi5xTe8oFSoM=
560560
github.com/ory/dockertest/v4 v4.0.0-beta.4/go.mod h1:p9kfE14tzK8+WU4F9YbIZlzhCzQ2pH7H1KIfBKrF3DM=
561561
github.com/ory/go-acc v0.2.9-0.20230103102148-6b1c9a70dbbe h1:rvu4obdvqR0fkSIJ8IfgzKOWwZ5kOT2UNfLq81Qk7rc=

0 commit comments

Comments
 (0)