@@ -75,7 +75,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
7575
7676 var stripeWebhookHandler http.Handler = webhooks .NewNoopWebhookHandler ()
7777 if cfg .StripeWebhookSigningSecretPath != "" {
78- stripeWebhookSecret , err := readStripeWebhookSecret (cfg .StripeWebhookSigningSecretPath )
78+ stripeWebhookSecret , err := readSecretFromFile (cfg .StripeWebhookSigningSecretPath )
7979 if err != nil {
8080 return fmt .Errorf ("failed to read stripe secret: %w" , err )
8181 }
@@ -84,9 +84,21 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
8484 log .Info ("No stripe webhook secret is configured, endpoints will return NotImplemented" )
8585 }
8686
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+
8799 srv .HTTPMux ().Handle ("/stripe/invoices/webhook" , handlers .ContentTypeHandler (stripeWebhookHandler , "application/json" ))
88100
89- if registerErr := register (srv , connPool , expClient , dbConn ); registerErr != nil {
101+ if registerErr := register (srv , connPool , expClient , dbConn , signer ); registerErr != nil {
90102 return fmt .Errorf ("failed to register services: %w" , registerErr )
91103 }
92104
@@ -97,7 +109,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
97109 return nil
98110}
99111
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 {
101113 proxy .RegisterMetrics (srv .MetricsRegistry ())
102114
103115 connectMetrics := NewConnectMetrics ()
@@ -120,8 +132,10 @@ func register(srv *baseserver.Server, connPool proxy.ServerConnectionPool, expCl
120132 teamsRoute , teamsServiceHandler := v1connect .NewTeamsServiceHandler (apiv1 .NewTeamsService (connPool ), handlerOptions ... )
121133 srv .HTTPMux ().Handle (teamsRoute , teamsServiceHandler )
122134
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+ }
125139
126140 userRoute , userServiceHandler := v1connect .NewUserServiceHandler (apiv1 .NewUserService (connPool ), handlerOptions ... )
127141 srv .HTTPMux ().Handle (userRoute , userServiceHandler )
@@ -132,10 +146,10 @@ func register(srv *baseserver.Server, connPool proxy.ServerConnectionPool, expCl
132146 return nil
133147}
134148
135- func readStripeWebhookSecret (path string ) (string , error ) {
149+ func readSecretFromFile (path string ) (string , error ) {
136150 b , err := os .ReadFile (path )
137151 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 )
139153 }
140154
141155 return strings .TrimSpace (string (b )), nil
0 commit comments