blob: 3a0f2d83adabce1a4c7f7402065f71ff3a77a5af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}
}
|