File tree 2 files changed +22
-24
lines changed
2 files changed +22
-24
lines changed Original file line number Diff line number Diff line change 5
5
package cmd
6
6
7
7
import (
8
+ "encoding/json"
9
+ "net"
10
+ "os"
11
+ "time"
12
+
8
13
"github.com/gitpod-io/gitpod/common-go/baseserver"
9
14
"github.com/gitpod-io/gitpod/common-go/log"
10
15
"github.com/gitpod-io/gitpod/usage/pkg/controller"
11
16
"github.com/gitpod-io/gitpod/usage/pkg/db"
12
17
"github.com/gitpod-io/gitpod/usage/pkg/stripe"
13
18
"github.com/spf13/cobra"
14
- "net"
15
- "os"
16
- "time"
17
19
)
18
20
19
21
func init () {
@@ -47,9 +49,20 @@ func run() *cobra.Command {
47
49
var billingController controller.BillingController = & controller.NoOpBillingController {}
48
50
49
51
if apiKeyFile != "" {
50
- c , err := stripe .Authenticate (apiKeyFile )
52
+ bytes , err := os .ReadFile (apiKeyFile )
53
+ if err != nil {
54
+ log .WithError (err ).Fatal ("Failed to read Stripe API keys." )
55
+ }
56
+
57
+ var config stripe.ClientConfig
58
+ err = json .Unmarshal (bytes , & config )
59
+ if err != nil {
60
+ log .WithError (err ).Fatal ("Failed to unmarshal Stripe API keys." )
61
+ }
62
+
63
+ c , err := stripe .New (config )
51
64
if err != nil {
52
- log .WithError (err ).Fatal ("Failed to initialize stripe client." )
65
+ log .WithError (err ).Fatal ("Failed to initialize Stripe client." )
53
66
}
54
67
billingController = controller .NewStripeBillingController (c )
55
68
}
Original file line number Diff line number Diff line change 5
5
package stripe
6
6
7
7
import (
8
- "encoding/json"
9
8
"fmt"
10
9
"math"
11
- "os"
12
10
"strings"
13
11
14
12
"github.com/gitpod-io/gitpod/common-go/log"
@@ -20,27 +18,14 @@ type Client struct {
20
18
sc * client.API
21
19
}
22
20
23
- type stripeKeys struct {
21
+ type ClientConfig struct {
24
22
PublishableKey string `json:"publishableKey"`
25
23
SecretKey string `json:"secretKey"`
26
24
}
27
25
28
- // Authenticate authenticates the Stripe client using a provided file containing a Stripe secret key.
29
- func Authenticate (apiKeyFile string ) (* Client , error ) {
30
- bytes , err := os .ReadFile (apiKeyFile )
31
- if err != nil {
32
- return nil , err
33
- }
34
-
35
- var stripeKeys stripeKeys
36
- err = json .Unmarshal (bytes , & stripeKeys )
37
- if err != nil {
38
- return nil , err
39
- }
40
-
41
- sc := & client.API {}
42
- sc .Init (stripeKeys .SecretKey , nil )
43
- return & Client {sc : sc }, nil
26
+ // New authenticates a Stripe client using the provided config
27
+ func New (config ClientConfig ) (* Client , error ) {
28
+ return & Client {sc : client .New (config .SecretKey , nil )}, nil
44
29
}
45
30
46
31
// UpdateUsage updates teams' Stripe subscriptions with usage data
You can’t perform that action at this time.
0 commit comments