Skip to content

Commit

Permalink
fixup! Add the ingress-postgres-outbox ingress rule
Browse files Browse the repository at this point in the history
  • Loading branch information
graham-russell committed Dec 11, 2024
1 parent 9282214 commit 2edce50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
38 changes: 35 additions & 3 deletions ingress_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type NewIngressRule struct {
// The status of the rule. Rules can be enabled or disabled.
Status string `json:"status,omitempty"`
// The rule target.
Target Target `json:"target"`
Target IngressTarget `json:"target"`
}

func (r *NewIngressRule) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -128,6 +128,11 @@ func (s *IngressMongoTarget) TargetType() string {
return "ingress/mongodb"
}

// RuleType gets the type of target this rule has.
func (r *IngressRule) RuleType() string {
return r.Target.TargetType()
}

type IngressPostgresOutboxTarget struct {
// The URL for your Postgres database.
Url string `json:"url,omitempty"`
Expand Down Expand Up @@ -159,8 +164,35 @@ func (s *IngressPostgresOutboxTarget) TargetType() string {
}

// Creates an Ingress rule for the application with the specified application ID.
func (c *Client) CreateIngressRule(appID string, rule *NewIngressRule) (Rule, error) {
var out Rule
func (c *Client) CreateIngressRule(appID string, rule *NewIngressRule) (IngressRule, error) {
var out IngressRule
err := c.request("POST", "/apps/"+appID+"/rules", &rule, &out)
return out, err
}

// Lists the rules for the application specified by the application ID.
func (c *Client) IngressRules(appID string) ([]IngressRule, error) {
var rules []IngressRule
err := c.request("GET", "/apps/"+appID+"/rules", nil, &rules)
return rules, err
}

// Returns the ingess rule specified by the rule ID, for the application specified by application ID.
func (c *Client) IngressRule(appID, ruleID string) (IngressRule, error) {
var rule IngressRule
err := c.request("GET", "/apps/"+appID+"/rules/"+ruleID, nil, &rule)
return rule, err
}

// Updates the rule specified by the rule ID, for the application specified by application ID.
func (c *Client) UpdateIngressRule(appID, ruleID string, rule *NewIngressRule) (IngressRule, error) {
var out IngressRule
err := c.request("PATCH", "/apps/"+appID+"/rules/"+ruleID, &rule, &out)
return out, err
}

// Deletes the rule specified by the rule ID, for the application specified by application ID.
func (c *Client) DeleteIngressRule(appID, ruleID string) error {
err := c.request("DELETE", "/apps/"+appID+"/rules/"+ruleID, nil, nil)
return err
}
6 changes: 3 additions & 3 deletions ingress_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestRuleIngressPostgresOutbox(t *testing.T) {
testIngressRule(t, target)
}

func testIngressRule(t *testing.T, target Target) {
func testIngressRule(t *testing.T, target IngressTarget) {
client, _ := newTestClient(t)
app := newTestApp(t, &client)

Expand All @@ -55,11 +55,11 @@ func testIngressRule(t *testing.T, target Target) {
assert.NotEmpty(t, r.Created)
assert.NotEmpty(t, r.Modified)

r2, err := client.Rule(app.ID, r.ID)
r2, err := client.IngressRule(app.ID, r.ID)
assert.NoError(t, err)
assert.Equal(t, r, r2)

err = client.DeleteRule(app.ID, r.ID)
err = client.DeleteIngressRule(app.ID, r.ID)
assert.NoError(t, err)

err = client.DeleteApp(app.ID)
Expand Down
4 changes: 0 additions & 4 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ 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

0 comments on commit 2edce50

Please sign in to comment.