From c6c35a542e3dccd78fc7826eeb566aabadfd8bc4 Mon Sep 17 00:00:00 2001 From: Ludovic Vielle Date: Mon, 8 Jun 2026 19:57:39 +0200 Subject: [PATCH] Wire file.Service into api.Config, delete pkg/filesign Replace the FileSign field in api.Config and server.Config with File (*file.Service). Pass the new file.Service and other required deps to files_v1.NewMux. Remove the now-redundant filesign package. Update the favicon URL path to /api/files/v1/public/ in server.go. Signed-off-by: Ludovic Vielle --- pkg/filesign/service.go | 63 ----------------------------------------- pkg/probod/probod.go | 4 +-- pkg/server/api/api.go | 10 +++++-- pkg/server/server.go | 8 +++--- 4 files changed, 12 insertions(+), 73 deletions(-) delete mode 100644 pkg/filesign/service.go diff --git a/pkg/filesign/service.go b/pkg/filesign/service.go deleted file mode 100644 index d93b1c686..000000000 --- a/pkg/filesign/service.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2026 Probo Inc . -// -// 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 filesign - -import ( - "context" - "fmt" - "time" - - "go.gearno.de/kit/pg" - "go.probo.inc/probo/pkg/coredata" - "go.probo.inc/probo/pkg/filemanager" - "go.probo.inc/probo/pkg/gid" -) - -type Service struct { - pg *pg.Client - fileManager *filemanager.Service -} - -func NewService(pgClient *pg.Client, fileManager *filemanager.Service) *Service { - return &Service{ - pg: pgClient, - fileManager: fileManager, - } -} - -// GeneratePresignedFileURL returns a short-lived S3 presigned URL for a PUBLIC file. -// Prefer file.Service.GenerateFileURL in most cases — it returns a stable, cacheable -// application URL. Only use this when a direct S3 URL with a controlled TTL is required -// (e.g. the /api/files/v1 HTTP handler that issues the presign-on-redirect). -func (s *Service) GeneratePresignedFileURL( - ctx context.Context, - fileID gid.GID, - expiresIn time.Duration, -) (string, error) { - file := &coredata.File{} - - err := s.pg.WithConn(ctx, func(ctx context.Context, conn pg.Querier) error { - if err := file.LoadPublicByID(ctx, conn, fileID); err != nil { - return fmt.Errorf("cannot load public file: %w", err) - } - - return nil - }) - if err != nil { - return "", err - } - - return s.fileManager.GenerateFileUrl(ctx, file, expiresIn) -} diff --git a/pkg/probod/probod.go b/pkg/probod/probod.go index 2c4c9f9fc..54a59f394 100644 --- a/pkg/probod/probod.go +++ b/pkg/probod/probod.go @@ -59,7 +59,6 @@ import ( "go.probo.inc/probo/pkg/evidencedescriber" "go.probo.inc/probo/pkg/file" "go.probo.inc/probo/pkg/filemanager" - "go.probo.inc/probo/pkg/filesign" "go.probo.inc/probo/pkg/geoloc" "go.probo.inc/probo/pkg/html2pdf" "go.probo.inc/probo/pkg/iam" @@ -540,7 +539,6 @@ func (impl *Implm) Run( cookieBannerService := cookiebanner.NewService(pgClient, impl.cfg.Branding) fileService := file.NewService(pgClient, baseURL, fileManagerService) - filesignService := filesign.NewService(pgClient, fileManagerService) proboService, err := probo.NewService( ctx, @@ -606,7 +604,7 @@ func (impl *Implm) Run( AllowedOrigins: impl.cfg.Api.Cors.AllowedOrigins, ExtraHeaderFields: impl.cfg.Api.ExtraHeaderFields, Probo: proboService, - FileSign: filesignService, + File: fileService, IAM: iamService, Trust: trustService, ESign: esignService, diff --git a/pkg/server/api/api.go b/pkg/server/api/api.go index 188a7552c..db582b2d1 100644 --- a/pkg/server/api/api.go +++ b/pkg/server/api/api.go @@ -32,7 +32,7 @@ import ( "go.probo.inc/probo/pkg/connector/provider" "go.probo.inc/probo/pkg/cookiebanner" "go.probo.inc/probo/pkg/esign" - "go.probo.inc/probo/pkg/filesign" + "go.probo.inc/probo/pkg/file" "go.probo.inc/probo/pkg/geoloc" "go.probo.inc/probo/pkg/iam" "go.probo.inc/probo/pkg/mailman" @@ -56,7 +56,7 @@ type ( BaseURL *baseurl.BaseURL AllowedOrigins []string Probo *probo.Service - FileSign *filesign.Service + File *file.Service IAM *iam.Service Trust *trust.Service ESign *esign.Service @@ -210,7 +210,11 @@ func NewServer(cfg Config) (*Server, error) { ), filesHandler: files_v1.NewMux( cfg.Logger.Named("files.v1"), - cfg.FileSign, + cfg.File, + cfg.Probo, + cfg.IAM, + cfg.Cookie, + cfg.TokenSecret, ), mcpHandler: mcp_v1.NewMux( cfg.Logger.Named("mcp.v1"), diff --git a/pkg/server/server.go b/pkg/server/server.go index b547f38f4..45c5bb7b5 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -31,7 +31,7 @@ import ( "go.probo.inc/probo/pkg/connector/provider" "go.probo.inc/probo/pkg/cookiebanner" "go.probo.inc/probo/pkg/esign" - "go.probo.inc/probo/pkg/filesign" + "go.probo.inc/probo/pkg/file" "go.probo.inc/probo/pkg/geoloc" "go.probo.inc/probo/pkg/iam" "go.probo.inc/probo/pkg/iam/oauth2server" @@ -55,7 +55,7 @@ type Config struct { AllowedOrigins []string ExtraHeaderFields map[string]string Probo *probo.Service - FileSign *filesign.Service + File *file.Service IAM *iam.Service Trust *trust.Service ESign *esign.Service @@ -94,7 +94,7 @@ func NewServer(cfg Config) (*Server, error) { BaseURL: cfg.BaseURL, AllowedOrigins: cfg.AllowedOrigins, Probo: cfg.Probo, - FileSign: cfg.FileSign, + File: cfg.File, IAM: cfg.IAM, Trust: cfg.Trust, ESign: cfg.ESign, @@ -278,7 +278,7 @@ func compliancePageHeadData(baseURL *baseurl.BaseURL, trustService *trust.Servic } if tc.LogoFileID != nil { - faviconURL, err := baseURL.WithPath("/api/files/v1/" + tc.LogoFileID.String()).String() + faviconURL, err := baseURL.WithPath("/api/files/v1/public/" + tc.LogoFileID.String()).String() if err == nil { headData.FaviconURL = faviconURL }