mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
Merge pull request #1987 from andreas-marschke/fix-integration-json-parsing
fix(integrations): Use payload instead of re-reading closed Body
This commit is contained in:
commit
3e0f5a44f0
@ -161,7 +161,7 @@ func ReceiveIntegration(w http.ResponseWriter, r *http.Request) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
RunIntegration(integration, project, r)
|
RunIntegration(integration, project, r, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
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))
|
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...)
|
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)
|
environmentJSONBytes, err := json.Marshal(extractedResults)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -252,9 +251,10 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
|
|||||||
|
|
||||||
var environmentJSONString = string(environmentJSONBytes)
|
var environmentJSONString = string(environmentJSONBytes)
|
||||||
var taskDefinition = db.Task{
|
var taskDefinition = db.Task{
|
||||||
TemplateID: integration.TemplateID,
|
TemplateID: integration.TemplateID,
|
||||||
ProjectID: integration.ProjectID,
|
ProjectID: integration.ProjectID,
|
||||||
Environment: environmentJSONString,
|
Environment: environmentJSONString,
|
||||||
|
IntegrationID: &integration.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = helpers.TaskPool(r).AddTask(taskDefinition, nil, integration.ProjectID)
|
_, err = helpers.TaskPool(r).AddTask(taskDefinition, nil, integration.ProjectID)
|
||||||
@ -264,7 +264,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)
|
result = make(map[string]string)
|
||||||
|
|
||||||
for _, extractValue := range extractValues {
|
for _, extractValue := range extractValues {
|
||||||
@ -272,19 +272,12 @@ func Extract(extractValues []db.IntegrationExtractValue, r *http.Request) (resul
|
|||||||
case db.IntegrationExtractHeaderValue:
|
case db.IntegrationExtractHeaderValue:
|
||||||
result[extractValue.Variable] = r.Header.Get(extractValue.Key)
|
result[extractValue.Variable] = r.Header.Get(extractValue.Key)
|
||||||
case db.IntegrationExtractBodyValue:
|
case db.IntegrationExtractBodyValue:
|
||||||
bodyBytes, err := io.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var body = string(bodyBytes)
|
|
||||||
|
|
||||||
switch extractValue.BodyDataType {
|
switch extractValue.BodyDataType {
|
||||||
case db.IntegrationBodyDataJSON:
|
case db.IntegrationBodyDataJSON:
|
||||||
result[extractValue.Variable] =
|
var extractedResult = fmt.Sprintf("%v", gojsonq.New().JSONString(string(payload)).Find(extractValue.Key))
|
||||||
fmt.Sprintf("%v", gojsonq.New().JSONString(body).Find(extractValue.Key))
|
result[extractValue.Variable] = extractedResult
|
||||||
case db.IntegrationBodyDataString:
|
case db.IntegrationBodyDataString:
|
||||||
result[extractValue.Variable] = body
|
result[extractValue.Variable] = string(payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ func GetMigrations() []Migration {
|
|||||||
{Version: "2.9.61"},
|
{Version: "2.9.61"},
|
||||||
{Version: "2.9.62"},
|
{Version: "2.9.62"},
|
||||||
{Version: "2.9.70"},
|
{Version: "2.9.70"},
|
||||||
|
{Version: "2.9.97"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ type Task struct {
|
|||||||
DryRun bool `db:"dry_run" json:"dry_run"`
|
DryRun bool `db:"dry_run" json:"dry_run"`
|
||||||
Diff bool `db:"diff" json:"diff"`
|
Diff bool `db:"diff" json:"diff"`
|
||||||
|
|
||||||
|
IntegrationID *int `db:"integration_id" json:"integration_id"`
|
||||||
|
|
||||||
// override variables
|
// override variables
|
||||||
Playbook string `db:"playbook" json:"playbook"`
|
Playbook string `db:"playbook" json:"playbook"`
|
||||||
Environment string `db:"environment" json:"environment"`
|
Environment string `db:"environment" json:"environment"`
|
||||||
|
1
db/sql/migrations/v2.9.97.sql
Normal file
1
db/sql/migrations/v2.9.97.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
alter table `task` add `integration_id` int null references project__integration(`id`) on delete set null;
|
@ -23,10 +23,13 @@
|
|||||||
<v-col>
|
<v-col>
|
||||||
<v-list two-line subheader class="pa-0">
|
<v-list two-line subheader class="pa-0">
|
||||||
<v-list-item class="pa-0">
|
<v-list-item class="pa-0">
|
||||||
<v-list-item-content>
|
<v-list-item-content v-if="item.user_id != null">
|
||||||
<v-list-item-title>{{ $t('author') }}</v-list-item-title>
|
<v-list-item-title>{{ $t('author') }}</v-list-item-title>
|
||||||
<v-list-item-subtitle>{{ user.name || '-' }}</v-list-item-subtitle>
|
<v-list-item-subtitle>{{ user.name || '-' }}</v-list-item-subtitle>
|
||||||
</v-list-item-content>
|
</v-list-item-content>
|
||||||
|
<v-list-item-content v-else-if="item.integration_id != null">
|
||||||
|
<v-list-item-title>{{ $t('integration') }}</v-list-item-title>
|
||||||
|
</v-list-item-content>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
@ -238,5 +238,5 @@ export default {
|
|||||||
Run: 'Run',
|
Run: 'Run',
|
||||||
CreateDemoProject: 'Create Demo Project',
|
CreateDemoProject: 'Create Demo Project',
|
||||||
LeaveProject: 'Leave Project',
|
LeaveProject: 'Leave Project',
|
||||||
|
integration: 'Integration',
|
||||||
};
|
};
|
||||||
|
@ -185,7 +185,7 @@
|
|||||||
:tooltip="item.last_task.message"
|
:tooltip="item.last_task.message"
|
||||||
/>
|
/>
|
||||||
<div style="color: gray; font-size: 14px;">
|
<div style="color: gray; font-size: 14px;">
|
||||||
{{ $t('by', {user_name: item.last_task.user_name}) }}
|
{{ $t('by', {user_name: item.last_task.user_name }) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user