google-app-engine - 如何在 Go AppEngine 应用程序中将 TLS 1.2 与 appengine/urlfetch 结合使用

标签 google-app-engine ssl go

我正在编写一个 go appengine 应用程序,它需要从 Stripe 获取一个页面。

基本上我用的是these instructions随官方 Stripe API 一起提供。但是,当我使用 dev_appserver.py 运行它时,我得到:

2016/08/14 12:03:15 Requesting POST api.stripe.com/v1/customers
2016/08/14 12:03:18 Error encountered from Stripe: {"type":"invalid_request_error","message":"Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.","request_id":"req_90O6reF1Mwi9yZ","status":401}

我发现 Python AppEngine 应用程序可以指定要在我的 app.yaml 中使用的 SSL 库(请参阅 SSL support)。但是,如果我将 libraries 部分添加到我的 app.yaml 文件中,我会得到:

$ (go_appengine/dev_appserver.py app)
Traceback (most recent call last):
  File "go_appengine/dev_appserver.py", line 89, in <module>
    _run_file(__file__, globals())
  File "go_appengine/dev_appserver.py", line 85, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1040, in <module>
    main()
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1033, in main
    dev_server.start(options)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 758, in start
    options.config_paths, options.app_id)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 831, in __init__
    module_configuration = ModuleConfiguration(config_path, app_id)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 127, in __init__
    self._config_path)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 424, in _parse_configuration
    config, files = appinfo_includes.ParseAndReturnIncludePaths(f)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/appinfo_includes.py", line 82, in ParseAndReturnIncludePaths
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/appinfo.py", line 2191, in LoadSingleAppInfo
    listener.Parse(app_info)
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/yaml_listener.py", line 227, in Parse
    self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
  File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/yaml_listener.py", line 178, in _HandleEvents
    raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: libraries entries are only supported by the "python27" runtime
  in "app/app.yaml", line 25, column 1

这是有道理的,因为我没有使用 Python。我真的需要一种方法来为 Go 设置它。

我的 app.yaml 文件如下所示:

application: app-name
version: alpha-001
runtime: go
api_version: go1

handlers:
...

runtime 更改为 python27 可以消除库错误,但显然我的 go 代码无法正常工作。

关于如何通过开发应用服务器和生产环境启用 TLS 1.2 有什么想法吗?

最佳答案

来自 Go net/http 文档:

For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport:

tr := &http.Transport{
    TLSClientConfig:    &tls.Config{...},
    DisableCompression: true,
}
client := &http.Client{Transport: tr}

来自appengine documentation看起来您可以像往常一样使用 net/http 包并进行一些调整。

关于google-app-engine - 如何在 Go AppEngine 应用程序中将 TLS 1.2 与 appengine/urlfetch 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38942171/

相关文章:

google-app-engine - 如何使用自定义域强制执行到 Google App Engine 的 HTTPS 流量?

SSL 证书问题无法获取本地颁发者证书

ssl - IBM MobileFirst 证书固定

mongodb - 带有 mgo 驱动程序的 mongo 聚合查询

java - 将数据插入 google appengine 的数据库

google-app-engine - GAE Go——异步数据存储 API?

google-app-engine - 在 GAE 上使用 Rest API

amazon-web-services - 具有相互身份验证的 AWS 安全 REST API

json unmarshal 不工作但解码确实

go - 在 go 中发布带有数据的请求