Skip to content

Commit

Permalink
[Actions] Fix external service urls (elastic#85556)
Browse files Browse the repository at this point in the history
* Fix services urls

* Improve tests
  • Loading branch information
cnasikas authored Dec 10, 2020
1 parent b3706b1 commit dec668a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ describe('Jira service', () => {
beforeAll(() => {
service = createExternalService(
{
config: { apiUrl: 'https://siem-kibana.atlassian.net', projectKey: 'CK' },
// The trailing slash at the end of the url is intended.
// All API calls need to have the trailing slash removed.
config: { apiUrl: 'https://siem-kibana.atlassian.net/', projectKey: 'CK' },
secrets: { apiToken: 'token', email: '[email protected]' },
},
logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ export const createExternalService = (
throw Error(`[Action]${i18n.NAME}: Wrong configuration.`);
}

const incidentUrl = `${url}/${BASE_URL}/issue`;
const capabilitiesUrl = `${url}/${CAPABILITIES_URL}`;
const urlWithoutTrailingSlash = url.endsWith('/') ? url.slice(0, -1) : url;
const incidentUrl = `${urlWithoutTrailingSlash}/${BASE_URL}/issue`;
const capabilitiesUrl = `${urlWithoutTrailingSlash}/${CAPABILITIES_URL}`;
const commentUrl = `${incidentUrl}/{issueId}/comment`;
const getIssueTypesOldAPIURL = `${url}/${BASE_URL}/issue/createmeta?projectKeys=${projectKey}&expand=projects.issuetypes.fields`;
const getIssueTypeFieldsOldAPIURL = `${url}/${BASE_URL}/issue/createmeta?projectKeys=${projectKey}&issuetypeIds={issueTypeId}&expand=projects.issuetypes.fields`;
const getIssueTypesUrl = `${url}/${BASE_URL}/issue/createmeta/${projectKey}/issuetypes`;
const getIssueTypeFieldsUrl = `${url}/${BASE_URL}/issue/createmeta/${projectKey}/issuetypes/{issueTypeId}`;
const searchUrl = `${url}/${BASE_URL}/search`;
const getIssueTypesOldAPIURL = `${urlWithoutTrailingSlash}/${BASE_URL}/issue/createmeta?projectKeys=${projectKey}&expand=projects.issuetypes.fields`;
const getIssueTypeFieldsOldAPIURL = `${urlWithoutTrailingSlash}/${BASE_URL}/issue/createmeta?projectKeys=${projectKey}&issuetypeIds={issueTypeId}&expand=projects.issuetypes.fields`;
const getIssueTypesUrl = `${urlWithoutTrailingSlash}/${BASE_URL}/issue/createmeta/${projectKey}/issuetypes`;
const getIssueTypeFieldsUrl = `${urlWithoutTrailingSlash}/${BASE_URL}/issue/createmeta/${projectKey}/issuetypes/{issueTypeId}`;
const searchUrl = `${urlWithoutTrailingSlash}/${BASE_URL}/search`;

const axiosInstance = axios.create({
auth: { username: email, password: apiToken },
});

const getIncidentViewURL = (key: string) => {
return `${url}/${VIEW_INCIDENT_URL}/${key}`;
return `${urlWithoutTrailingSlash}/${VIEW_INCIDENT_URL}/${key}`;
};

const getCommentsURL = (issueId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ describe('IBM Resilient service', () => {
beforeAll(() => {
service = createExternalService(
{
config: { apiUrl: 'https://resilient.elastic.co', orgId: '201' },
// The trailing slash at the end of the url is intended.
// All API calls need to have the trailing slash removed.
config: { apiUrl: 'https://resilient.elastic.co/', orgId: '201' },
secrets: { apiKeyId: 'keyId', apiKeySecret: 'secret' },
},
logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe('ServiceNow service', () => {
beforeAll(() => {
service = createExternalService(
{
config: { apiUrl: 'https://dev102283.service-now.com' },
// The trailing slash at the end of the url is intended.
// All API calls need to have the trailing slash removed.
config: { apiUrl: 'https://dev102283.service-now.com/' },
secrets: { username: 'admin', password: 'admin' },
},
logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export const createExternalService = (
throw Error(`[Action]${i18n.NAME}: Wrong configuration.`);
}

const incidentUrl = `${url}/${INCIDENT_URL}`;
const fieldsUrl = `${url}/${SYS_DICTIONARY}?sysparm_query=name=task^internal_type=string&active=true&read_only=false&sysparm_fields=max_length,element,column_label`;
const urlWithoutTrailingSlash = url.endsWith('/') ? url.slice(0, -1) : url;
const incidentUrl = `${urlWithoutTrailingSlash}/${INCIDENT_URL}`;
const fieldsUrl = `${urlWithoutTrailingSlash}/${SYS_DICTIONARY}?sysparm_query=name=task^internal_type=string&active=true&read_only=false&sysparm_fields=max_length,element,column_label`;
const axiosInstance = axios.create({
auth: { username, password },
});

const getIncidentViewURL = (id: string) => {
return `${url}/${VIEW_INCIDENT_URL}${id}`;
return `${urlWithoutTrailingSlash}/${VIEW_INCIDENT_URL}${id}`;
};

const getIncident = async (id: string) => {
Expand Down

0 comments on commit dec668a

Please sign in to comment.