Add file visibility (PRIVATE/PUBLIC) + public files API

Adds a visibility enum to files with PRIVATE (default) and PUBLIC states.
PUBLIC files are accessible via an unauthenticated /api/files/v1/{fileID}
endpoint that redirects to a presigned S3 URL. Introduces pkg/file service
to manage file operations. Logo uploads (trust centers, organizations,
frameworks, references) are marked PUBLIC; other files are PRIVATE.
Includes database migration and backfill for existing logos.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-18 17:28:10 +01:00
parent 9237ad8ce2
commit a5743729f7
20 changed files with 339 additions and 10 deletions

View File

@@ -29,9 +29,11 @@ import (
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/mailman"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/file"
"go.probo.inc/probo/pkg/securecookie"
connect_v1 "go.probo.inc/probo/pkg/server/api/connect/v1"
console_v1 "go.probo.inc/probo/pkg/server/api/console/v1"
files_v1 "go.probo.inc/probo/pkg/server/api/files/v1"
mcp_v1 "go.probo.inc/probo/pkg/server/api/mcp/v1"
slack_v1 "go.probo.inc/probo/pkg/server/api/slack/v1"
trust_v1 "go.probo.inc/probo/pkg/server/api/trust/v1"
@@ -44,6 +46,7 @@ type (
BaseURL *baseurl.BaseURL
AllowedOrigins []string
Probo *probo.Service
File *file.Service
IAM *iam.Service
Trust *trust.Service
ESign *esign.Service
@@ -66,6 +69,7 @@ type (
cfg Config
compliancePageHandler http.Handler
consoleHandler http.Handler
filesHandler http.Handler
mcpHandler http.Handler
slackHandler http.Handler
connectHandler http.Handler
@@ -139,6 +143,10 @@ func NewServer(cfg Config) (*Server, error) {
cfg.BaseURL,
cfg.CustomDomainCname,
),
filesHandler: files_v1.NewMux(
cfg.Logger.Named("files.v1"),
cfg.File,
),
mcpHandler: mcp_v1.NewMux(
cfg.Logger.Named("mcp.v1"),
cfg.Probo,
@@ -191,6 +199,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
router.Mount("/console/v1", http.StripPrefix("/console/v1", s.consoleHandler))
router.Mount("/connect/v1", http.StripPrefix("/connect/v1", s.connectHandler))
router.Mount("/files/v1", http.StripPrefix("/files/v1", s.filesHandler))
router.Mount("/trust/v1", http.StripPrefix("/trust/v1", s.compliancePageHandler))
router.Mount("/mcp/v1", http.StripPrefix("/mcp/v1", s.mcpHandler))
router.Mount("/slack/v1", http.StripPrefix("/slack/v1", s.slackHandler))

View File

@@ -0,0 +1,76 @@
// Copyright (c) 2026 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 files_v1
import (
"errors"
"net/http"
"time"
"github.com/go-chi/chi/v5"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/file"
)
const presignedURLExpiry = 1 * time.Hour
type Handler struct {
logger *log.Logger
fileSvc *file.Service
}
func NewMux(logger *log.Logger, fileSvc *file.Service) *chi.Mux {
h := &Handler{
logger: logger,
fileSvc: fileSvc,
}
r := chi.NewRouter()
r.Get("/{fileID}", h.handleGetPublicFile)
return r
}
func (h *Handler) handleGetPublicFile(w http.ResponseWriter, r *http.Request) {
fileIDStr := chi.URLParam(r, "fileID")
fileID, err := gid.ParseGID(fileIDStr)
if err != nil {
http.NotFound(w, r)
return
}
presignedURL, err := h.fileSvc.GetPublicFileURL(r.Context(), fileID, presignedURLExpiry)
if err != nil {
if errors.Is(err, coredata.ErrResourceNotFound) {
http.NotFound(w, r)
return
}
h.logger.ErrorCtx(
r.Context(),
"cannot get public file URL",
log.Error(err),
log.String("file_id", fileIDStr),
)
http.Error(w, "internal server error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, presignedURL, http.StatusTemporaryRedirect)
}