Skip to content

Commit

Permalink
[Response Ops][Connectors] Refactor Jira Connector to use latest API …
Browse files Browse the repository at this point in the history
…only (#197787)

## Summary

Jira Cloud and Datacenter work using the same API urls. In this PR we
remove the calls to the capabilities API which was being used to know
the API url we needed to hit

To test it:
- Create Jira Cloud and Datacenter connectors
- Test all use cases related to them

Related to #189017

## Research Work

**getCapabilities, createIncident and getIncident** are always the same,
therefore ignored for the rest of this document

- getCapabilities: `/rest/capabilities`
- createIncident: `/rest/api/2/issue`
- getIncident: `/rest/api/2/issue`

## API links

- Cloud:
https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#version
- DC: https://docs.atlassian.com/software/jira/docs/api/REST/9.17.0/

### Expected API urls based on the API links

- Get issue types

- Cloud: `GET /rest/api/2/issue/createmeta/{projectIdOrKey}/issuetypes`
  - DC:`GET /rest/api/2/issue/createmeta/{projectIdOrKey}/issuetypes`

- Get fields by issue type
- Cloud: `GET
/rest/api/2/issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}`
- DC:
`GET /rest/api/2/issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}`

### API we hit

- Get issue types

- Cloud `GET
/rest/api/2/issue/createmeta?projectKeys=ROC&expand=projects.issuetypes.fields`
(variable name we are using is `getIssueTypesOldAPIURL`)
- DC `GET /rest/api/2/issue/createmeta/RES/issuetypes` (variable name is
`getIssueTypesUrl`)

- Get fields by issue type
- Cloud `GET
/rest/api/2/issue/createmeta?projectKeys=ROC&issuetypeIds={issueTypeId}&expand=projects.issuetypes.fields`
(variable name is `getIssueTypeFieldsOldAPIURL`)
- DC `GET /rest/api/2/issue/createmeta/RES/issuetypes/{issueTypeId}`
(variable name is `getIssueTypeFieldsUrl`)

#### Analysed use cases to retrieve API urls we hit

- created a case with JIRA Cloud as Connector
- did a connector test with JIRA Cloud as connector
- created a case with JIRA DC as connector
- did a connector test with JIRA DC as connector

### Conclusions

- We are not using the right endpoints for Cloud, we should update them
to use the same endpoints.

---------

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: adcoelho <[email protected]>
Co-authored-by: Antonio <[email protected]>
Co-authored-by: Lisa Cawley <[email protected]>
  • Loading branch information
6 people authored Nov 7, 2024
1 parent 996104f commit 953d877
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 623 deletions.
4 changes: 2 additions & 2 deletions docs/management/connectors/action-types/jira.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Jira connector uses the https://developer.atlassian.com/cloud/jira/platform/
[[jira-compatibility]]
=== Compatibility

Jira on-premise deployments (Server and Data Center) are not supported.
Jira Cloud and Jira Data Center are supported. Jira on-premise deployments are not supported.

[float]
[[define-jira-ui]]
Expand All @@ -37,7 +37,7 @@ Name:: The name of the connector.
URL:: Jira instance URL.
Project key:: Jira project key.
Email:: The account email for HTTP Basic authentication.
API token:: Jira API authentication token for HTTP Basic authentication.
API token:: Jira API authentication token for HTTP Basic authentication. For Jira Data Center, this value should be the password associated with the email owner.

[float]
[[jira-action-configuration]]
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/actions/server/lib/axios_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,12 @@ describe('throwIfResponseIsNotValid', () => {
})
).not.toThrow();
});

test('it does NOT throw if HTTP status code is 204 even if the content type is not supported', () => {
expect(() =>
throwIfResponseIsNotValid({
res: { ...res, status: 204, headers: { ['content-type']: 'text/html' } },
})
).not.toThrow();
});
});
10 changes: 10 additions & 0 deletions x-pack/plugins/actions/server/lib/axios_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ export const throwIfResponseIsNotValid = ({
const requiredContentType = 'application/json';
const contentType = res.headers['content-type'] ?? 'undefined';
const data = res.data;
const statusCode = res.status;

/**
* Some external services may return a 204
* status code but with unsupported content type like text/html.
* To avoid throwing on valid requests we return.
*/
if (statusCode === 204) {
return;
}

/**
* Check that the content-type of the response is application/json.
Expand Down
Loading

0 comments on commit 953d877

Please sign in to comment.