Skip to content

Commit

Permalink
To prevent 404 and 405 error (#29)
Browse files Browse the repository at this point in the history
* To prevent 404 and 405 error

* Test changing host name

* changing unexpected inputs

* Unit test parameter change

* change

* change

* test

* Update index.test.js

* error message

* Update index.test.js

* name change

* change

* revert the changes

* Update index.js

* Update index.js

* change
  • Loading branch information
NiraimathiGunalan authored Feb 7, 2024
1 parent bfe32ab commit 22196b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: 'Create or Update Discovered APIs'
description: 'Creates or updates the targeted api files'
inputs:
api-host:
api_host:
description: 'Domain name of the ApiConnect instance where discovered APIs will be sent'
required: true
api-key:
api_key:
description: 'APIC API key'
required: false
provider-org:
provider_org:
description: 'Name of ID of provider org to us'
required: true
api-files:
api_files:
description: 'One or more file names of the APIs to sync with apiconnect discovery repo'
required: true
api-folders:
api_folders:
description: 'One or more folder names containing APIs to sync with apiconnect discovery repo'
required: true
resync_check:
Expand Down
31 changes: 15 additions & 16 deletions discovery-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ let createOrUpdateApiInternal = async function(curlUrl, token, bodyContent, meth

let datasourceStateUpdate = async function(apihost, bodyContent, token, porg, dataSourceLocation) {
try {
await axios.patch(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources/${encodeURIComponent(dataSourceLocation)}`, bodyContent, {
dataSourceLocation = dataSourceLocation.replaceAll('/', '-');
await axios.patch(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources/${dataSourceLocation}`, bodyContent, {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
Expand All @@ -137,30 +138,28 @@ let checkAndRegisterDataSource = async function(apihost, token, porg, dataSource
// Use this function to perform the datasource registration. If the dataSource doesn't exist create it
let resp;
try {
resp = await axios.get(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources/${encodeURIComponent(dataSourceLocation)}`, {
dataSourceLocation = dataSourceLocation.replaceAll('/', '-');
resp = await axios.get(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources/${dataSourceLocation}`, {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
'Content-Type': 'application/json'

}
}).then(response => {
if (response.data.status === 404) {
const bodyContent = JSON.stringify({ title: dataSourceLocation, collector_type: COLLECTOR_TYPE });
resp = axios.post(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources`, bodyContent, {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
}
});
if (resp.status === 404) {
const bodyContent = JSON.stringify({ title: dataSourceLocation, collector_type: COLLECTOR_TYPE });
resp = await axios.post(`https://platform-api.${apihost}/discovery/orgs/${porg}/data-sources`, bodyContent, {
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json',
'Content-Type': 'application/json'

}
});
}
} catch (error) {
console.log(error);
return { status: 500, message: error };
}
return resp;

};

Expand Down
31 changes: 15 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit 22196b7

Please sign in to comment.