mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-16 03:08:35 +00:00

# Which Problems Are Solved Actions v2 is not a feature flag anymore, include functionality on executions is not used and json tags of proto messages are handled incorrectly. # How the Problems Are Solved - Remove actions from the feature flags on system and instance level - Remove include type on executions, only in the API, later maybe in the handling logic as well - Use protojson in request and response handling of actions v2 # Additional Changes - Correct integration tests for request and response handling - Use json.RawMessage for events, so that the event payload is not base64 encoded - Added separate context for async webhook calls, that executions are not cancelled when called async # Additional Context Related to #9759 Closes #9710 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
92 lines
3.2 KiB
Go
92 lines
3.2 KiB
Go
package action
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/repository/execution"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v2beta"
|
|
)
|
|
|
|
func (s *Server) SetExecution(ctx context.Context, req *action.SetExecutionRequest) (*action.SetExecutionResponse, error) {
|
|
reqTargets := req.GetTargets()
|
|
targets := make([]*execution.Target, len(reqTargets))
|
|
for i, target := range reqTargets {
|
|
targets[i] = &execution.Target{Type: domain.ExecutionTargetTypeTarget, Target: target}
|
|
}
|
|
set := &command.SetExecution{
|
|
Targets: targets,
|
|
}
|
|
var err error
|
|
var details *domain.ObjectDetails
|
|
instanceID := authz.GetInstance(ctx).InstanceID()
|
|
switch t := req.GetCondition().GetConditionType().(type) {
|
|
case *action.Condition_Request:
|
|
cond := executionConditionFromRequest(t.Request)
|
|
details, err = s.command.SetExecutionRequest(ctx, cond, set, instanceID)
|
|
case *action.Condition_Response:
|
|
cond := executionConditionFromResponse(t.Response)
|
|
details, err = s.command.SetExecutionResponse(ctx, cond, set, instanceID)
|
|
case *action.Condition_Event:
|
|
cond := executionConditionFromEvent(t.Event)
|
|
details, err = s.command.SetExecutionEvent(ctx, cond, set, instanceID)
|
|
case *action.Condition_Function:
|
|
details, err = s.command.SetExecutionFunction(ctx, command.ExecutionFunctionCondition(t.Function.GetName()), set, instanceID)
|
|
default:
|
|
err = zerrors.ThrowInvalidArgument(nil, "ACTION-5r5Ju", "Errors.Execution.ConditionInvalid")
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &action.SetExecutionResponse{
|
|
SetDate: timestamppb.New(details.EventDate),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListExecutionFunctions(ctx context.Context, _ *action.ListExecutionFunctionsRequest) (*action.ListExecutionFunctionsResponse, error) {
|
|
return &action.ListExecutionFunctionsResponse{
|
|
Functions: s.ListActionFunctions(),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListExecutionMethods(ctx context.Context, _ *action.ListExecutionMethodsRequest) (*action.ListExecutionMethodsResponse, error) {
|
|
return &action.ListExecutionMethodsResponse{
|
|
Methods: s.ListGRPCMethods(),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListExecutionServices(ctx context.Context, _ *action.ListExecutionServicesRequest) (*action.ListExecutionServicesResponse, error) {
|
|
return &action.ListExecutionServicesResponse{
|
|
Services: s.ListGRPCServices(),
|
|
}, nil
|
|
}
|
|
|
|
func executionConditionFromRequest(request *action.RequestExecution) *command.ExecutionAPICondition {
|
|
return &command.ExecutionAPICondition{
|
|
Method: request.GetMethod(),
|
|
Service: request.GetService(),
|
|
All: request.GetAll(),
|
|
}
|
|
}
|
|
|
|
func executionConditionFromResponse(response *action.ResponseExecution) *command.ExecutionAPICondition {
|
|
return &command.ExecutionAPICondition{
|
|
Method: response.GetMethod(),
|
|
Service: response.GetService(),
|
|
All: response.GetAll(),
|
|
}
|
|
}
|
|
|
|
func executionConditionFromEvent(event *action.EventExecution) *command.ExecutionEventCondition {
|
|
return &command.ExecutionEventCondition{
|
|
Event: event.GetEvent(),
|
|
Group: event.GetGroup(),
|
|
All: event.GetAll(),
|
|
}
|
|
}
|