如何将GCP服务帐户JSON字符串转换为DataForm凭据字符串?
我有一个GCP服务帐户JSON密钥,需要将其转换为数据形式凭据模板,如下所述。基本上,新线必须转换为\ n,并进行更多转换。会有一种简单的方法吗?
{
"projectId": "prj-dfad-4curtool-d-c818",
"credentials": "{
"type": "service_account",
"project_id": "prj-xxxx-xxx-x-xxx",
"private_key_id": "35cf...27b",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIE...ZNwub\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "102742287670708666429",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}",
"location": "US"
}
这样的数据形式凭据
{
"projectId": "prj-dfad-4curtool-d-c818",
"credentials": "{\r\n \"type\": \"service_account\",\r\n \"project_id\": \"prj-xxxx-xxx-x-xxx\",\r\n \"private_key_id\": \"35cf...27b\",\r\n \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIE...ZNwub\\n-----END PRIVATE KEY-----\\n\",\r\n \"client_email\": \"[email protected]\",\r\n \"client_id\": \"102742287670708666429\",\r\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\r\n \"token_uri\": \"https://oauth2.googleapis.com/token\",\r\n \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\r\n \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/[email protected]\"\r\n}\r\n\r\n",
"location": "US"
}
I have a GCP Service Account JSON key, that needs to be converted to a Dataform Credentials Template, as mentioned below. Basically, newlines have to be converted to \n , and some more transformations. Would there be an easy way to do this?
{
"projectId": "prj-dfad-4curtool-d-c818",
"credentials": "{
"type": "service_account",
"project_id": "prj-xxxx-xxx-x-xxx",
"private_key_id": "35cf...27b",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIE...ZNwub\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "102742287670708666429",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}",
"location": "US"
}
to the Dataform Credentials like this
{
"projectId": "prj-dfad-4curtool-d-c818",
"credentials": "{\r\n \"type\": \"service_account\",\r\n \"project_id\": \"prj-xxxx-xxx-x-xxx\",\r\n \"private_key_id\": \"35cf...27b\",\r\n \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIE...ZNwub\\n-----END PRIVATE KEY-----\\n\",\r\n \"client_email\": \"[email protected]\",\r\n \"client_id\": \"102742287670708666429\",\r\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\r\n \"token_uri\": \"https://oauth2.googleapis.com/token\",\r\n \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\r\n \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/[email protected]\"\r\n}\r\n\r\n",
"location": "US"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是使用 sed 替换控制chars(EG NEWLINE)具有逃脱的等效物(例如
\ n
)。在Linux上:
One option is to use sed to replace control chars (e.g. newline) with escaped equivalents (e.g.
\n
).On Linux: