-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-134761 Authenticated Preview/Publish API calls for restricted si…
…tes (#54) Moved the helix admin function out of utils to helixUtils. Updated preview/publish to pass the Authorization code, if the key is defined in config. Below config to be added to .env HELIX_ADMIN_API_KEYS={"cc": "<cc key>", "cc-pink": "<cc key>"} Checked for below, With Preview Enabled (on CC / CC-Pink) Non Protected Site (CC-Pink - No Key) - Preview passed Protected Site (CC) with valid Key - Preview passed Protected Site (CC) with Invalid/Missing Key - Preview failed and logged in xlsx Preview/Publish is disabled back till the bulk API is fixed. Co-authored-by: Raghu A <[email protected]>
- Loading branch information
1 parent
3817361
commit ddf8c2f
Showing
6 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* ************************************************************************ | ||
* ADOBE CONFIDENTIAL | ||
* ___________________ | ||
* | ||
* Copyright 2023 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
************************************************************************* */ | ||
|
||
const fetch = require('node-fetch'); | ||
const appConfig = require('./appConfig'); | ||
const urlInfo = require('./urlInfo'); | ||
|
||
const MAX_RETRIES = 5; | ||
|
||
class HelixUtils { | ||
async simulatePreviewPublish(path, operation, isFloodgate, retryAttempt = 1) { | ||
let previewStatus = { success: true, path }; | ||
try { | ||
const repo = isFloodgate ? `${urlInfo.getRepo()}-pink` : urlInfo.getRepo(); | ||
const previewUrl = `https://admin.hlx.page/${operation}/${urlInfo.getOwner()}/${repo}/${urlInfo.getBranch()}${path}`; | ||
const options = { method: 'POST' }; | ||
const { helixAdminApiKeys } = appConfig.getConfig(); | ||
if (helixAdminApiKeys && helixAdminApiKeys[repo]) { | ||
options.headers = new fetch.Headers(); | ||
options.headers.append('Authorization', `token ${helixAdminApiKeys[repo]}`); | ||
} | ||
const response = await fetch( | ||
`${previewUrl}`, | ||
options, | ||
); | ||
if (!response.ok && retryAttempt <= MAX_RETRIES) { | ||
previewStatus = await this.simulatePreviewPublish(path, operation, retryAttempt + 1, isFloodgate); | ||
} | ||
previewStatus.responseJson = await response.json(); | ||
} catch (error) { | ||
previewStatus.success = false; | ||
} | ||
return previewStatus; | ||
} | ||
} | ||
|
||
module.exports = new HelixUtils(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters