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
- "os"
11
9
"strings"
12
10
13
11
"github.com/gitpod-io/gitpod/common-go/log"
@@ -19,27 +17,14 @@ type Client struct {
19
17
sc * client.API
20
18
}
21
19
22
- type stripeKeys struct {
20
+ type ClientConfig struct {
23
21
PublishableKey string `json:"publishableKey"`
24
22
SecretKey string `json:"secretKey"`
25
23
}
26
24
27
- // Authenticate authenticates the Stripe client using a provided file containing a Stripe secret key.
28
- func Authenticate (apiKeyFile string ) (* Client , error ) {
29
- bytes , err := os .ReadFile (apiKeyFile )
30
- if err != nil {
31
- return nil , err
32
- }
33
-
34
- var stripeKeys stripeKeys
35
- err = json .Unmarshal (bytes , & stripeKeys )
36
- if err != nil {
37
- return nil , err
38
- }
39
-
40
- sc := & client.API {}
41
- sc .Init (stripeKeys .SecretKey , nil )
42
- return & Client {sc : sc }, nil
25
+ // New authenticates a Stripe client using the provided config
26
+ func New (config ClientConfig ) (* Client , error ) {
27
+ return & Client {sc : client .New (config .SecretKey , nil )}, nil
43
28
}
44
29
45
30
// UpdateUsage updates teams' Stripe subscriptions with usage data
You can’t perform that action at this time.
0 commit comments