Luk*_*ett 9 rest powershell azure-web-sites kudu
我正在尝试使用PowerShell通过REST API将更新的内容文件放到Azure网站上.但是,在提供我的凭据时,Invoke-RestMethod -Credentials我返回了标准Azure登录页面的HTML.
如何从PowerShell中使用Kudu进行身份验证?谢谢.
Set*_*eth 15
您可以先通过Powershell获取网站,然后使用网站上的发布凭据来调用Kudu REST API.下面的例子将获得Kudu版本.
$website = Get-AzureWebsite -Name "WebsiteName"
$username = $website.PublishingUsername
$password = $website.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
$kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
Run Code Online (Sandbox Code Playgroud)
在新的ARM世界和最新的PowerShell中,您需要对@ Seth的答案进行一些调整.
具体来说,您获得发布信用的方式是不同的,这是前3行.其余的我无耻地从@Seth复制完成片段.
确保根据需要替换YourResourceGroup/YourWebApp:
$creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
$kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3091 次 |
| 最近记录: |