google-gax 0.8.12 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google/gax.rb +0 -1
- data/lib/google/gax/version.rb +1 -1
- data/lib/google/longrunning/operations_client.rb +9 -16
- metadata +22 -13
- data/lib/google/gax/credentials.rb +0 -150
- data/lib/google/gax/version.rb~ +0 -34
- data/spec/google/gax/credentials_spec.rb +0 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fddb2e602722db6f4c4aa081c4660a6a3291214c
|
4
|
+
data.tar.gz: 6be83a2a050318833068ccef972ae886668a5484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6f35c2dcc528491d6a58dd6bf32813708995b20317363cc3eea067ae2358ffdb76da2809a4f12cb1968a1c2361c7cc6235a271c63dcb67e315fbff1a1a9de4
|
7
|
+
data.tar.gz: b9e48955378a15a297f967334ed6d7ff629a0a983acfc7e7e61b25bf6e58d87b7340717585aebe70f234973a86b2e86c79fbb1e4fd445f2dea2b010c0a6dfb19
|
data/lib/google/gax.rb
CHANGED
data/lib/google/gax/version.rb
CHANGED
@@ -40,6 +40,7 @@ require "json"
|
|
40
40
|
require "pathname"
|
41
41
|
|
42
42
|
require "google/gax"
|
43
|
+
require "googleauth"
|
43
44
|
|
44
45
|
require "google/longrunning/operations_pb"
|
45
46
|
|
@@ -80,18 +81,12 @@ module Google
|
|
80
81
|
# The scopes needed to make gRPC calls to all of the methods defined in
|
81
82
|
# this service.
|
82
83
|
ALL_SCOPES = [
|
83
|
-
"https://www.googleapis.com/auth/cloud-platform",
|
84
84
|
].freeze
|
85
85
|
|
86
|
-
# @param
|
87
|
-
# The domain name of the API remote host.
|
88
|
-
# @param port [Integer]
|
89
|
-
# The port on which to connect to the remote host.
|
90
|
-
# @param credentials
|
91
|
-
# [Google::Gax::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
86
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
92
87
|
# Provides the means for authenticating requests made by the client. This parameter can
|
93
88
|
# be many types.
|
94
|
-
# A `Google::
|
89
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
95
90
|
# authenticating requests made by this client.
|
96
91
|
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
97
92
|
# credentials for this client.
|
@@ -105,7 +100,7 @@ module Google
|
|
105
100
|
# @param scopes [Array<String>]
|
106
101
|
# The OAuth scopes for this service. This parameter is ignored if
|
107
102
|
# an updater_proc is supplied.
|
108
|
-
# @param client_config[Hash]
|
103
|
+
# @param client_config [Hash]
|
109
104
|
# A Hash for call options for each method. See
|
110
105
|
# Google::Gax#construct_settings for the structure of
|
111
106
|
# this data. Falls back to the default config if not specified
|
@@ -122,8 +117,6 @@ module Google
|
|
122
117
|
scopes: ALL_SCOPES,
|
123
118
|
client_config: {},
|
124
119
|
timeout: DEFAULT_TIMEOUT,
|
125
|
-
app_name: nil,
|
126
|
-
app_version: nil,
|
127
120
|
lib_name: nil,
|
128
121
|
lib_version: ""
|
129
122
|
# These require statements are intentionally placed here to initialize
|
@@ -139,14 +132,14 @@ module Google
|
|
139
132
|
credentials ||= chan_creds
|
140
133
|
credentials ||= updater_proc
|
141
134
|
end
|
142
|
-
if
|
143
|
-
warn "`
|
135
|
+
if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT
|
136
|
+
warn "`service_path` and `port` parameters are deprecated and will be removed"
|
144
137
|
end
|
145
138
|
|
146
|
-
credentials ||= Google::
|
139
|
+
credentials ||= Google::Auth::Credentials.default(scopes: scopes)
|
147
140
|
|
148
141
|
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
149
|
-
updater_proc = Google::
|
142
|
+
updater_proc = Google::Auth::Credentials.new(credentials).updater_proc
|
150
143
|
end
|
151
144
|
if credentials.is_a?(GRPC::Core::Channel)
|
152
145
|
channel = credentials
|
@@ -157,7 +150,7 @@ module Google
|
|
157
150
|
if credentials.is_a?(Proc)
|
158
151
|
updater_proc = credentials
|
159
152
|
end
|
160
|
-
if credentials.is_a?(Google::
|
153
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
161
154
|
updater_proc = credentials.updater_proc
|
162
155
|
end
|
163
156
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-gax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google API Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|
@@ -16,42 +16,54 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.6.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.6.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: grpc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.2
|
34
|
+
- - "<"
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
36
|
+
version: '2.0'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.7.2
|
44
|
+
- - "<"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: '2.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: googleapis-common-protos
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: 1.3.5
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
|
-
- - "
|
61
|
+
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: 1.3.5
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.0'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: google-protobuf
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,7 +174,6 @@ files:
|
|
162
174
|
- lib/google/gax/api_callable.rb
|
163
175
|
- lib/google/gax/bundling.rb
|
164
176
|
- lib/google/gax/constants.rb
|
165
|
-
- lib/google/gax/credentials.rb
|
166
177
|
- lib/google/gax/errors.rb
|
167
178
|
- lib/google/gax/grpc.rb
|
168
179
|
- lib/google/gax/operation.rb
|
@@ -170,14 +181,12 @@ files:
|
|
170
181
|
- lib/google/gax/settings.rb
|
171
182
|
- lib/google/gax/util.rb
|
172
183
|
- lib/google/gax/version.rb
|
173
|
-
- lib/google/gax/version.rb~
|
174
184
|
- lib/google/longrunning/operations_client.rb
|
175
185
|
- lib/google/longrunning/operations_client_config.json
|
176
186
|
- spec/fixtures/fixture.proto
|
177
187
|
- spec/fixtures/fixture_pb.rb
|
178
188
|
- spec/google/gax/api_callable_spec.rb
|
179
189
|
- spec/google/gax/bundling_spec.rb
|
180
|
-
- spec/google/gax/credentials_spec.rb
|
181
190
|
- spec/google/gax/grpc_spec.rb
|
182
191
|
- spec/google/gax/operation_spec.rb
|
183
192
|
- spec/google/gax/path_template_spec.rb
|
@@ -1,150 +0,0 @@
|
|
1
|
-
# Copyright 2017, Google Inc.
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are
|
6
|
-
# met:
|
7
|
-
#
|
8
|
-
# * Redistributions of source code must retain the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer.
|
10
|
-
# * Redistributions in binary form must reproduce the above
|
11
|
-
# copyright notice, this list of conditions and the following disclaimer
|
12
|
-
# in the documentation and/or other materials provided with the
|
13
|
-
# distribution.
|
14
|
-
# * Neither the name of Google Inc. nor the names of its
|
15
|
-
# contributors may be used to endorse or promote products derived from
|
16
|
-
# this software without specific prior written permission.
|
17
|
-
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
require 'forwardable'
|
31
|
-
require 'googleauth'
|
32
|
-
require 'json'
|
33
|
-
require 'signet/oauth_2/client'
|
34
|
-
|
35
|
-
module Google
|
36
|
-
module Gax
|
37
|
-
# @private
|
38
|
-
# Represents the OAuth 2.0 signing logic.
|
39
|
-
# This class is intended to be inherited by API-specific classes
|
40
|
-
# which overrides the SCOPE constant.
|
41
|
-
class Credentials
|
42
|
-
TOKEN_CREDENTIAL_URI = 'https://accounts.google.com/o/oauth2/token'.freeze
|
43
|
-
AUDIENCE = 'https://accounts.google.com/o/oauth2/token'.freeze
|
44
|
-
SCOPE = [].freeze
|
45
|
-
PATH_ENV_VARS = [].freeze
|
46
|
-
JSON_ENV_VARS = [].freeze
|
47
|
-
DEFAULT_PATHS = [].freeze
|
48
|
-
|
49
|
-
attr_accessor :client
|
50
|
-
|
51
|
-
##
|
52
|
-
# Delegate client methods to the client object.
|
53
|
-
extend Forwardable
|
54
|
-
def_delegators :@client,
|
55
|
-
:token_credential_uri, :audience,
|
56
|
-
:scope, :issuer, :signing_key, :updater_proc
|
57
|
-
|
58
|
-
def initialize(keyfile, scope: nil)
|
59
|
-
verify_keyfile_provided! keyfile
|
60
|
-
if keyfile.is_a? Signet::OAuth2::Client
|
61
|
-
@client = keyfile
|
62
|
-
elsif keyfile.is_a? Hash
|
63
|
-
hash = stringify_hash_keys keyfile
|
64
|
-
hash['scope'] ||= scope
|
65
|
-
@client = init_client hash
|
66
|
-
else
|
67
|
-
verify_keyfile_exists! keyfile
|
68
|
-
json = JSON.parse ::File.read(keyfile)
|
69
|
-
json['scope'] ||= scope
|
70
|
-
@client = init_client json
|
71
|
-
end
|
72
|
-
@client.fetch_access_token!
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Returns the default credentials.
|
77
|
-
#
|
78
|
-
def self.default(scope: nil)
|
79
|
-
env = ->(v) { ENV[v] }
|
80
|
-
json = lambda do |v|
|
81
|
-
unless ENV[v].nil?
|
82
|
-
begin
|
83
|
-
JSON.parse ENV[v]
|
84
|
-
rescue
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
path = ->(p) { ::File.file? p }
|
90
|
-
|
91
|
-
# First try to find keyfile file from environment variables.
|
92
|
-
self::PATH_ENV_VARS.map(&env).compact.select(&path)
|
93
|
-
.each do |file|
|
94
|
-
return new file, scope: scope
|
95
|
-
end
|
96
|
-
# Second try to find keyfile json from environment variables.
|
97
|
-
self::JSON_ENV_VARS.map(&json).compact.each do |hash|
|
98
|
-
return new hash, scope: scope
|
99
|
-
end
|
100
|
-
# Third try to find keyfile file from known file paths.
|
101
|
-
self::DEFAULT_PATHS.select(&path).each do |file|
|
102
|
-
return new file, scope: scope
|
103
|
-
end
|
104
|
-
# Finally get instantiated client from Google::Auth.
|
105
|
-
scope ||= self::SCOPE
|
106
|
-
client = Google::Auth.get_application_default scope
|
107
|
-
new client
|
108
|
-
end
|
109
|
-
|
110
|
-
protected
|
111
|
-
|
112
|
-
# Verify that the keyfile argument is provided.
|
113
|
-
def verify_keyfile_provided!(keyfile)
|
114
|
-
return unless keyfile.nil?
|
115
|
-
raise 'The keyfile passed to Google::Gax::Credentials.new was nil.'
|
116
|
-
end
|
117
|
-
|
118
|
-
# Verify that the keyfile argument is a file.
|
119
|
-
def verify_keyfile_exists!(keyfile)
|
120
|
-
exists = ::File.file? keyfile
|
121
|
-
raise "The keyfile '#{keyfile}' is not a valid file." unless exists
|
122
|
-
end
|
123
|
-
|
124
|
-
# Initializes the Signet client.
|
125
|
-
def init_client(keyfile)
|
126
|
-
client_opts = client_options keyfile
|
127
|
-
Signet::OAuth2::Client.new client_opts
|
128
|
-
end
|
129
|
-
|
130
|
-
# returns a new Hash with string keys instead of symbol keys.
|
131
|
-
def stringify_hash_keys(hash)
|
132
|
-
Hash[hash.map { |k, v| [k.to_s, v] }]
|
133
|
-
end
|
134
|
-
|
135
|
-
def client_options(options)
|
136
|
-
# Keyfile options have higher priority over constructor defaults
|
137
|
-
options['token_credential_uri'] ||= self.class::TOKEN_CREDENTIAL_URI
|
138
|
-
options['audience'] ||= self.class::AUDIENCE
|
139
|
-
options['scope'] ||= self.class::SCOPE
|
140
|
-
|
141
|
-
# client options for initializing signet client
|
142
|
-
{ token_credential_uri: options['token_credential_uri'],
|
143
|
-
audience: options['audience'],
|
144
|
-
scope: Array(options['scope']),
|
145
|
-
issuer: options['client_email'],
|
146
|
-
signing_key: OpenSSL::PKey::RSA.new(options['private_key']) }
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
data/lib/google/gax/version.rb~
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright 2016, Google Inc.
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are
|
6
|
-
# met:
|
7
|
-
#
|
8
|
-
# * Redistributions of source code must retain the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer.
|
10
|
-
# * Redistributions in binary form must reproduce the above
|
11
|
-
# copyright notice, this list of conditions and the following disclaimer
|
12
|
-
# in the documentation and/or other materials provided with the
|
13
|
-
# distribution.
|
14
|
-
# * Neither the name of Google Inc. nor the names of its
|
15
|
-
# contributors may be used to endorse or promote products derived from
|
16
|
-
# this software without specific prior written permission.
|
17
|
-
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
module Google
|
31
|
-
module Gax
|
32
|
-
VERSION = '0.8.7'.freeze
|
33
|
-
end
|
34
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# Copyright 2017, Google Inc.
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are
|
6
|
-
# met:
|
7
|
-
#
|
8
|
-
# * Redistributions of source code must retain the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer.
|
10
|
-
# * Redistributions in binary form must reproduce the above
|
11
|
-
# copyright notice, this list of conditions and the following disclaimer
|
12
|
-
# in the documentation and/or other materials provided with the
|
13
|
-
# distribution.
|
14
|
-
# * Neither the name of Google Inc. nor the names of its
|
15
|
-
# contributors may be used to endorse or promote products derived from
|
16
|
-
# this software without specific prior written permission.
|
17
|
-
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
require 'google/gax/credentials'
|
31
|
-
|
32
|
-
# This test is testing the private class Google::Gax::Credentials. We want to
|
33
|
-
# make sure that the passed in scope propogates to the Signet object. This means
|
34
|
-
# testing the private API, which is generally frowned on.
|
35
|
-
describe Google::Gax::Credentials, :private do
|
36
|
-
let(:default_keyfile_hash) do
|
37
|
-
{
|
38
|
-
'private_key_id' => 'testabc1234567890xyz',
|
39
|
-
'private_key' => "-----BEGIN RSA PRIVATE KEY-----\nMIIBOwIBAAJBAOyi0Hy1l4Ym2m2o71Q0TF4O9E81isZEsX0bb+Bqz1SXEaSxLiXM\nUZE8wu0eEXivXuZg6QVCW/5l+f2+9UPrdNUCAwEAAQJAJkqubA/Chj3RSL92guy3\nktzeodarLyw8gF8pOmpuRGSiEo/OLTeRUMKKD1/kX4f9sxf3qDhB4e7dulXR1co/\nIQIhAPx8kMW4XTTL6lJYd2K5GrH8uBMp8qL5ya3/XHrBgw3dAiEA7+3Iw3ULTn2I\n1J34WlJ2D5fbzMzB4FAHUNEV7Ys3f1kCIQDtUahCMChrl7+H5t9QS+xrn77lRGhs\nB50pjvy95WXpgQIhAI2joW6JzTfz8fAapb+kiJ/h9Vcs1ZN3iyoRlNFb61JZAiA8\nNy5NyNrMVwtB/lfJf1dAK/p/Bwd8LZLtgM6PapRfgw==\n-----END RSA PRIVATE KEY-----\n",
|
40
|
-
'client_email' => 'credz-testabc1234567890xyz@developer.gserviceaccount.com',
|
41
|
-
'client_id' => 'credz-testabc1234567890xyz.apps.googleusercontent.com',
|
42
|
-
'type' => 'service_account'
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'uses a default scope' do
|
47
|
-
mocked_signet = double('Signet::OAuth2::Client')
|
48
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
49
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
50
|
-
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
|
51
|
-
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
|
52
|
-
expect(options[:scope]).to eq([])
|
53
|
-
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
|
54
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
55
|
-
|
56
|
-
mocked_signet
|
57
|
-
end
|
58
|
-
|
59
|
-
Google::Gax::Credentials.new default_keyfile_hash
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'uses a custom scope' do
|
63
|
-
mocked_signet = double('Signet::OAuth2::Client')
|
64
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
65
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
66
|
-
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
|
67
|
-
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
|
68
|
-
expect(options[:scope]).to eq(['http://example.com/scope'])
|
69
|
-
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
|
70
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
71
|
-
|
72
|
-
mocked_signet
|
73
|
-
end
|
74
|
-
|
75
|
-
Google::Gax::Credentials.new default_keyfile_hash, scope: 'http://example.com/scope'
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'can be subclassed to pass in other env paths' do
|
79
|
-
TEST_PATH_ENV_VAR = 'TEST_PATH'.freeze
|
80
|
-
TEST_PATH_ENV_VAL = '/unknown/path/to/file.txt'.freeze
|
81
|
-
TEST_JSON_ENV_VAR = 'TEST_JSON_VARS'.freeze
|
82
|
-
|
83
|
-
ENV[TEST_PATH_ENV_VAR] = TEST_PATH_ENV_VAL
|
84
|
-
ENV[TEST_JSON_ENV_VAR] = JSON.generate(default_keyfile_hash)
|
85
|
-
|
86
|
-
class TestCredentials < Google::Gax::Credentials
|
87
|
-
SCOPE = 'http://example.com/scope'.freeze
|
88
|
-
PATH_ENV_VARS = [TEST_PATH_ENV_VAR].freeze
|
89
|
-
JSON_ENV_VARS = [TEST_JSON_ENV_VAR].freeze
|
90
|
-
end
|
91
|
-
|
92
|
-
allow(::File).to receive(:file?).with(TEST_PATH_ENV_VAL) { false }
|
93
|
-
|
94
|
-
mocked_signet = double('Signet::OAuth2::Client')
|
95
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
96
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
97
|
-
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
|
98
|
-
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
|
99
|
-
expect(options[:scope]).to eq(['http://example.com/scope'])
|
100
|
-
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
|
101
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
102
|
-
|
103
|
-
mocked_signet
|
104
|
-
end
|
105
|
-
|
106
|
-
TestCredentials.default
|
107
|
-
end
|
108
|
-
end
|