Configure s3 client when probod start

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-28 14:13:07 +01:00
parent 521fc20766
commit 66b4761154
3 changed files with 69 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/getprobo/probo/pkg/probo/coredata"
"go.gearno.de/kit/migrator"
"go.gearno.de/kit/pg"
@@ -25,19 +26,27 @@ import (
type (
Service struct {
pg *pg.Client
scope *coredata.Scope
pg *pg.Client
scope *coredata.Scope
s3 *s3.Client
bucket string
}
)
func NewService(ctx context.Context, pgClient *pg.Client) (*Service, error) {
func NewService(ctx context.Context, pgClient *pg.Client, s3Client *s3.Client, bucket string) (*Service, error) {
err := migrator.NewMigrator(pgClient, coredata.Migrations).Run(ctx, "migrations")
if err != nil {
return nil, fmt.Errorf("cannot migrate database schema: %w", err)
}
if bucket == "" {
return nil, fmt.Errorf("bucket is required")
}
return &Service{
pg: pgClient,
scope: coredata.NewScope(), // must be created from auth
pg: pgClient,
s3: s3Client,
scope: coredata.NewScope(), // must be created from auth
bucket: bucket,
}, nil
}

25
pkg/probod/awsConfig.go Normal file
View File

@@ -0,0 +1,25 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package probod
type (
awsConfig struct {
Region string `json:"region"`
Bucket string `json:"bucket"`
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
Endpoint string `json:"endpoint"`
}
)

View File

@@ -23,11 +23,14 @@ import (
"sync"
"time"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/getprobo/probo/pkg/api"
console_v1 "github.com/getprobo/probo/pkg/api/console/v1"
"github.com/getprobo/probo/pkg/awsconfig"
"github.com/getprobo/probo/pkg/probo"
"github.com/getprobo/probo/pkg/usrmgr"
"github.com/prometheus/client_golang/prometheus"
"go.gearno.de/kit/httpclient"
"go.gearno.de/kit/httpserver"
"go.gearno.de/kit/log"
"go.gearno.de/kit/pg"
@@ -44,6 +47,7 @@ type (
Pg pgConfig `json:"pg"`
Api apiConfig `json:"api"`
Auth authConfig `json:"auth"`
AWS awsConfig `json:"aws"`
}
)
@@ -77,6 +81,13 @@ func New() *Implm {
CookieDomain: "localhost",
CookiePath: "/",
},
AWS: awsConfig{
Region: "us-east-1",
Bucket: "probod",
AccessKeyID: "probod",
SecretAccessKey: "thisisnotasecret",
Endpoint: "http://127.0.0.1:9000",
},
},
}
}
@@ -111,13 +122,30 @@ func (impl *Implm) Run(
return fmt.Errorf("cannot get pepper bytes: %w", err)
}
// Initialize the user management service with the pepper
awsConfig := awsconfig.NewConfig(
l,
httpclient.DefaultPooledClient(
httpclient.WithLogger(l),
httpclient.WithTracerProvider(tp),
httpclient.WithRegisterer(r),
),
awsconfig.Options{
Region: impl.cfg.AWS.Region,
AccessKeyID: impl.cfg.AWS.AccessKeyID,
SecretAccessKey: impl.cfg.AWS.SecretAccessKey,
Endpoint: impl.cfg.AWS.Endpoint,
},
)
s3Client := s3.NewFromConfig(awsConfig)
// TODO: merge usrmgr and probo service
usrmgrService, err := usrmgr.NewService(ctx, pgClient, pepper)
if err != nil {
return fmt.Errorf("cannot create usrmgr service: %w", err)
}
proboService, err := probo.NewService(ctx, pgClient)
proboService, err := probo.NewService(ctx, pgClient, s3Client, impl.cfg.AWS.Bucket)
if err != nil {
return fmt.Errorf("cannot create probo service: %w", err)
}