MCPcopy
hub / github.com/daptin/daptin / CreateIntegrationOperationHandler

Function CreateIntegrationOperationHandler

server/integration_operation_handler.go:23–136  ·  view source on GitHub ↗
(cruds map[string]*resource.DbResource)

Source from the content-addressed store, hash-verified

21}
22
23func CreateIntegrationOperationHandler(cruds map[string]*resource.DbResource) func(*gin.Context) {
24 return func(c *gin.Context) {
25 providerName := c.Param("providerName")
26 operationName := integrationOperationNameParam(c)
27 log.Tracef("Integration operation request received provider=[%s] operation=[%s]", providerName, operationName)
28 if providerName == "" || operationName == "" {
29 log.Warnf("Integration operation request missing provider or operation provider=[%s] operation=[%s]", providerName, operationName)
30 c.AbortWithStatusJSON(http.StatusBadRequest, map[string]interface{}{
31 "error": "provider and operation are required",
32 })
33 return
34 }
35
36 var body integrationOperationRequest
37 if c.Request.Body != nil {
38 err := json.NewDecoder(c.Request.Body).Decode(&body)
39 if err != nil && !errors.Is(err, io.EOF) {
40 log.Warnf("Integration operation request body parse failed provider=[%s] operation=[%s]: %v", providerName, operationName, err)
41 c.AbortWithStatusJSON(http.StatusBadRequest, map[string]interface{}{
42 "error": err.Error(),
43 })
44 return
45 }
46 }
47 if body.Input == nil {
48 body.Input = make(map[string]interface{})
49 }
50 sanitizeProviderScopedIntegrationInput(body.Input)
51 if body.OAuthTokenID != nil {
52 body.Input["oauth_token_id"] = body.OAuthTokenID
53 }
54 if body.CredentialID != nil {
55 body.Input["credential_id"] = body.CredentialID
56 }
57 log.Debugf("Integration operation input prepared provider=[%s] operation=[%s] input_keys=%d oauth_token=%t credential=%t",
58 providerName, operationName, len(body.Input), body.OAuthTokenID != nil, body.CredentialID != nil)
59
60 user := c.Request.Context().Value("user")
61 sessionUser := sessionUserFromContextValue(user)
62 requestSessionUser := *sessionUser
63 body.Input["sessionUser"] = sessionUser
64 body.Input["requestSessionUser"] = &requestSessionUser
65 body.Input["httpRequest"] = c.Request
66 body.Input["httpRequestHeaders"] = map[string][]string(c.Request.Header)
67
68 worldCrud := cruds["world"]
69 if worldCrud == nil {
70 log.Errorf("Integration operation cannot execute provider=[%s] operation=[%s]: world resource is not available", providerName, operationName)
71 c.AbortWithStatusJSON(http.StatusInternalServerError, map[string]interface{}{
72 "error": "world resource is not available",
73 })
74 return
75 }
76
77 performer, ok := resource.GetActionHandler(worldCrud, providerName)
78 if !ok || performer == nil {
79 log.Warnf("Integration operation provider not found provider=[%s] operation=[%s]", providerName, operationName)
80 c.AbortWithStatusJSON(http.StatusNotFound, map[string]interface{}{

Callers 1

MainFunction · 0.85

Calls 9

GetActionHandlerFunction · 0.92
makeFunction · 0.85
ErrorMethod · 0.80
BeginxMethod · 0.65
ConnectionMethod · 0.65
DoActionMethod · 0.65

Tested by

no test coverage detected