REST调用sslCertificate.insert失败,并显示“无法解析SSL证书”,但gcloud正常工作

时间:2019-02-08 13:38:47

标签: ssl google-cloud-platform

这是一个生成错误的示例程序:

import urllib3
import certifi
from google.auth.transport.urllib3 import AuthorizedHttp
from google.oauth2 import service_account
import boto3
from pprint import pprint
import json

# parameters

JSON_SERVICE_ACCOUNT_FILE = "/home/mwilbert/gcp/matt-vm-service-account.json"
SCOPES = [
  'https://www.googleapis.com/auth/devstorage.read_write',
  'https://www.googleapis.com/auth/compute'
]

TEST_PROJECTID = 'mwilbert-workspace'
TEST_FULLCHAIN_FILE = '/etc/letsencrypt/live/fake.mapgeo.io/fullchain.pem'
TEST_PRIVKEY_FILE = '/etc/letsencrypt/live/fake.mapgeo.io/privkey.pem'

http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',ca_certs=certifi.where())
credentials = service_account.Credentials.from_service_account_file(JSON_SERVICE_ACCOUNT_FILE)
scoped_credentials = credentials.with_scopes(SCOPES)
authed_http = AuthorizedHttp(scoped_credentials,http)

requestBody = {
  "name":"deleteme",
  "description": "fake domain cert",
  "certificate": TEST_FULLCHAIN_FILE,
  "privateKey": TEST_PRIVKEY_FILE,
}
rb = json.dumps(requestBody)
url = 'https://www.googleapis.com/compute/v1/projects/%s/global/sslCertificates' % TEST_PROJECTID
r = authed_http.urlopen('POST',
                        url,
                        headers={'Content-Type': 'application/json'},
                        body=rb)

response = json.loads(r.data)
pprint(response)

但是,如果我将相同的参数传递给gcloud

gcloud compute ssl-certificates create deleteme
--certificate=/etc/letsencrypt/live/fake.mapgeo.io/fullchain.pem
--private-key=/etc/letsencrypt/live/fake.mapgeo.io/privkey.pem
--description="fake domain cert" --project=mwilbert-workspace

在同一终端会话中创建证书。证书为.PEM格式。

有人接到这个电话吗?如果是这样,还有指针吗?

0 个答案:

没有答案