How to access Kudu in Azure using power shell script

前端 未结 3 599
执念已碎
执念已碎 2020-12-04 03:51

I am trying to access Kudu through power shell script. Link looks like: https://adc-dev.scm.azurewebsites.net. I need to copy war file located in <

3条回答
  •  长情又很酷
    2020-12-04 04:42

    To access Kudu API, get your WebApp:

    $app = Get-AzWebApp -ResourceGroupName "your RG" -Name "your App"
    

    Then get publishing credentials for the app:

    $resourceName = "$($app.Name)/publishingcredentials";
    $resourceType = "Microsoft.Web/sites/config";
    $publishingCredentials = Invoke-AzResourceAction `
            -ResourceGroupName $app.ResourceGroup `
            -ResourceType $resourceType `
            -ResourceName $resourceName `
            -Action list `
            -ApiVersion $apiVersion `
            -Force;
    

    Format the username/password suitable for a HTTP-request:

    $user = $publishingCredentials.Properties.PublishingUserName;
    $pass = $publishingCredentials.Properties.PublishingPassword;
    $creds = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("${user}:${pass}")));
    

    Finally, you can access the Kudu API:

    $header = @{
        Authorization = "Basic $creds"
    };
    $kuduApiBaseUrl = "https://$($app.Name).scm.azurewebsites.net";
    

    Example, check if extension is installed:

    $extensionName = "Microsoft.AspNetCore.AzureAppServices.SiteExtension";
    $kuduApiUrl = "$kuduApiBaseUrl/api/siteextensions/$extensionName";
    $response = Invoke-RestMethod -Method 'Get' -Uri $kuduApiUrl -Headers $header;
    

    Example, get list of available extensions:

    $kuduApiUrl = "$kuduApiBaseUrl/api/extensionfeed";
    $response = Invoke-RestMethod -Method 'Get' -Uri $kuduApiUrl -Headers $header;
    

    Example, install an extension:

    $kuduApiUrl = "$kuduApiBaseUrl/api/siteextensions";
    $response = Invoke-RestMethod -Method 'Put' -Uri $kuduApiUrl -Headers $header;
    

    API-details are at https://github.com/projectkudu/kudu/wiki/REST-API

    Also deployment slots can be accessed. App config needs to be retrieved for the slot and a minor modification of the base URL is needed.

提交回复
热议问题