Resolve trust API nodes through resource aliases

Switch the trust center API to resolve aliased nodes via the
resourcealias service instead of the trust-center-specific alias
resolvers.

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-06-22 10:59:15 +02:00
parent 231f7d153e
commit 7f47b6efb7
5 changed files with 37 additions and 11 deletions

View File

@@ -45,10 +45,9 @@ func (r *queryResolver) Node(ctx context.Context, id string) (types.Node, error)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
scope := coredata.NewScopeFromObjectID(trustCenter.ID)
resourceID, err = r.trust.TrustCenterAliases.ResolveAlias(
resourceID, err = r.resourceAlias.ResolveAlias(
ctx,
scope,
trustCenter.OrganizationID,
id,
)
if err != nil {
@@ -56,7 +55,7 @@ func (r *queryResolver) Node(ctx context.Context, id string) (types.Node, error)
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
}
r.logger.ErrorCtx(ctx, "cannot resolve trust center alias", log.Error(err))
r.logger.ErrorCtx(ctx, "cannot resolve resource alias", log.Error(err))
return nil, gqlutils.Internal(ctx)
}

View File

@@ -23,6 +23,7 @@ import (
"go.probo.inc/probo/pkg/filemanager"
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/mailman"
"go.probo.inc/probo/pkg/resourcealias"
"go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
@@ -32,11 +33,23 @@ import (
"go.probo.inc/probo/pkg/trust"
)
func NewGraphQLHandler(iamSvc *iam.Service, trustSvc *trust.Service, fileManagerSvc *filemanager.Service, esignSvc *esign.Service, mailmanSvc *mailman.Service, logger *log.Logger, baseURL *baseurl.BaseURL, cookieConfig securecookie.Config, tokenSecret string) http.Handler {
func NewGraphQLHandler(
iamSvc *iam.Service,
trustSvc *trust.Service,
resourceAliasSvc *resourcealias.Service,
fileManagerSvc *filemanager.Service,
esignSvc *esign.Service,
mailmanSvc *mailman.Service,
logger *log.Logger,
baseURL *baseurl.BaseURL,
cookieConfig securecookie.Config,
tokenSecret string,
) http.Handler {
config := schema.Config{
Resolvers: &Resolver{
iam: iamSvc,
trust: trustSvc,
resourceAlias: resourceAliasSvc,
fileManager: fileManagerSvc,
esign: esignSvc,
mailman: mailmanSvc,

View File

@@ -42,6 +42,7 @@ import (
"go.probo.inc/probo/pkg/filemanager"
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/mailman"
"go.probo.inc/probo/pkg/resourcealias"
"go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/compliancepage"
@@ -62,6 +63,7 @@ type (
Resolver struct {
trust *trust.Service
resourceAlias *resourcealias.Service
fileManager *filemanager.Service
esign *esign.Service
mailman *mailman.Service
@@ -76,6 +78,7 @@ func NewMux(
logger *log.Logger,
iamSvc *iam.Service,
trustSvc *trust.Service,
resourceAliasSvc *resourcealias.Service,
fileManagerSvc *filemanager.Service,
esignSvc *esign.Service,
mailmanSvc *mailman.Service,
@@ -98,7 +101,18 @@ func NewMux(
)
r.Method(http.MethodGet, "/session-transfer", sessionTransferHandler)
graphqlHandler := NewGraphQLHandler(iamSvc, trustSvc, fileManagerSvc, esignSvc, mailmanSvc, logger, baseURL, cookieConfig, tokenSecret)
graphqlHandler := NewGraphQLHandler(
iamSvc,
trustSvc,
resourceAliasSvc,
fileManagerSvc,
esignSvc,
mailmanSvc,
logger,
baseURL,
cookieConfig,
tokenSecret,
)
r.Group(
func(r chi.Router) {

View File

@@ -24,16 +24,16 @@ import (
"go.probo.inc/probo/pkg/server/gqlutils"
)
func (r *Resolver) trustCenterAliasForStorageResource(
func (r *Resolver) resourceAliasForStorageResource(
ctx context.Context,
storageResourceID gid.GID,
) (*string, error) {
trustCenter := compliancepage.CompliancePageFromContext(ctx)
scope := coredata.NewScopeFromObjectID(trustCenter.ID)
alias, err := r.trust.TrustCenterAliases.GetByStorageResourceID(ctx, scope, storageResourceID)
alias, err := r.resourceAlias.GetByResourceID(ctx, scope, storageResourceID)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot load trust center alias", log.Error(err))
r.logger.ErrorCtx(ctx, "cannot load resource alias", log.Error(err))
return nil, gqlutils.Internal(ctx)
}

View File

@@ -71,7 +71,7 @@ func (r *auditResolver) ReportFile(ctx context.Context, obj *types.Audit) (*type
// Alias is the resolver for the alias field.
func (r *auditReportResolver) Alias(ctx context.Context, obj *types.AuditReport) (*string, error) {
return r.trustCenterAliasForStorageResource(ctx, obj.ID)
return r.resourceAliasForStorageResource(ctx, obj.ID)
}
// IsUserAuthorized is the resolver for the isUserAuthorized field.
@@ -176,7 +176,7 @@ func (r *complianceFrameworkResolver) Framework(ctx context.Context, obj *types.
// Alias is the resolver for the alias field.
func (r *documentResolver) Alias(ctx context.Context, obj *types.Document) (*string, error) {
return r.trustCenterAliasForStorageResource(ctx, obj.ID)
return r.resourceAliasForStorageResource(ctx, obj.ID)
}
// IsUserAuthorized is the resolver for the isUserAuthorized field.
@@ -920,7 +920,7 @@ func (r *trustCenterResolver) Updates(ctx context.Context, obj *types.TrustCente
// Alias is the resolver for the alias field.
func (r *trustCenterFileResolver) Alias(ctx context.Context, obj *types.TrustCenterFile) (*string, error) {
return r.trustCenterAliasForStorageResource(ctx, obj.ID)
return r.resourceAliasForStorageResource(ctx, obj.ID)
}
// IsUserAuthorized is the resolver for the isUserAuthorized field.