Add resourcealias application service
Introduce a standalone resourcealias package with its own service, IAM policies, and OAuth2 scopes so alias management no longer lives inside the trust center services. Remove the trust-center-specific alias services from probo and trust, and wire the new service into probod, the server, and the API layer. Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
@@ -364,9 +364,9 @@ func (s *Service) fetchDocumentIDs(ctx context.Context, scope coredata.Scoper, o
|
||||
cursorKey = &ck
|
||||
}
|
||||
|
||||
aliases, err := s.TrustCenterAliases.LoadByResourceIDs(ctx, scope, resourceIDs)
|
||||
aliases, err := s.resourceAlias.LoadByResourceIDs(ctx, scope, resourceIDs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load trust center aliases: %w", err)
|
||||
return nil, fmt.Errorf("cannot load resource aliases: %w", err)
|
||||
}
|
||||
|
||||
paths := make([]string, 0, len(resourceIDs))
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"go.probo.inc/probo/pkg/html2pdf"
|
||||
"go.probo.inc/probo/pkg/iam"
|
||||
"go.probo.inc/probo/pkg/probo"
|
||||
"go.probo.inc/probo/pkg/resourcealias"
|
||||
"go.probo.inc/probo/pkg/slack"
|
||||
)
|
||||
|
||||
@@ -62,7 +63,7 @@ type (
|
||||
Reports *ReportService
|
||||
Organizations *OrganizationService
|
||||
ComplianceExternalURLs *ComplianceExternalURLService
|
||||
TrustCenterAliases *TrustCenterAliasService
|
||||
resourceAlias *resourcealias.Service
|
||||
}
|
||||
)
|
||||
|
||||
@@ -78,6 +79,7 @@ func NewService(
|
||||
fileManagerService *filemanager.Service,
|
||||
logger *log.Logger,
|
||||
slack *slack.Service,
|
||||
resourceAliasSvc *resourcealias.Service,
|
||||
) *Service {
|
||||
svc := &Service{
|
||||
pg: pgClient,
|
||||
@@ -91,6 +93,7 @@ func NewService(
|
||||
fileManager: fileManagerService,
|
||||
logger: logger,
|
||||
slack: slack,
|
||||
resourceAlias: resourceAliasSvc,
|
||||
}
|
||||
svc.TrustCenters = &TrustCenterService{svc: svc}
|
||||
svc.Documents = &DocumentService{svc: svc, html2pdfConverter: html2pdfConverter}
|
||||
@@ -104,7 +107,6 @@ func NewService(
|
||||
svc.Reports = &ReportService{svc: svc}
|
||||
svc.Organizations = &OrganizationService{svc: svc}
|
||||
svc.ComplianceExternalURLs = &ComplianceExternalURLService{svc: svc}
|
||||
svc.TrustCenterAliases = &TrustCenterAliasService{svc: svc}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
// Copyright (c) 2025-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 trust
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
)
|
||||
|
||||
type TrustCenterAliasService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
func (s TrustCenterAliasService) ResolveAlias(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
organizationID gid.GID,
|
||||
alias string,
|
||||
) (gid.GID, error) {
|
||||
record := &coredata.TrustCenterAlias{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
if err := record.LoadByAlias(ctx, conn, scope, organizationID, alias); err != nil {
|
||||
return fmt.Errorf("cannot load trust center alias: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return gid.Nil, err
|
||||
}
|
||||
|
||||
return record.ResourceID, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterAliasService) GetByStorageResourceID(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
storageResourceID gid.GID,
|
||||
) (*string, error) {
|
||||
record := &coredata.TrustCenterAlias{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
if err := record.LoadByResourceID(ctx, conn, scope, storageResourceID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center alias: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &record.Alias, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterAliasService) LoadByResourceIDs(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
resourceIDs []gid.GID,
|
||||
) (map[gid.GID]string, error) {
|
||||
if len(resourceIDs) == 0 {
|
||||
return map[gid.GID]string{}, nil
|
||||
}
|
||||
|
||||
var aliases coredata.TrustCenterAliases
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
if err := aliases.LoadByResourceIDs(ctx, conn, scope, resourceIDs); err != nil {
|
||||
return fmt.Errorf("cannot load trust center aliases: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[gid.GID]string, len(aliases))
|
||||
for _, alias := range aliases {
|
||||
result[alias.ResourceID] = alias.Alias
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user