gpt4 book ai didi

c# - 使用 powershell 脚本获取功能键时出错

转载 作者:行者123 更新时间:2023-12-03 04:21:30 26 4
gpt4 key购买 nike

我有一个 http 触发的 azure 函数,我需要在部署期间填充其函数键。我目前正在尝试使用给定的进程获取功能键 here (只是我不调用主机 key API,而是调用功能 key API /admin/functions/$functionName/keys?code=$masterKey)。当我使用 KUDU zip API 将压缩的函数代码上传到函数应用程序时,我就会立即调用 API。

我面临的问题是,在尝试设置功能应用程序的应用程序设置时,我收到错误

Invoke-RestMethod : {"id":"643ea0b3-5ffe-4683-a8d3-62daec8c8db9","requestId":"ec5461d6-57bc-45dd-b3ac-358602cfa94c","statusCode":500,"errorCode":0,"message":" Value cannot be null.\r\nParameter name: source"}

但是当我在本地尝试时,这是有效的。当我进行 REST 调用以获取功能键并因此出现错误时,我怀疑该功能尚未部署。错误消息是什么意思以及如何修复它?这是暂时性问题吗?

更新:代码片段

function get_credentials($resourceGroupName, $functionAppName){
$creds = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName `
-ResourceType Microsoft.Web/sites/config -ResourceName "$functionAppName/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)))
return $base64AuthInfo
}
function get_master_key($kuduAuthToken, $functionAppName ){
Write-Host "KUDU token is $kuduAuthToken"
$apiUrl = "https://$functionAppName.scm.azurewebsites.net/api/functions/admin/masterkey"
$result = Invoke-RestMethod -Uri $apiUrl -Headers @{"Authorization"="Basic $kuduAuthToken";"If-Match"="*"}
$masterKey = $result.masterKey
Write-Host "master key is $masterKey"
return $masterKey
}

function get_function_key($functionAppName, $functionName, $masterKey ){

$apiUrl = "https://$functionAppName.azurewebsites.net/admin/functions/$functionName/keys?code=$masterKey"
Write-Host "Calling $apiUrl"
$result = Invoke-RestMethod -Uri $apiUrl
Write-Host "Result is $result"
return $result.keys[0].value
Write-Host "host token is $result"
}
$authToken = get_credentials $resourceGroupName $functionAppName
$masterKey = get_master_key $authToken $functionAppName
get_function_key $functionAppName $purgeFunctionName $masterKey

最佳答案

根据你的描述,我测试了你的工作流程,发现只发生了一次。

enter image description here

之后,相同的请求就可以按预期工作。

enter image description here

根据我的理解,正如您所猜测的那样,这可能是一个暂时性问题。另外,请确保您的功能可以按预期工作。此外,为了为您的函数生成每个函数 key 而不是使用默认主机 key ,您还可以利用 ARM REST API(例如 https://{functionappname}.azurewebsites.net/admin/functions/{functionname}/keys/{keyname}) 为现有功能创建新的功能键。

enter image description here

创建功能键的详细命令,可以引用类似issue .

关于c# - 使用 powershell 脚本获取功能键时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48338850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com