@@ -10,7 +10,6 @@ import (
1010 "os/signal"
1111 "syscall"
1212 "the-dev-tools/backend/internal/api"
13- "the-dev-tools/backend/internal/api/auth"
1413 "the-dev-tools/backend/internal/api/middleware/mwauth"
1514 "the-dev-tools/backend/internal/api/middleware/mwcompress"
1615 "the-dev-tools/backend/internal/api/rbody"
@@ -65,15 +64,11 @@ import (
6564 "the-dev-tools/backend/pkg/service/sworkspacesusers"
6665 devtoolsdb "the-dev-tools/db"
6766 "the-dev-tools/db/pkg/sqlc/gen"
68- "the-dev-tools/db/pkg/tursoembedded"
6967 "the-dev-tools/db/pkg/tursolocal"
7068 "time"
7169
7270 "connectrpc.com/connect"
7371 "github.com/bufbuild/httplb"
74- "github.com/magiclabs/magic-admin-go"
75-
76- magiccl "github.com/magiclabs/magic-admin-go/client"
7772)
7873
7974func main () {
@@ -94,7 +89,6 @@ func main() {
9489 if hmacSecret == "" {
9590 log .Fatal (errors .New ("HMAC_SECRET env var is required" ))
9691 }
97- hmacSecretBytes := []byte (hmacSecret )
9892
9993 dbMode := os .Getenv ("DB_MODE" )
10094 if dbMode == "" {
@@ -106,12 +100,8 @@ func main() {
106100 var dbCloseFunc func ()
107101 var err error
108102 switch dbMode {
109- case devtoolsdb .EMBEDDED :
110- currentDB , dbCloseFunc , err = GetDBEmbedded ()
111103 case devtoolsdb .LOCAL :
112104 currentDB , dbCloseFunc , err = GetDBLocal (ctx )
113- case devtoolsdb .REMOTE :
114- err = errors .New ("remote db mode is not supported" )
115105 default :
116106 err = errors .New ("invalid db mode" )
117107 }
@@ -170,79 +160,29 @@ func main() {
170160 var optionsCompress , optionsAuth , opitonsAll []connect.HandlerOption
171161 optionsCompress = append (optionsCompress , connect .WithCompression ("zstd" , mwcompress .NewDecompress , mwcompress .NewCompress ))
172162 optionsCompress = append (optionsCompress , connect .WithCompression ("gzip" , nil , nil ))
173- if dbMode != devtoolsdb .LOCAL {
174- // optionsAuth = append(optionsCompress, connect.WithInterceptors(mwauth.NewAuthInterceptor(hmacSecretBytes)))
175- optionsAuth = append (optionsCompress , connect .WithInterceptors (mwauth .NewAuthInterceptor ()))
176- } else {
177- _ , err := us .GetUser (ctx , mwauth .LocalDummyID )
178- if err != nil {
179- if errors .Is (err , suser .ErrUserNotFound ) {
180- defaultUser := & muser.User {
181- ID : mwauth .LocalDummyID ,
182- }
183- err = us .CreateUser (ctx , defaultUser )
184- if err != nil {
185- log .Fatal (err )
186- }
187- } else {
163+ _ , err = us .GetUser (ctx , mwauth .LocalDummyID )
164+ if err != nil {
165+ if errors .Is (err , suser .ErrUserNotFound ) {
166+ defaultUser := & muser.User {
167+ ID : mwauth .LocalDummyID ,
168+ }
169+ err = us .CreateUser (ctx , defaultUser )
170+ if err != nil {
188171 log .Fatal (err )
189172 }
173+ } else {
174+ log .Fatal (err )
190175 }
191-
192- optionsAuth = append (optionsCompress , connect .WithInterceptors (mwauth .NewAuthInterceptor ()))
193176 }
177+
178+ optionsAuth = append (optionsAuth , connect .WithInterceptors (mwauth .NewAuthInterceptor ()))
194179 opitonsAll = append (optionsAuth , optionsCompress ... )
195180
196181 // Services Connect RPC
197- newServiceManager := NewServiceManager (20 )
198-
199- if dbMode != devtoolsdb .LOCAL {
200- // Email
201- AWS_ACCESS_KEY := os .Getenv ("AWS_ACCESS_KEY" )
202- if AWS_ACCESS_KEY == "" {
203- log .Fatalf ("AWS_ACCESS_KEY is empty" )
204- }
205- AWS_SECRET_KEY := os .Getenv ("AWS_SECRET_KEY" )
206- if AWS_SECRET_KEY == "" {
207- log .Fatalf ("AWS_SECRET_KEY is empty" )
208- }
182+ newServiceManager := NewServiceManager (30 )
209183
210- // TODO: @Ege move to private repo
211- // emailClient, err := sesv2.NewClient(AWS_ACCESS_KEY, AWS_SECRET_KEY, "")
212- // if err != nil {
213- // log.Fatalf("failed to create email client: %v", err)
214- // }
215-
216- // path := os.Getenv("EMAIL_INVITE_TEMPLATE_PATH")
217- // if path == "" {
218- // log.Fatalf("EMAIL_INVITE_TEMPLATE_PATH is empty")
219- // }
220- // emailInviteManager, err := emailinvite.NewEmailTemplateFile(path, emailClient)
221- // if err != nil {
222- // log.Fatalf("failed to create email invite manager: %v", err)
223- // }
224- // Workspace Service
225- workspaceSrv := rworkspace .New (currentDB , ws , wus , us , es )
226- newServiceManager .AddService (rworkspace .CreateService (workspaceSrv , opitonsAll ))
227- } else {
228- workspaceSrv := rworkspace .New (currentDB , ws , wus , us , es )
229- newServiceManager .AddService (rworkspace .CreateService (workspaceSrv , opitonsAll ))
230- }
231- // Auth Service
232- if dbMode != devtoolsdb .LOCAL {
233- magicLinkSecret := os .Getenv ("MAGIC_LINK_SECRET" )
234- if magicLinkSecret == "" {
235- log .Fatal ("MAGIC_LINK_SECRET env var is required" )
236- }
237-
238- cl := magic .NewClientWithRetry (5 , time .Second , 10 * time .Second )
239- MagicLinkClient , err := magiccl .New (magicLinkSecret , cl )
240- if err != nil {
241- log .Fatal (err )
242- }
243- authSrv := auth .New (* MagicLinkClient , us , ws , wus , hmacSecretBytes )
244- newServiceManager .AddService (auth .CreateService (authSrv , optionsCompress ))
245- }
184+ workspaceSrv := rworkspace .New (currentDB , ws , wus , us , es )
185+ newServiceManager .AddService (rworkspace .CreateService (workspaceSrv , opitonsAll ))
246186
247187 // Collection Service
248188 collectionSrv := rcollection .New (currentDB , cs , ws ,
@@ -367,36 +307,6 @@ func (sm *ServiceManager) GetServices() []api.Service {
367307 return sm .s
368308}
369309
370- func GetDBEmbedded () (* sql.DB , func (), error ) {
371- dbName := os .Getenv ("DB_NAME" )
372- if dbName == "" {
373- return nil , nil , errors .New ("DB_NAME env var is required" )
374- }
375- dbToken := os .Getenv ("DB_TOKEN" )
376- if dbToken == "" {
377- return nil , nil , errors .New ("DB_TOKEN env var is required" )
378- }
379- dbUsername := os .Getenv ("DB_USERNAME" )
380- if dbUsername == "" {
381- return nil , nil , errors .New ("DB_USERNAME env var is required" )
382- }
383- dbVolumePath := os .Getenv ("DB_VOLUME_PATH" )
384- if dbVolumePath == "" {
385- return nil , nil , errors .New ("DB_VOLUME_PATH env var is required" )
386- }
387-
388- encryptKey := os .Getenv ("DB_ENCRYPTION_KEY" )
389- if encryptKey == "" {
390- return nil , nil , errors .New ("DB_ENCRYPT_KEY env var is required" )
391- }
392-
393- db , a , err := tursoembedded .NewTursoEmbeded (dbName , dbUsername , dbToken , dbVolumePath , encryptKey )
394- if err != nil {
395- return nil , nil , err
396- }
397- return db , a , nil
398- }
399-
400310func GetDBLocal (ctx context.Context ) (* sql.DB , func (), error ) {
401311 dbName := os .Getenv ("DB_NAME" )
402312 if dbName == "" {
0 commit comments