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) } }