Skip to content

Commit

Permalink
[INF-5307] - Update SDK with ingress/mongodb Integration Rule
Browse files Browse the repository at this point in the history
We have recently added Integration Rules for MongoDB. This exposes them. An update the the Ably Terraform provider will come in a separate step.
  • Loading branch information
graham-russell committed Dec 6, 2024
1 parent 7e96bc9 commit 8b32290
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (r *Rule) UnmarshalJSON(data []byte) error {
var t AmqpTarget
err = json.Unmarshal(raw.Target, &t)
r.Target = &t
case "ingress/mongodb":
var t IngressMongoTarget
err = json.Unmarshal(raw.Target, &t)
r.Target = &t
case "aws/sqs":
var t AwsSqsTarget
err = json.Unmarshal(raw.Target, &t)
Expand Down Expand Up @@ -465,6 +469,33 @@ func (s *AmqpTarget) TargetType() string {
return "amqp"
}

// MongoTarget is the type used for MongoDB Ingress rules.
type IngressMongoTarget struct {
// The URL of the MongoDB server.
Url string `json:"url,omitempty"`
// Watch is the collection to watch.
Watch string `json:"watch,omitempty"`
// The database to watch.
Database string `json:"database,omitempty"`
// The collection to watch.
Collection string `json:"collection,omitempty"`
// The pipeline to use.
Pipeline string `json:"pipeline,omitempty"`
// FullDocument controls how the full document is sent.
FullDocument string `json:"fullDocument,omitempty"`
// FullDocumentBeforeChange controls how the full document is sent.
FullDocumentBeforeChange string `json:"fullDocumentBeforeChange,omitempty"`
// The primary site.
PrimarySite string `json:"primarySite,omitempty"`
// The provisioned capacity.
ProvisionedCapacity int `json:"provisionedCapacity,omitempty"`
}

// IngressMongoTarget implements the Target interface.
func (s *IngressMongoTarget) TargetType() string {
return "ingress/mongodb"
}

// AwsSqsTarget is the type used for aws/sqs rules.
type AwsSqsTarget struct {
// The region is which AWS SQS is hosted. See the AWS documentation for more detail.
Expand Down
16 changes: 16 additions & 0 deletions rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ func TestRuleAmqpExtrernal(t *testing.T) {
testRule(t, target)
}

func TestRuleIngressMongo(t *testing.T) {
target := &IngressMongoTarget{
Url: "mongodb://coco:[email protected]:27017",
Watch: "COLLECTION",
Database: "coconut",
Collection: "coconut",
Pipeline: "[{'$set': {'_ablyChannel': 'myChannel'}}]",
FullDocument: "off",
FullDocumentBeforeChange: "off",
PrimarySite: "us-east-1-A",
ProvisionedCapacity: 1,
}

testRule(t, target)
}

func TestRuleAmqp(t *testing.T) {
target := &AmqpTarget{
Headers: []Header{{Name: "a", Value: "b"}},
Expand Down

0 comments on commit 8b32290

Please sign in to comment.