diff options
Diffstat (limited to 'cmd/stripe-preflight')
| -rw-r--r-- | cmd/stripe-preflight/main.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cmd/stripe-preflight/main.go b/cmd/stripe-preflight/main.go new file mode 100644 index 0000000..3a0f2d8 --- /dev/null +++ b/cmd/stripe-preflight/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "os" + "time" + + "aigw/internal/billing" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + result, err := billing.CheckStripePermissions(ctx, os.Getenv("AIGW_STRIPE_API_KEY")) + if encodeErr := json.NewEncoder(os.Stdout).Encode(result); encodeErr != nil { + fmt.Fprintln(os.Stderr, "encode Stripe preflight result") + os.Exit(1) + } + if err != nil { + if errors.Is(err, billing.ErrLiveStripeKey) { + fmt.Fprintln(os.Stderr, "Stripe preflight requires an rk_test_ or sk_test_ key; live keys are refused") + } else { + fmt.Fprintln(os.Stderr, "Stripe preflight failed") + } + os.Exit(1) + } + if !result.Ready { + fmt.Fprintln(os.Stderr, "Stripe restricted key is missing one or more required read permissions") + os.Exit(1) + } +} |
