【问题标题】:Why doesn't gcloud auth activate-service-account work on Windows?为什么 gcloud auth activate-service-account 在 Windows 上不起作用?
【发布时间】:2019-05-15 01:34:08
【问题描述】:

我有一个新下载的 Google Cloud 服务帐户令牌。我想在 Windows、Mac 和 Linux 上激活它作为 CI 管道的一部分。为此,我这样做:

gcloud auth activate-service-account --key-file=./token.json

这在 Linux 和 Mac 上运行良好。在 Windows 上,我收到以下错误:

ERROR: (gcloud.auth.activate-service-account) Could not read json file C:\Users\appveyor\token.json: No JSON object could be decoded

无论我从 PowerShell 调用 gcloud 还是从 cmd.exe 调用 gcloud.cmd,都会发生错误。怎么回事?

【问题讨论】:

    标签: windows gcloud


    【解决方案1】:

    发现是字符编码问题。我之前使用

    将字符串输入AppVeyor
    [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:GCLOUD_TOKEN)) | Out-File .\token.json
    

    将文件写入为 UTF-16LE。 gcloud 捆绑的 Python 并不关心这一点。我的下一次尝试使用了Set-Content -Encoding utf8 .\token.json,但它使用 BOM 写入 UTF-8,gcloud 仍然无法处理。最后让它与以下内容一起工作:

    $content = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:GCLOUD_TOKEN)) ; $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False ; [System.IO.File]::WriteAllLines('token.json', $content, $Utf8NoBomEncoding)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 2019-02-21
      • 2021-03-21
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多