-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated backup/restore scripts. (#855)
- Loading branch information
Showing
21 changed files
with
991 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,7 @@ | ||
@REM Capture the content of an API Management portal into dest_folder - incl. pages, layouts, configuration, etc. but excluding media files | ||
|
||
set management_endpoint="< service name >.management.azure-api.net" | ||
set access_token="SharedAccessSignature ..." | ||
set dest_folder="../dist/snapshot" | ||
|
||
node ./capture %management_endpoint% %access_token% %dest_folder% |
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,55 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { request, downloadBlobs, getStorageSasTokenOrThrow } = require("./utils"); | ||
const managementApiEndpoint = process.argv[2]; | ||
const managementApiAccessToken = process.argv[3]; | ||
const destinationFolder = process.argv[4]; | ||
|
||
|
||
async function getContentTypes() { | ||
const data = await request("GET", `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes?api-version=2019-12-01`, managementApiAccessToken); | ||
const contentTypes = data.value.map(x => x.id.replace("\/contentTypes\/", "")); | ||
|
||
return contentTypes; | ||
} | ||
|
||
async function getContentItems(contentType) { | ||
const data = await request("GET", `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes/${contentType}/contentItems?api-version=2019-12-01`, managementApiAccessToken); | ||
const contentItems = data.value; | ||
|
||
return contentItems; | ||
} | ||
|
||
async function captureJson() { | ||
const result = {}; | ||
const contentTypes = await getContentTypes(); | ||
|
||
for (const contentType of contentTypes) { | ||
const contentItems = await getContentItems(contentType); | ||
|
||
contentItems.forEach(contentItem => { | ||
result[contentItem.id] = contentItem; | ||
delete contentItem.id; | ||
}); | ||
} | ||
|
||
await fs.promises.mkdir(path.resolve(destinationFolder), { recursive: true }); | ||
|
||
fs.writeFileSync(`${destinationFolder}/data.json`, JSON.stringify(result)); | ||
} | ||
|
||
async function capture() { | ||
const blobStorageUrl = await getStorageSasTokenOrThrow(managementApiEndpoint, managementApiAccessToken); | ||
const localMediaFolder = `./${destinationFolder}/media`; | ||
|
||
await captureJson(); | ||
await downloadBlobs(blobStorageUrl, localMediaFolder); | ||
} | ||
|
||
capture() | ||
.then(() => { | ||
console.log("DONE"); | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); |
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,6 @@ | ||
@REM Delete the content of an API Management portal - incl. pages, layouts, configuration, media files, etc. | ||
|
||
set management_endpoint="< service name >.management.azure-api.net" | ||
set access_token="SharedAccessSignature ..." | ||
|
||
node ./cleanup %management_endpoint% %access_token% |
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,45 @@ | ||
const { request, deleteBlobs, getStorageSasTokenOrThrow } = require("./utils"); | ||
const managementApiEndpoint = process.argv[2]; | ||
const managementApiAccessToken = process.argv[3]; | ||
|
||
|
||
async function getContentTypes() { | ||
const data = await request("GET", `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes?api-version=2019-12-01`, managementApiAccessToken); | ||
const contentTypes = data.value.map(x => x.id.replace("\/contentTypes\/", "")); | ||
|
||
return contentTypes; | ||
} | ||
|
||
async function getContentItems(contentType) { | ||
const data = await request("GET", `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes/${contentType}/contentItems?api-version=2019-12-01`, managementApiAccessToken); | ||
const contentItems = data.value; | ||
|
||
return contentItems; | ||
} | ||
|
||
async function deleteContent() { | ||
const contentTypes = await getContentTypes(); | ||
|
||
for (const contentType of contentTypes) { | ||
const contentItems = await getContentItems(contentType); | ||
|
||
for (const contentItem of contentItems) { | ||
await request("DELETE", `https://${managementApiEndpoint}//subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/${contentItem.id}?api-version=2019-12-01`, managementApiAccessToken); | ||
} | ||
} | ||
} | ||
|
||
async function cleanup() { | ||
const blobStorageUrl = await getStorageSasTokenOrThrow(managementApiEndpoint, managementApiAccessToken); | ||
|
||
await deleteContent(); | ||
await deleteBlobs(blobStorageUrl); | ||
} | ||
|
||
cleanup() | ||
.then(() => { | ||
console.log("DONE"); | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); |
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,61 @@ | ||
const fs = require('fs'), | ||
path = require('path'), | ||
configDesignFile = path.join(__dirname, '\\..\\src\\config.design.json'), | ||
configPublishFile = path.join(__dirname, '\\..\\src\\config.publish.json'), | ||
configRuntimeFile = path.join(__dirname, '\\..\\src\\config.runtime.json'); | ||
|
||
const managementEndpoint = process.argv[2]; | ||
const apimSasAccessTokenValue = process.argv[3]; | ||
const backendUrlValue = process.argv[4]; | ||
const apimServiceNameValue = process.argv[5]; | ||
const apimServiceUrlValue = `https://${managementEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/${apimServiceNameValue}`; | ||
|
||
const apimServiceParameter = "managementApiUrl"; | ||
const apimSasAccessTokenParameter = "managementApiAccessToken"; | ||
const backendUrlParameter = "backendUrl"; | ||
|
||
fs.readFile(configDesignFile, { encoding: 'utf-8' }, function (err, data) { | ||
if (!err) { | ||
const obj = JSON.parse(data); | ||
obj[apimServiceParameter] = apimServiceUrlValue; | ||
obj[apimSasAccessTokenParameter] = apimSasAccessTokenValue; | ||
obj[backendUrlParameter] = backendUrlValue; | ||
fs.writeFile(configDesignFile, JSON.stringify(obj, null, 4), function (errWrite) { | ||
if (errWrite) { | ||
return console.log(errWrite); | ||
} | ||
}); | ||
} else { | ||
console.log(err); | ||
} | ||
}); | ||
|
||
fs.readFile(configPublishFile, { encoding: 'utf-8' }, function (err, data) { | ||
if (!err) { | ||
const obj = JSON.parse(data); | ||
obj[apimServiceParameter] = apimServiceUrlValue; | ||
obj[apimSasAccessTokenParameter] = apimSasAccessTokenValue; | ||
fs.writeFile(configPublishFile, JSON.stringify(obj, null, 4), function (errWrite) { | ||
if (errWrite) { | ||
return console.log(errWrite); | ||
} | ||
}); | ||
} else { | ||
console.log(err); | ||
} | ||
}); | ||
|
||
fs.readFile(configRuntimeFile, { encoding: 'utf-8' }, function (err, data) { | ||
if (!err) { | ||
const obj = JSON.parse(data); | ||
obj[apimServiceParameter] = apimServiceUrlValue; | ||
obj[backendUrlParameter] = backendUrlValue; | ||
fs.writeFile(configRuntimeFile, JSON.stringify(obj, null, 4), function (errWrite) { | ||
if (errWrite) { | ||
return console.log(errWrite); | ||
} | ||
}); | ||
} else { | ||
console.log(err); | ||
} | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,25 @@ | ||
@REM Reprovision an existing API Management portal deployment - clean all the content, autogenerate new content, upload it, publish the portal, and host it | ||
|
||
cd .. | ||
call npm install | ||
cd scripts | ||
|
||
set apimServiceName="<service-name>" | ||
set management_endpoint="<service-name>.management.azure-api.net/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx/providers/Microsoft.ApiManagement/service/<service-name>" | ||
set access_token="SharedAccessSignature integration&..." | ||
set portalUrl="https://portalstorage.../" | ||
set backendUrl="https://<service-name>.developer.azure-api.net" | ||
|
||
set source_folder="../dist/snapshot" | ||
|
||
node ./cleanup %management_endpoint% %access_token% | ||
node ./configure %management_endpoint% %access_token% %backendUrl% %apimServiceName% | ||
node ./generate %management_endpoint% %access_token% %source_folder% | ||
|
||
cd .. | ||
|
||
@REM Run the publishing step and upload the generated portal to a Storage Account for hosting | ||
|
||
call npm run publish | ||
call az storage blob upload-batch --source dist/website --destination $web --connection-string %storage_connection_string% | ||
explorer %portalUrl% |
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,7 @@ | ||
@REM Generate and provision default content of an API Management portal - incl. pages, layouts, configuration, media files, etc. | ||
|
||
set management_endpoint="< service name >.management.azure-api.net" | ||
set access_token="SharedAccessSignature ..." | ||
set source_folder="../dist/snapshot" | ||
|
||
node ./generate %management_endpoint% %access_token% %source_folder% |
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,36 @@ | ||
const fs = require("fs"); | ||
const { request, uploadBlobs, getStorageSasTokenOrThrow } = require("./utils"); | ||
const managementApiEndpoint = process.argv[2] | ||
const managementApiAccessToken = process.argv[3] | ||
const sourceFolder = process.argv[4]; | ||
|
||
|
||
async function generateJson() { | ||
const data = fs.readFileSync(`${sourceFolder}/data.json`); | ||
const dataObj = JSON.parse(data); | ||
const keys = Object.keys(dataObj); | ||
|
||
for (const key of keys) { | ||
await request( | ||
"PUT", | ||
`https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/${key}?api-version=2019-12-01`, | ||
managementApiAccessToken, | ||
JSON.stringify(dataObj[key])); | ||
} | ||
} | ||
|
||
async function generate() { | ||
const blobStorageUrl = await getStorageSasTokenOrThrow(managementApiEndpoint, managementApiAccessToken); | ||
const localMediaFolder = `./${sourceFolder}/media`; | ||
|
||
await generateJson(); | ||
await uploadBlobs(blobStorageUrl, localMediaFolder); | ||
} | ||
|
||
generate() | ||
.then(() => { | ||
console.log("DONE"); | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); |
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,8 @@ | ||
# Generate and provision default content of an API Management portal - incl. pages, layouts, configuration, media files, etc. | ||
|
||
export management_endpoint="< service name >.management.azure-api.net" | ||
export access_token="SharedAccessSignature ..." | ||
export source_folder="../dist/snapshot" | ||
|
||
# make sure to double quote the $access_token variable so it handles the space correctly | ||
node ./generate $management_endpoint "$access_token" $data_file |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.