@@ -6,14 +6,17 @@ package server
6
6
7
7
import (
8
8
"fmt"
9
+ "net"
9
10
"net/http"
10
11
"net/url"
11
12
"os"
12
13
"strings"
13
14
14
15
"github.com/bufbuild/connect-go"
16
+ common_db "github.com/gitpod-io/gitpod/common-go/db"
15
17
"github.com/gitpod-io/gitpod/common-go/experiments"
16
18
"github.com/gitpod-io/gitpod/common-go/log"
19
+ "gorm.io/gorm"
17
20
18
21
"github.com/gitpod-io/gitpod/components/public-api/go/config"
19
22
"github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"
@@ -41,6 +44,16 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
41
44
return fmt .Errorf ("failed to setup connection pool: %w" , err )
42
45
}
43
46
47
+ dbConn , err := common_db .Connect (common_db.ConnectionParams {
48
+ User : os .Getenv ("DB_USERNAME" ),
49
+ Password : os .Getenv ("DB_PASSWORD" ),
50
+ Host : net .JoinHostPort (os .Getenv ("DB_HOST" ), os .Getenv ("DB_PORT" )),
51
+ Database : "gitpod" ,
52
+ })
53
+ if err != nil {
54
+ return fmt .Errorf ("failed to establish database connection: %w" , err )
55
+ }
56
+
44
57
expClient := experiments .NewClient ()
45
58
46
59
srv , err := baseserver .New ("public_api_server" ,
@@ -73,7 +86,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
73
86
74
87
srv .HTTPMux ().Handle ("/stripe/invoices/webhook" , handlers .ContentTypeHandler (stripeWebhookHandler , "application/json" ))
75
88
76
- if registerErr := register (srv , connPool , expClient ); registerErr != nil {
89
+ if registerErr := register (srv , connPool , expClient , dbConn ); registerErr != nil {
77
90
return fmt .Errorf ("failed to register services: %w" , registerErr )
78
91
}
79
92
@@ -84,7 +97,7 @@ func Start(logger *logrus.Entry, version string, cfg *config.Configuration) erro
84
97
return nil
85
98
}
86
99
87
- func register (srv * baseserver.Server , connPool proxy.ServerConnectionPool , expClient experiments.Client ) error {
100
+ func register (srv * baseserver.Server , connPool proxy.ServerConnectionPool , expClient experiments.Client , dbConn * gorm. DB ) error {
88
101
proxy .RegisterMetrics (srv .MetricsRegistry ())
89
102
90
103
connectMetrics := NewConnectMetrics ()
@@ -107,7 +120,7 @@ func register(srv *baseserver.Server, connPool proxy.ServerConnectionPool, expCl
107
120
teamsRoute , teamsServiceHandler := v1connect .NewTeamsServiceHandler (apiv1 .NewTeamsService (connPool ), handlerOptions ... )
108
121
srv .HTTPMux ().Handle (teamsRoute , teamsServiceHandler )
109
122
110
- tokensRoute , tokensServiceHandler := v1connect .NewTokensServiceHandler (apiv1 .NewTokensService (connPool , expClient ), handlerOptions ... )
123
+ tokensRoute , tokensServiceHandler := v1connect .NewTokensServiceHandler (apiv1 .NewTokensService (connPool , expClient , dbConn ), handlerOptions ... )
111
124
srv .HTTPMux ().Handle (tokensRoute , tokensServiceHandler )
112
125
113
126
userRoute , userServiceHandler := v1connect .NewUserServiceHandler (apiv1 .NewUserService (connPool ), handlerOptions ... )
0 commit comments