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 <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-06-08 19:57:39 +02:00
parent e51382ce70
commit c6c35a542e
4 changed files with 12 additions and 73 deletions

View File

@@ -1,63 +0,0 @@
// Copyright (c) 2026 Probo Inc <hello@probo.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 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)
}

View File

@@ -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,

View File

@@ -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"),

View File

@@ -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
}