Configure s3 client when probod start
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||||
"go.gearno.de/kit/migrator"
|
"go.gearno.de/kit/migrator"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
@@ -25,19 +26,27 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Service struct {
|
Service struct {
|
||||||
pg *pg.Client
|
pg *pg.Client
|
||||||
scope *coredata.Scope
|
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")
|
err := migrator.NewMigrator(pgClient, coredata.Migrations).Run(ctx, "migrations")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot migrate database schema: %w", err)
|
return nil, fmt.Errorf("cannot migrate database schema: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bucket == "" {
|
||||||
|
return nil, fmt.Errorf("bucket is required")
|
||||||
|
}
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
pg: pgClient,
|
pg: pgClient,
|
||||||
scope: coredata.NewScope(), // must be created from auth
|
s3: s3Client,
|
||||||
|
scope: coredata.NewScope(), // must be created from auth
|
||||||
|
bucket: bucket,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
25
pkg/probod/awsConfig.go
Normal file
25
pkg/probod/awsConfig.go
Normal 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"`
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -23,11 +23,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/getprobo/probo/pkg/api"
|
"github.com/getprobo/probo/pkg/api"
|
||||||
console_v1 "github.com/getprobo/probo/pkg/api/console/v1"
|
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/probo"
|
||||||
"github.com/getprobo/probo/pkg/usrmgr"
|
"github.com/getprobo/probo/pkg/usrmgr"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"go.gearno.de/kit/httpclient"
|
||||||
"go.gearno.de/kit/httpserver"
|
"go.gearno.de/kit/httpserver"
|
||||||
"go.gearno.de/kit/log"
|
"go.gearno.de/kit/log"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
@@ -44,6 +47,7 @@ type (
|
|||||||
Pg pgConfig `json:"pg"`
|
Pg pgConfig `json:"pg"`
|
||||||
Api apiConfig `json:"api"`
|
Api apiConfig `json:"api"`
|
||||||
Auth authConfig `json:"auth"`
|
Auth authConfig `json:"auth"`
|
||||||
|
AWS awsConfig `json:"aws"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,6 +81,13 @@ func New() *Implm {
|
|||||||
CookieDomain: "localhost",
|
CookieDomain: "localhost",
|
||||||
CookiePath: "/",
|
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)
|
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)
|
usrmgrService, err := usrmgr.NewService(ctx, pgClient, pepper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create usrmgr service: %w", err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create probo service: %w", err)
|
return fmt.Errorf("cannot create probo service: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user