Skip to content
This repository was archived by the owner on Mar 8, 2026. It is now read-only.

Commit cfc5236

Browse files
add subscription_status and trial_ends_at to Tenant; validate in middleware
- Tenant struct gains SubscriptionStatus and TrialEndsAt fields - Validator returns 401 when tenant has no active subscription and trial has expired - InMemoryClient returns active subscription for tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 20fa81d commit cfc5236

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

ds/client_inmemory.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package ds
22

3-
import "reflect"
3+
import (
4+
"reflect"
5+
"time"
6+
)
47

58
type InMemoryClient struct {
69
payload map[Kind]interface{}
@@ -19,8 +22,10 @@ func (c *InMemoryClient) Get(kind Kind, id string, dst interface{}) error {
1922

2023
if kind == KindTenant {
2124
reflect.ValueOf(dst).Elem().Set(reflect.ValueOf(Tenant{
22-
Id: id,
23-
Name: "test-123",
25+
Id: id,
26+
Name: "test-123",
27+
SubscriptionStatus: "active",
28+
TrialEndsAt: time.Now().Unix() + 86400,
2429
}))
2530
}
2631

ds/model.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package ds
22

33
type Tenant struct {
4-
Id string `datastore:"id" json:"id"`
5-
Name string `datastore:"name" json:"name"`
6-
Email string `datastore:"email" json:"email"`
7-
Callback string `datastore:"callback" json:"callback"`
8-
SlackChannel string `datastore:"slack_channel" json:"slack_channel"`
9-
Created int64 `datastore:"created" json:"created"`
10-
Comment int64 `datastore:"comment" json:"comment"`
4+
Id string `datastore:"id" json:"id"`
5+
Name string `datastore:"name" json:"name"`
6+
Email string `datastore:"email" json:"email"`
7+
Callback string `datastore:"callback" json:"callback"`
8+
SlackChannel string `datastore:"slack_channel" json:"slack_channel"`
9+
Created int64 `datastore:"created" json:"created"`
10+
Comment int64 `datastore:"comment" json:"comment"`
11+
SubscriptionStatus string `datastore:"subscription_status" json:"subscription_status"`
12+
TrialEndsAt int64 `datastore:"trial_ends_at" json:"trial_ends_at"`
1113
}
1214

1315
type Webhook struct {

tenant/tenant.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tenant
22

33
import (
44
"net/http"
5+
"time"
56

67
"github.com/gorilla/mux"
78
"github.com/oasdiff/go-common/ds"
@@ -29,6 +30,12 @@ func (v *Validator) Validate(next http.Handler) http.Handler {
2930
return
3031
}
3132

33+
if t.SubscriptionStatus != "active" && t.TrialEndsAt <= time.Now().Unix() {
34+
logrus.Infof("tenant '%s' has no active subscription or trial for request '%s'", id, r.URL.String())
35+
w.WriteHeader(http.StatusUnauthorized)
36+
return
37+
}
38+
3239
next.ServeHTTP(w, r)
3340
})
3441
}

0 commit comments

Comments
 (0)