fix(integrations): Use payload instead of re-reading closed Body

This commit is contained in:
Andreas Marschke 2024-05-02 06:57:04 +02:00
parent c762dcd21d
commit 27e9fb1aa2
7 changed files with 18 additions and 25 deletions

View File

@ -161,7 +161,7 @@ func ReceiveIntegration(w http.ResponseWriter, r *http.Request) {
continue
}
RunIntegration(integration, project, r)
RunIntegration(integration, project, r, payload)
}
w.WriteHeader(http.StatusNoContent)
@ -227,7 +227,7 @@ func MatchCompare(value interface{}, method db.IntegrationMatchMethodType, expec
}
}
func RunIntegration(integration db.Integration, project db.Project, r *http.Request) {
func RunIntegration(integration db.Integration, project db.Project, r *http.Request, payload []byte) {
log.Info(fmt.Sprintf("Running integration %d", integration.ID))
@ -241,9 +241,8 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
extractValues = append(extractValues, extractValuesForExtractor...)
var extractedResults = Extract(extractValues, r)
var extractedResults = Extract(extractValues, r, payload)
// XXX: LOG AN EVENT HERE
environmentJSONBytes, err := json.Marshal(extractedResults)
if err != nil {
log.Error(err)
@ -256,15 +255,9 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
ProjectID: integration.ProjectID,
Debug: true,
Environment: environmentJSONString,
Integration: true,
}
//var user db.User
//user, err = helpers.Store(r).GetUser(1)
//if err != nil {
// log.Error(err)
// return
//}
_, err = helpers.TaskPool(r).AddTask(taskDefinition, nil, integration.ProjectID)
if err != nil {
log.Error(err)
@ -272,7 +265,7 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
}
}
func Extract(extractValues []db.IntegrationExtractValue, r *http.Request) (result map[string]string) {
func Extract(extractValues []db.IntegrationExtractValue, r *http.Request, payload []byte) (result map[string]string) {
result = make(map[string]string)
for _, extractValue := range extractValues {
@ -280,19 +273,12 @@ func Extract(extractValues []db.IntegrationExtractValue, r *http.Request) (resul
case db.IntegrationExtractHeaderValue:
result[extractValue.Variable] = r.Header.Get(extractValue.Key)
case db.IntegrationExtractBodyValue:
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
return
}
var body = string(bodyBytes)
switch extractValue.BodyDataType {
case db.IntegrationBodyDataJSON:
result[extractValue.Variable] =
fmt.Sprintf("%v", gojsonq.New().JSONString(body).Find(extractValue.Key))
var extractedResult = fmt.Sprintf("%v", gojsonq.New().JSONString(string(payload)).Find(extractValue.Key))
result[extractValue.Variable] = extractedResult
case db.IntegrationBodyDataString:
result[extractValue.Variable] = body
result[extractValue.Variable] = string(payload)
}
}
}

View File

@ -66,6 +66,7 @@ func GetMigrations() []Migration {
{Version: "2.9.61"},
{Version: "2.9.62"},
{Version: "2.9.70"},
{Version: "2.9.71"},
}
}

View File

@ -20,6 +20,8 @@ type Task struct {
DryRun bool `db:"dry_run" json:"dry_run"`
Diff bool `db:"diff" json:"diff"`
Integration bool `db:"integration" json:"integration"`
// override variables
Playbook string `db:"playbook" json:"playbook"`
Environment string `db:"environment" json:"environment"`

View File

@ -0,0 +1 @@
alter table `task` add integration boolean not null default false;

View File

@ -23,10 +23,13 @@
<v-col>
<v-list two-line subheader class="pa-0">
<v-list-item class="pa-0">
<v-list-item-content>
<v-list-item-content v-if="!item.integration">
<v-list-item-title>{{ $t('author') }}</v-list-item-title>
<v-list-item-subtitle>{{ user.name || '-' }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-content v-if="item.integration">
<v-list-item-title>{{ $t('integration') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-col>

View File

@ -238,5 +238,5 @@ export default {
Run: 'Run',
CreateDemoProject: 'Create Demo Project',
LeaveProject: 'Leave Project',
integration: 'Integration',
};