我正在使用google/api_client
library in ruby。我的代码在开发和本地测试中运行良好,但在Travis-CI上却不太好。我将我的私钥存储为本地和Travis的多行字符串。我的代码在这里失败了:
require "google/api_client"
class GoogleCalendarAdapter
def key
OpenSSL::PKey::RSA.new(ENV["GOOGLE_P12_PEM"], "notasecret") # line 27
end
end
我已通过Travis-CI网络控制台将GOOGLE_P12_PEM环境变量定义为:
"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAK...\n...
\n-----END RSA PRIVATE KEY-----\n"
这是我收到的错误:
Failure/Error: events = calendar.fetch_events(start_time, end_time)
OpenSSL::PKey::RSAError:
Neither PUB key nor PRIV key: not enough data
# ./lib/google_calendar_adapter.rb:27:in `initialize'
# ./lib/google_calendar_adapter.rb:27:in `new'
# ./lib/google_calendar_adapter.rb:27:in `key'
# ./lib/google_calendar_adapter.rb:36:in `oauth2_client'
# ./lib/google_calendar_adapter.rb:49:in `google_api_client'
# ./lib/google_calendar_adapter.rb:15:in `fetch_events'
# ./spec/lib/google_calendar_adapter_spec.rb:18:in `block (3 levels) in <top (required)>'
欢迎任何有关如何解决此问题的建议。