Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mkt 6648 #220

Merged
merged 10 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened]
jobs:
security:
security-jira:
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/sast-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: SAST Scan
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security-sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Semgrep Scan
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto
4 changes: 2 additions & 2 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security:
security-sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand All @@ -12,4 +12,4 @@ jobs:
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --all-projects --fail-on=all --strict-out-of-sync=false
args: --all-projects --fail-on=all
62 changes: 41 additions & 21 deletions src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,18 @@ const getPagedData = async (
return aggregatedResponse;
};

const getSyncData = async (
exports.getSyncData = async (
url,
config,
query,
responseKey,
aggregatedResponse = null
aggregatedResponse = null,
retries = 0
) => {
try {
const response = await fetchCsData(url, config, query);

/*
/*
Below syncToken array would contain type --> 'asset_published', 'entry_published' sync tokens
*/
if (
Expand All @@ -260,34 +262,52 @@ const getSyncData = async (
? response.sync_token
: aggregatedResponse.sync_token;
}
if (response.pagination_token) {
return getSyncData(
url,
config,
(query = { pagination_token: response.pagination_token }),
responseKey,
aggregatedResponse
);
}
if (response.pagination_token) {
try {
return await getSyncData(
url,
config,
{ pagination_token: response.pagination_token },
responseKey,
aggregatedResponse,
0 // Reset retries for each call
);
} catch (error) {
if (retries < config.httpRetries) {
const timeToWait = 2 ** retries * 100;
console.log(`Retry attempt ${retries + 1} after pagination token error. Waiting for ${timeToWait} ms...`);
await waitFor(timeToWait);
return await getSyncData(
url,
config,
{ pagination_token: response.pagination_token },
responseKey,
aggregatedResponse,
retries + 1
);
} else {
throw new Error(`Failed to fetch sync data after ${config.httpRetries} retry attempts due to invalid pagination token.`);
}
}
}

if (response.sync_token) {
/**
* To make final sync call and concatenate the result if found any during on fetch request.
*/
if (response.sync_token) {
const aggregatedSyncToken = syncToken.filter(item => item !== undefined);
for (const token of aggregatedSyncToken) {
const syncResponse = await fetchCsData(
url,
config,
(query = { sync_token: token })
);
aggregatedResponse.data = aggregatedResponse.data?.concat(
...syncResponse.items
{ sync_token: token }
);
aggregatedResponse.data = aggregatedResponse.data.concat(syncResponse.items);
aggregatedResponse.sync_token = syncResponse.sync_token;
}
}

syncToken = []
syncToken = [];
return aggregatedResponse;
} catch (error) {
throw new Error(`Failed to fetch sync data: ${error.message}`);
}
};

Loading