mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-16 12:58:00 +00:00
6dcdef0268
* fix: add action v2 execution to features * fix: add action v2 execution to features * fix: add action v2 execution to features * fix: update internal/command/instance_features_model.go Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> * fix: merge back main * fix: merge back main * fix: rename feature and service * fix: rename feature and service * fix: review changes * fix: review changes --------- Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
133 lines
4.2 KiB
Go
133 lines
4.2 KiB
Go
package action
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object/v2"
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v3alpha"
|
|
)
|
|
|
|
func (s *Server) ListExecutionFunctions(_ context.Context, _ *action.ListExecutionFunctionsRequest) (*action.ListExecutionFunctionsResponse, error) {
|
|
return &action.ListExecutionFunctionsResponse{
|
|
Functions: s.ListActionFunctions(),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListExecutionMethods(_ context.Context, _ *action.ListExecutionMethodsRequest) (*action.ListExecutionMethodsResponse, error) {
|
|
return &action.ListExecutionMethodsResponse{
|
|
Methods: s.ListGRPCMethods(),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListExecutionServices(_ context.Context, _ *action.ListExecutionServicesRequest) (*action.ListExecutionServicesResponse, error) {
|
|
return &action.ListExecutionServicesResponse{
|
|
Services: s.ListGRPCServices(),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetExecution(ctx context.Context, req *action.SetExecutionRequest) (*action.SetExecutionResponse, error) {
|
|
if err := checkExecutionEnabled(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
set := &command.SetExecution{
|
|
Targets: req.GetTargets(),
|
|
Includes: req.GetIncludes(),
|
|
}
|
|
|
|
var err error
|
|
var details *domain.ObjectDetails
|
|
switch t := req.GetCondition().GetConditionType().(type) {
|
|
case *action.Condition_Request:
|
|
cond := &command.ExecutionAPICondition{
|
|
Method: t.Request.GetMethod(),
|
|
Service: t.Request.GetService(),
|
|
All: t.Request.GetAll(),
|
|
}
|
|
details, err = s.command.SetExecutionRequest(ctx, cond, set, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Response:
|
|
cond := &command.ExecutionAPICondition{
|
|
Method: t.Response.GetMethod(),
|
|
Service: t.Response.GetService(),
|
|
All: t.Response.GetAll(),
|
|
}
|
|
details, err = s.command.SetExecutionResponse(ctx, cond, set, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Event:
|
|
cond := &command.ExecutionEventCondition{
|
|
Event: t.Event.GetEvent(),
|
|
Group: t.Event.GetGroup(),
|
|
All: t.Event.GetAll(),
|
|
}
|
|
details, err = s.command.SetExecutionEvent(ctx, cond, set, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Function:
|
|
details, err = s.command.SetExecutionFunction(ctx, command.ExecutionFunctionCondition(t.Function), set, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return &action.SetExecutionResponse{
|
|
Details: object.DomainToDetailsPb(details),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) DeleteExecution(ctx context.Context, req *action.DeleteExecutionRequest) (*action.DeleteExecutionResponse, error) {
|
|
if err := checkExecutionEnabled(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var err error
|
|
var details *domain.ObjectDetails
|
|
switch t := req.GetCondition().GetConditionType().(type) {
|
|
case *action.Condition_Request:
|
|
cond := &command.ExecutionAPICondition{
|
|
Method: t.Request.GetMethod(),
|
|
Service: t.Request.GetService(),
|
|
All: t.Request.GetAll(),
|
|
}
|
|
details, err = s.command.DeleteExecutionRequest(ctx, cond, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Response:
|
|
cond := &command.ExecutionAPICondition{
|
|
Method: t.Response.GetMethod(),
|
|
Service: t.Response.GetService(),
|
|
All: t.Response.GetAll(),
|
|
}
|
|
details, err = s.command.DeleteExecutionResponse(ctx, cond, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Event:
|
|
cond := &command.ExecutionEventCondition{
|
|
Event: t.Event.GetEvent(),
|
|
Group: t.Event.GetGroup(),
|
|
All: t.Event.GetAll(),
|
|
}
|
|
details, err = s.command.DeleteExecutionEvent(ctx, cond, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
case *action.Condition_Function:
|
|
details, err = s.command.DeleteExecutionFunction(ctx, command.ExecutionFunctionCondition(t.Function), authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return &action.DeleteExecutionResponse{
|
|
Details: object.DomainToDetailsPb(details),
|
|
}, nil
|
|
}
|