@@ -75,7 +75,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
75
75
76
76
var stripeWebhookHandler http.Handler = webhooks .NewNoopWebhookHandler ()
77
77
if cfg .StripeWebhookSigningSecretPath != "" {
78
- stripeWebhookSecret , err := readStripeWebhookSecret (cfg .StripeWebhookSigningSecretPath )
78
+ stripeWebhookSecret , err := readSecretFromFile (cfg .StripeWebhookSigningSecretPath )
79
79
if err != nil {
80
80
return fmt .Errorf ("failed to read stripe secret: %w" , err )
81
81
}
@@ -84,9 +84,21 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
84
84
log .Info ("No stripe webhook secret is configured, endpoints will return NotImplemented" )
85
85
}
86
86
87
+ var signer auth.Signer
88
+ if cfg .PersonalAccessTokenSigningKeyPath != "" {
89
+ personalACcessTokenSigningKey , err := readSecretFromFile (cfg .PersonalAccessTokenSigningKeyPath )
90
+ if err != nil {
91
+ return fmt .Errorf ("failed to read personal access token signing key: %w" , err )
92
+ }
93
+
94
+ signer = auth .NewHS256Signer ([]byte (personalACcessTokenSigningKey ))
95
+ } else {
96
+ log .Info ("No Personal Access Token signign key specified, PersonalAccessToken service will be disabled." )
97
+ }
98
+
87
99
srv .HTTPMux ().Handle ("/stripe/invoices/webhook" , handlers .ContentTypeHandler (stripeWebhookHandler , "application/json" ))
88
100
89
- if registerErr := register (srv , connPool , expClient , dbConn ); registerErr != nil {
101
+ if registerErr := register (srv , connPool , expClient , dbConn , signer ); registerErr != nil {
90
102
return fmt .Errorf ("failed to register services: %w" , registerErr )
91
103
}
92
104
@@ -97,7 +109,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
97
109
return nil
98
110
}
99
111
100
- func register (srv * baseserver.Server , connPool proxy.ServerConnectionPool , expClient experiments.Client , dbConn * gorm.DB ) error {
112
+ func register (srv * baseserver.Server , connPool proxy.ServerConnectionPool , expClient experiments.Client , dbConn * gorm.DB , signer auth. Signer ) error {
101
113
proxy .RegisterMetrics (srv .MetricsRegistry ())
102
114
103
115
connectMetrics := NewConnectMetrics ()
@@ -120,8 +132,10 @@ func register(srv *baseserver.Server, connPool proxy.ServerConnectionPool, expCl
120
132
teamsRoute , teamsServiceHandler := v1connect .NewTeamsServiceHandler (apiv1 .NewTeamsService (connPool ), handlerOptions ... )
121
133
srv .HTTPMux ().Handle (teamsRoute , teamsServiceHandler )
122
134
123
- tokensRoute , tokensServiceHandler := v1connect .NewTokensServiceHandler (apiv1 .NewTokensService (connPool , expClient , dbConn ), handlerOptions ... )
124
- srv .HTTPMux ().Handle (tokensRoute , tokensServiceHandler )
135
+ if signer != nil {
136
+ tokensRoute , tokensServiceHandler := v1connect .NewTokensServiceHandler (apiv1 .NewTokensService (connPool , expClient , dbConn , signer ), handlerOptions ... )
137
+ srv .HTTPMux ().Handle (tokensRoute , tokensServiceHandler )
138
+ }
125
139
126
140
userRoute , userServiceHandler := v1connect .NewUserServiceHandler (apiv1 .NewUserService (connPool ), handlerOptions ... )
127
141
srv .HTTPMux ().Handle (userRoute , userServiceHandler )
@@ -132,10 +146,10 @@ func register(srv *baseserver.Server, connPool proxy.ServerConnectionPool, expCl
132
146
return nil
133
147
}
134
148
135
- func readStripeWebhookSecret (path string ) (string , error ) {
149
+ func readSecretFromFile (path string ) (string , error ) {
136
150
b , err := os .ReadFile (path )
137
151
if err != nil {
138
- return "" , fmt .Errorf ("failed to read stripe webhook secret : %w" , err )
152
+ return "" , fmt .Errorf ("failed to read secret from file : %w" , err )
139
153
}
140
154
141
155
return strings .TrimSpace (string (b )), nil
0 commit comments