安全服务帐户凭证 json 密钥 kotlin
因此,我试图在本地主机上获取服务应用程序凭据,但遇到了一些问题。我创建并下载了 json 密钥,我想保护它们,而不是让它们以纯文本形式存在。
我想知道做到这一点的最佳方法。我有这样的代码:
fun getServiceAccountCredentials(
pathToFallBackCredentialsFile: String
): ServiceAccountCredentials {
return try {
getApplicationDefault() as ServiceAccountCredentials
} catch (e: IOException) {
return ServiceAccountCredentials.fromStream(FileInputStream(pathToFallBackCredentialsFile))
} catch (e: ClassCastException) {
return ServiceAccountCredentials.fromStream(this::class.java.classLoader.getResourceAsStream(pathToFallBackCredentialsFile))
}
}
这里的问题是我的 JSON 文件在我的存储库中以纯文本形式公开。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选项
Options
我找到了解决方案。
我从 GCP 激活了 Secret Manager,并在其中添加了 JSON 文件。
为了在java/kotlin应用程序中获取秘密(没有spring,如果你有spring,你可以使用“spring-cloud-gcp-starter-secretmanager”),我使用了下面的代码。
I found a solution.
I activated the Secret Manager from GCP and I've added the JSON file there.
To take the secret in a java/kotlin application(without spring, if you have spring you can use "spring-cloud-gcp-starter-secretmanager"), I used the following piece of code.