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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user