Replace trust center alias with resource alias in console API

Drop the setTrustCenterAlias and removeTrustCenterAlias mutations and
the alias field on Audit in favor of generic setResourceAlias and
removeResourceAlias mutations backed by the resourcealias service.

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-06-22 10:59:04 +02:00
parent 9b0a5745a0
commit 231f7d153e
11 changed files with 123 additions and 157 deletions

View File

@@ -0,0 +1,71 @@
package console_v1
// This file will be automatically regenerated based on the schema, any resolver
// implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.90
import (
"context"
"errors"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/resourcealias"
"go.probo.inc/probo/pkg/server/api/console/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
"go.probo.inc/probo/pkg/validator"
)
// SetResourceAlias is the resolver for the setResourceAlias field.
func (r *mutationResolver) SetResourceAlias(ctx context.Context, input types.SetResourceAliasInput) (*types.SetResourceAliasPayload, error) {
scope, err := r.authorize(ctx, input.ResourceID, resourcealias.ActionAliasSet)
if err != nil {
return nil, err
}
alias, err := r.resourceAlias.Create(
ctx,
scope,
resourcealias.CreateRequest{
ResourceID: input.ResourceID,
Alias: input.Alias,
},
)
if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
return nil, gqlutils.Conflict(ctx, err)
}
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
}
r.logger.ErrorCtx(ctx, "cannot set resource alias", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
return &types.SetResourceAliasPayload{
ResourceAlias: types.NewResourceAlias(input.ResourceID, alias),
}, nil
}
// RemoveResourceAlias is the resolver for the removeResourceAlias field.
func (r *mutationResolver) RemoveResourceAlias(ctx context.Context, input types.RemoveResourceAliasInput) (*types.RemoveResourceAliasPayload, error) {
scope, err := r.authorize(ctx, input.ResourceID, resourcealias.ActionAliasRemove)
if err != nil {
return nil, err
}
err = r.resourceAlias.Remove(ctx, scope, input.ResourceID)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot remove resource alias", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
return &types.RemoveResourceAliasPayload{
DeletedResourceID: input.ResourceID,
}, nil
}