使用脚本https://github.com/Azure/api-management-developer-portal/wiki/Migrate-portal-between-services,我能够检索所有定义并将其部署到新实例,问题是仅迁移了旧版Portal,而没有迁移新的Portal。我们如何迁移新的开发人员门户?我在脚本或文档中找不到任何设置或参考,我还尝试更改了目前作为2018-06-01-preview的api脚本的版本,但这也失败了。
在Mac上运行脚本不会返回对Azure API的调用的任何结果(不适用于capture.js,也不适用于generate.js),必须对js文件进行一些更改并创建.sh脚本。
migrate.sh
#!/usr/bin/env bash
#Migrate the content of an API Management portal from one service instance to another - incl. pages, layouts, configuration, media files, etc.
# BEGIN: provide all the required parameters. If your portal is self-hosted, use the storage account connection string from the config.design.json file. If your portal is managed, refer to the documentation for instructions on accessing its storage account connection string.
export source_management_endpoint="< source_service_name >.management.azure-api.net"
export source_access_token="SharedAccessSignature ..."
export source_storage_connection_string="DefaultEndpointsProtocol= ..."
export target_management_endpoint="< target_service_name >.management.azure-api.net"
export target_access_token="SharedAccessSignature..."
export target_storage_connection_string="DefaultEndpointsProtocol=..."
# END: provide all the required parameters.
export data_file="../dist/data.json"
export media_folder="../dist/content"
export media_container="content"
# Quotes are important in the parameters especially in the case of access_tokens, they have spaces in their values, that will throw off the js scripts.
# Capture the content of the source portal (excl. media)
node ./capture "$source_management_endpoint" "$source_access_token" "$data_file"
# Remove all the content of the target portal (incl. media)
node ./cleanup "$target_management_endpoint" "$target_access_token" "$target_storage_connection_string"
# Upload the content of the source portal (excl. media)
node ./generate "$target_management_endpoint" "$target_access_token" "$data_file"
# Download the media files from the source portal
mkdir "$media_folder"
az storage blob download-batch --source "$media_container" --destination "$media_folder" --connection-string "$source_storage_connection_string"
# Upload the media files to the target portal
az storage blob upload-batch --source "$media_folder" --destination "$media_container" --connection-string "$target_storage_connection_string"
#At this point your target API Management service should contain the same content of the portal as the source service. To make the portal of the target service available to visitors, you still need to publish it and, in case of a self-hosted version, host the generated files.
已经更改了capture.js和generate.js的请求功能,原始代码使用字符串来捕获有效负载,将其更改为缓冲区数组,在我的情况下已解决。这是新的请求
capture.js
async function request(url){
return new Promise((resolve,reject)=>{
const req = https.get(url,options, (res) =>{
let bodyChunks = [];
res.on('data', (chunk)=> {
bodyChunks.push(chunk);
}).on('end', ()=> {
let body = Buffer.concat(bodyChunks);
// console.log('BODY: ' + body);
try {
resolve(JSON.parse(body));
}
catch (e) {
reject(e);
}
})
})
req.on('error', (e)=> {
console.log('ERROR: ' + e.message);
reject(e);
})
req.end();
})
}
generate.js
async function request(url,body){
return new Promise((resolve,reject)=>{
const options = {
port: 443,
method: "PUT",
headers: {
"If-Match": "*",
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(body),
"Authorization": accessToken
}
};
const req = https.request(url,options, (res) =>{
let bodyChunks = [];
res.on('data', (chunk)=> {
bodyChunks.push(chunk);
}).on('end', ()=> {
let data = Buffer.concat(bodyChunks);
// console.log('DATA: ' + data);
try {
resolve(JSON.parse(data));
}
catch (e) {
console.log(url);
reject(e);
}
})
})
req.on('error', (e)=> {
console.log('ERROR: ' + e.message);
reject(e);
});
req.write(body);
req.end();
})
}