fixed retries and added update functionality

This commit is contained in:
Philip Ellis
2024-01-23 14:49:19 -06:00
parent f1385a4419
commit 4fa9a9013f
2 changed files with 20 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ const fs = require('fs')
const pmConvert = require('./PostmanCovertions') const pmConvert = require('./PostmanCovertions')
const pmAPI = require('./postmanAPI') const pmAPI = require('./postmanAPI')
let publicRemoteCollectionId = '23836355-6224d51a-d924-4c39-a58f-6970735aac8e' let publicRemoteCollectionId = '23836355-6224d51a-d924-4c39-a58f-6970735aac8e'
let publicRemoteCollectionNonUId = '6224d51a-d924-4c39-a58f-6970735aac8e'
let localCollection = JSON.parse(fs.readFileSync(`C:\\git\\api-specs\\postman\\collections\\sailpoint-api-v3.json`).toString()) let localCollection = JSON.parse(fs.readFileSync(`C:\\git\\api-specs\\postman\\collections\\sailpoint-api-v3.json`).toString())
@@ -246,14 +247,18 @@ async function updateRequestsInFolder(item, folderId, remoteItem) {
let postmanRequestBody = buildRequestBody(items) let postmanRequestBody = buildRequestBody(items)
let remotePostmanBody = buildRequestBody(remoteRequest) let remotePostmanBody = buildRequestBody(remoteRequest)
if (checkIfDifferent(postmanRequestBody, remotePostmanBody)) { if (checkIfDifferent(postmanRequestBody, remotePostmanBody)) {
if (remoteRequest) {
console.log(`deleting request ${remoteRequest.name}`)
let newRequestDelete = await new pmAPI.Request(publicRemoteCollectionId).delete(remoteRequest.id)
console.log(`deleted request ${newRequestDelete.data.id}`)
}
postmanRequestBody = buildRequestBody(items) postmanRequestBody = buildRequestBody(items)
if (remoteRequest) {
console.log(`updating request ${remoteRequest.name}`)
postmanRequestBody.folder = folderId
postmanRequestBody.collection = publicRemoteCollectionNonUId
let newRequestDelete = await new pmAPI.Request(publicRemoteCollectionId).update(remoteRequest.id, postmanRequestBody)
console.log(`updated request ${newRequestDelete.data.id}`)
} else {
let newRequest = await new pmAPI.Request(publicRemoteCollectionId).create(postmanRequestBody, folderId) let newRequest = await new pmAPI.Request(publicRemoteCollectionId).create(postmanRequestBody, folderId)
console.log(`creating request ${newRequest.data.name}`) console.log(`creating request ${newRequest.data.name}`)
}
} else { } else {
console.log(`no changes to request ${remoteRequest.name}`) console.log(`no changes to request ${remoteRequest.name}`)
} }

View File

@@ -26,11 +26,13 @@ class Collection {
this.collectionId = collectionId this.collectionId = collectionId
this.apiKey = process.env.POSTMAN_API_KEY this.apiKey = process.env.POSTMAN_API_KEY
this.axios = axios.create({ this.axios = axios.create({
timeout: 1000 * 5, // 60 seconds timeout: 1000 * 10, // 60 seconds
headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey } headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey }
}) })
axiosRetry(this.axios, { axiosRetry(this.axios, {
retries: 10, retries: 10,
retryDelay: axiosRetry.exponentialDelay,
shouldResetTimeout: true,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
@@ -93,7 +95,8 @@ class Folder {
}) })
axiosRetry(this.axios, { axiosRetry(this.axios, {
retries: 10, retries: 10,
//retryDelay: axiosRetry.exponentialDelay, retryDelay: axiosRetry.exponentialDelay,
shouldResetTimeout: true,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
@@ -165,6 +168,7 @@ class Request {
axiosRetry(this.axios, { axiosRetry(this.axios, {
retries: 10, retries: 10,
retryDelay: axiosRetry.exponentialDelay, retryDelay: axiosRetry.exponentialDelay,
shouldResetTimeout: true,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)
@@ -241,7 +245,8 @@ class Response {
}) })
axiosRetry(this.axios, { axiosRetry(this.axios, {
retries: 10, retries: 10,
//retryDelay: axiosRetry.exponentialDelay, retryDelay: axiosRetry.exponentialDelay,
shouldResetTimeout: true,
retryCondition: (error) => { retryCondition: (error) => {
console.log('error, retrying') console.log('error, retrying')
return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error) return error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || axiosRetry.isNetworkOrIdempotentRequestError(error)