Как перенести управляемый Azure API Developer Portal (не устаревший) контент в новые экземпляры - PullRequest
0 голосов
/ 06 февраля 2020

Используя сценарии https://github.com/Azure/api-management-developer-portal/wiki/Migrate-portal-between-services, я смог получить все определения и развернуть их на новом экземпляре, проблема была в том, что был перенесен только устаревший портал, а нового портала нет. Как мы можем перенести новый портал для разработчиков? Я не смог найти какие-либо настройки или ссылки в сценариях или документации, я также попытался изменить версию сценариев API в настоящее время как 2018-06-01-preview, но это также не удалось.

1 Ответ

0 голосов
/ 06 февраля 2020

Выполнение сценариев на ма c не вернуло никаких результатов для вызовов, сделанных в API Azure (не для захвата. js, ни для генерации. js), пришлось сделать некоторые изменения в js файлах и создание. sh сценариев.

перенос. 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.

Пришлось изменить функцию запроса на захват. js и сгенерировать. js, оригинальный код использует строку для захвата полезной нагрузки, меняя ее на Buffer Array, решенный в моем случае. Вот новый запрос

перехват. 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();
    })
}

Генерирование. 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();
    })
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...