尝试使用 Win10 桌面上的 PowerShell 5.1 Invoke-RestMethod 从 Artifactory Enterprise v6 实例获取存储库列表,但无法对其进行身份验证。
看起来很简单,但这
$myCred = Get-Credential notStanley
$lstART = Invoke-RestMethod -URI https://<myserver>/artifactory/api/repositories -Credential $myCred
仅返回允许匿名访问的项目。
如果我打开浏览器并登录到该 Artifactory 实例,我就可以粘贴上述 URI 并获取我的帐户有权访问的所有存储库的完整列表。
有任何提示 $myCred
缺少什么吗?
最佳答案
我过去曾尝试过使用artifactory,但-Credential
对我来说并没有真正起作用。
我尝试了API方式,更加简单易用。
使用 API key 连接到 Artifactory
Read here了解如何在 Artifactory 上获取您帐户的 API key 。
$header = @{"X-JFrog-Art-Api" = "yourAPIKey"}
Invoke-RestMethod -URI https://<myserver>/artifactory/api/repositories -Headers $header
使用基本身份验证和-Credential
如果您确实想要使用“获取凭据”提示,请确保使用在 Artifactory 中有效的用户名。它与域\用户不同。 from here
$login = Get-Credential -Message "Enter Credentials for Artifactory"
#invalid creds.. but its ok. Need to tell invoke-restmethod to use Basic Auth.
$headers = @{ Authorization = "Basic Zm9vOmJhcg==" }
# use -Credential to override the credentials.
$new = Invoke-RestMethod -URI https://<server>/artifactory/api/repositories -Headers $headers -Credential $login
关于powershell - 如何验证 Invoke-RestMethod 以列出 Artifactory 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60325084/