Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fedcea06c7 | ||
|
|
8d8a5814d8 | ||
|
|
8fa1a1bffd | ||
|
|
a37ae1d121 | ||
|
|
9138731eea |
+18
-13
@@ -93,30 +93,35 @@ jobs:
|
||||
run: go build ./...
|
||||
|
||||
image:
|
||||
# Mirrors the portal CI pattern (platform/portal PR #14): push to
|
||||
# registry.meghsakha.com, then POST a github-style payload signed
|
||||
# with HMAC-SHA256 to the orca webhook on the master. Master matches
|
||||
# on repo+branch and redeploys the breakpilot-tenant-registry service.
|
||||
needs: [shared, test]
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && hashFiles('Dockerfile') != ''
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
registry: registry.breakpilot.com
|
||||
registry: registry.meghsakha.com
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASS }}
|
||||
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
registry.breakpilot.com/${{ github.event.repository.name }}:sha-${{ github.sha }}
|
||||
registry.breakpilot.com/${{ github.event.repository.name }}:env-stage
|
||||
|
||||
- uses: anchore/sbom-action@v0
|
||||
with:
|
||||
image: registry.breakpilot.com/${{ github.event.repository.name }}:sha-${{ github.sha }}
|
||||
|
||||
- name: orca deploy stage
|
||||
run: orca apply --env=stage --image-tag=sha-${{ github.sha }}
|
||||
registry.meghsakha.com/breakpilot/tenant-registry:latest
|
||||
registry.meghsakha.com/breakpilot/tenant-registry:sha-${{ github.sha }}
|
||||
- name: trigger orca redeploy
|
||||
env:
|
||||
ORCA_TOKEN: ${{ secrets.ORCA_STAGE_TOKEN }}
|
||||
ORCA_WEBHOOK_SECRET: ${{ secrets.ORCA_WEBHOOK_SECRET }}
|
||||
run: |
|
||||
BODY='{"repository":{"full_name":"platform/tenant-registry"},"ref":"refs/heads/main"}'
|
||||
SIG="sha256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$ORCA_WEBHOOK_SECRET" -hex | awk '{print $NF}')"
|
||||
curl -ksSf -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-GitHub-Event: push" \
|
||||
-H "X-Hub-Signature-256: $SIG" \
|
||||
-d "$BODY" \
|
||||
https://46.225.100.82:6880/api/v1/webhooks/github
|
||||
|
||||
@@ -6,6 +6,7 @@ Generated section is appended on release tag via `git-cliff` (see `.gitea/workfl
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- feat(store): CreateTenant defaults trial_ends_at to NOW()+14d for customer kind; demo kind gets status='demo' and no trial end
|
||||
- feat(keycloak): M4.3 — internal/keycloak adapter (Admin API: org create + IT_ADMIN invite + execute-actions-email + attribute sync). admin_email on POST /v1/tenants triggers KC provisioning; failures emit keycloak.provision_failed audit but don't roll back. POST /v1/internal/keycloak/claims resolves the current claim bundle for a tenant.
|
||||
- feat(api): M4.2 — full REST surface (tenants CRUD + lifecycle, catalog, entitlements, API keys w/ argon2 hashing, audit query). pgx-backed Postgres store; in-memory fallback when DATABASE_URL is empty. OpenAPI 3.1 spec at openapi.yaml with kin-openapi contract test.
|
||||
- feat(schema): M4.1 — golang-migrate migrations for tenants + tenant_projects + tenant_products + tenant_idp_config + api_keys + audit_log; cmd/migrate binary; testcontainers round-trip + seed + slug-constraint tests
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
# /tenant-registry — long-running API server
|
||||
# /migrate — one-shot schema migrator (Orca init container in prod)
|
||||
|
||||
FROM golang:1.24-alpine AS build
|
||||
FROM golang:1.25-alpine AS build
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
+13
-11
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -87,22 +88,23 @@ func (s *statusRecorder) WriteHeader(c int) {
|
||||
func clientIP(r *http.Request) string {
|
||||
if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" {
|
||||
if i := strings.IndexByte(fwd, ','); i > 0 {
|
||||
return strings.TrimSpace(fwd[:i])
|
||||
return stripBrackets(strings.TrimSpace(fwd[:i]))
|
||||
}
|
||||
return strings.TrimSpace(fwd)
|
||||
return stripBrackets(strings.TrimSpace(fwd))
|
||||
}
|
||||
if host, _, ok := splitHostPort(r.RemoteAddr); ok {
|
||||
if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
|
||||
// net.SplitHostPort returns IPv6 without brackets already.
|
||||
return host
|
||||
}
|
||||
return r.RemoteAddr
|
||||
return stripBrackets(r.RemoteAddr)
|
||||
}
|
||||
|
||||
// splitHostPort is a port-tolerant version of net.SplitHostPort that doesn't
|
||||
// error on missing port.
|
||||
func splitHostPort(s string) (string, string, bool) {
|
||||
i := strings.LastIndexByte(s, ':')
|
||||
if i < 0 {
|
||||
return s, "", false
|
||||
// stripBrackets removes the `[...]` wrapping IPv6 hosts pick up from
|
||||
// net/http's RemoteAddr in some Go versions, since Postgres `inet` rejects
|
||||
// `[::1]` but accepts `::1`.
|
||||
func stripBrackets(s string) string {
|
||||
if len(s) >= 2 && s[0] == '[' && s[len(s)-1] == ']' {
|
||||
return s[1 : len(s)-1]
|
||||
}
|
||||
return s[:i], s[i+1:], true
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package server_test
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.meghsakha.com/platform/tenant-registry/internal/store"
|
||||
)
|
||||
@@ -119,3 +120,42 @@ func TestCancelTenant(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_setsTrialEndsAt(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
_, body := h.do("POST", "/v1/tenants", map[string]any{
|
||||
"slug": "trial-ends-co", "name": "Trial Ends Co.",
|
||||
})
|
||||
out := decode[struct {
|
||||
Tenant *store.Tenant `json:"tenant"`
|
||||
}](t, body)
|
||||
if out.Tenant.Status != "trial" {
|
||||
t.Fatalf("status = %q, want trial", out.Tenant.Status)
|
||||
}
|
||||
if out.Tenant.TrialEndsAt == nil {
|
||||
t.Fatal("trial_ends_at is nil; should be ~14 days from now")
|
||||
}
|
||||
// Sanity-check: ends_at is in the future, within 13.5-14.5 days.
|
||||
delta := time.Until(*out.Tenant.TrialEndsAt)
|
||||
if delta < 13*24*time.Hour || delta > 15*24*time.Hour {
|
||||
t.Errorf("trial_ends_at offset = %v, want ~14d", delta)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_demoKindHasNoTrialEnd(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
_, body := h.do("POST", "/v1/tenants", map[string]any{
|
||||
"slug": "demo-co", "name": "Demo", "kind": "demo",
|
||||
})
|
||||
out := decode[struct {
|
||||
Tenant *store.Tenant `json:"tenant"`
|
||||
}](t, body)
|
||||
if out.Tenant.Status != "demo" {
|
||||
t.Errorf("status = %q, want demo", out.Tenant.Status)
|
||||
}
|
||||
if out.Tenant.TrialEndsAt != nil {
|
||||
t.Errorf("trial_ends_at = %v, want nil for demo kind", out.Tenant.TrialEndsAt)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -69,14 +69,24 @@ func (m *Memory) CreateTenant(_ context.Context, in TenantCreate) (*Tenant, erro
|
||||
return nil, ErrConflict
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
kind := firstNonEmpty(in.Kind, "customer")
|
||||
status := "trial"
|
||||
var trialEnds *time.Time
|
||||
if kind == "demo" {
|
||||
status = "demo"
|
||||
} else {
|
||||
end := now.Add(14 * 24 * time.Hour)
|
||||
trialEnds = &end
|
||||
}
|
||||
t := &Tenant{
|
||||
ID: uuid.NewString(),
|
||||
Slug: in.Slug,
|
||||
Name: in.Name,
|
||||
Status: "trial",
|
||||
Kind: firstNonEmpty(in.Kind, "customer"),
|
||||
Status: status,
|
||||
Kind: kind,
|
||||
Plan: firstNonEmpty(in.Plan, "starter"),
|
||||
SalesOwner: in.SalesOwner,
|
||||
TrialEndsAt: trialEnds,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
@@ -90,9 +90,20 @@ func scanTenant(row pgx.Row) (*Tenant, error) {
|
||||
func (p *Postgres) CreateTenant(ctx context.Context, in TenantCreate) (*Tenant, error) {
|
||||
kind := firstNonEmpty(in.Kind, "customer")
|
||||
plan := firstNonEmpty(in.Plan, "starter")
|
||||
// Default status = 'trial'; set trial_ends_at = NOW() + 14 days so the
|
||||
// portal's trial banner has a real countdown to render. Demo tenants
|
||||
// (kind=demo) get status='demo' and no trial_ends_at — that's set by
|
||||
// the M13.2 demo provisioning path.
|
||||
row := p.pool.QueryRow(ctx,
|
||||
`INSERT INTO tenants (slug, name, kind, plan, sales_owner)
|
||||
VALUES ($1, $2, $3::tenant_kind, $4, NULLIF($5, ''))
|
||||
`INSERT INTO tenants (slug, name, kind, plan, status, sales_owner, trial_ends_at)
|
||||
VALUES (
|
||||
$1, $2, $3::tenant_kind, $4,
|
||||
CASE WHEN $3::tenant_kind = 'demo' THEN 'demo'::tenant_status
|
||||
ELSE 'trial'::tenant_status END,
|
||||
NULLIF($5, ''),
|
||||
CASE WHEN $3::tenant_kind = 'demo' THEN NULL
|
||||
ELSE NOW() + INTERVAL '14 days' END
|
||||
)
|
||||
RETURNING id::text, slug, name, status::text, kind::text, plan,
|
||||
COALESCE(erp_customer_id,''), COALESCE(stripe_cust_id,''),
|
||||
trial_ends_at, contract_start, contract_end, COALESCE(sales_owner,''),
|
||||
|
||||
Reference in New Issue
Block a user