72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
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.94
|
|
|
|
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
|
|
}
|