google-api-client 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.4.2
2
+
3
+ * Fixed incompatibility with Ruby 1.8.7
4
+
1
5
  # 0.4.1
2
6
 
3
7
  * Fixed ancestor checking issue when assigning Autoparse identifiers
@@ -401,6 +401,76 @@ module Google
401
401
  end
402
402
  end
403
403
 
404
+ ##
405
+ # Verifies an ID token against a server certificate. Used to ensure that
406
+ # an ID token supplied by an untrusted client-side mechanism is valid.
407
+ # Raises an error if the token is invalid or missing.
408
+ def verify_id_token!
409
+ gem 'jwt', '~> 0.1.4'
410
+ require 'jwt'
411
+ require 'openssl'
412
+ @certificates ||= {}
413
+ if !self.authorization.respond_to?(:id_token)
414
+ raise ArgumentError, (
415
+ "Current authorization mechanism does not support ID tokens: " +
416
+ "#{self.authorization.class.to_s}"
417
+ )
418
+ elsif !self.authorization.id_token
419
+ raise ArgumentError, (
420
+ "Could not verify ID token, ID token missing. " +
421
+ "Scopes were: #{self.authorization.scope.inspect}"
422
+ )
423
+ else
424
+ check_cached_certs = lambda do
425
+ valid = false
426
+ for key, cert in @certificates
427
+ begin
428
+ self.authorization.decoded_id_token(cert.public_key)
429
+ valid = true
430
+ rescue JWT::DecodeError, Signet::UnsafeOperationError
431
+ # Expected exception. Ignore, ID token has not been validated.
432
+ end
433
+ end
434
+ valid
435
+ end
436
+ if check_cached_certs.call()
437
+ return true
438
+ end
439
+ request = self.generate_request(
440
+ :http_method => :get,
441
+ :uri => 'https://www.googleapis.com/oauth2/v1/certs',
442
+ :authenticated => false
443
+ )
444
+ response = self.transmit(:request => request)
445
+ if response.status >= 200 && response.status < 300
446
+ @certificates.merge!(
447
+ Hash[MultiJson.decode(response.body).map do |key, cert|
448
+ [key, OpenSSL::X509::Certificate.new(cert)]
449
+ end]
450
+ )
451
+ elsif response.status >= 400
452
+ case response.status
453
+ when 400...500
454
+ exception_type = ClientError
455
+ when 500...600
456
+ exception_type = ServerError
457
+ else
458
+ exception_type = TransmissionError
459
+ end
460
+ url = request.to_env(Faraday.default_connection)[:url]
461
+ raise exception_type,
462
+ "Could not retrieve certificates from: #{url}"
463
+ end
464
+ if check_cached_certs.call()
465
+ return true
466
+ else
467
+ raise InvalidIDTokenError,
468
+ "Could not verify ID token against any available certificate."
469
+ end
470
+ end
471
+ return nil
472
+ end
473
+
404
474
  ##
405
475
  # Generates a request.
406
476
  #
@@ -172,12 +172,14 @@ module Google
172
172
  query_parameters = parameters.reject do |k, v|
173
173
  template_variables.include?(k)
174
174
  end
175
- if query_parameters.size > 0
176
- uri.query_values = (uri.query_values || []) + query_parameters
175
+ # encode all non-template parameters
176
+ params = ""
177
+ unless query_parameters.empty?
178
+ params = "?" + Addressable::URI.form_encode(query_parameters)
177
179
  end
178
180
  # Normalization is necessary because of undesirable percent-escaping
179
181
  # during URI template expansion
180
- return uri.normalize
182
+ return uri.normalize + params
181
183
  end
182
184
 
183
185
  ##
@@ -74,22 +74,26 @@ module Google
74
74
  Google::INFLECTOR.camelize(api.name)
75
75
  api_version_string =
76
76
  Google::INFLECTOR.camelize(api.version).gsub('.', '_')
77
- if Google::APIClient::Schema.const_defined?(api_name_string, false)
77
+ # This is for compatibility with Ruby 1.8.7.
78
+ # TODO(bobaman) Remove this when we eventually stop supporting 1.8.7.
79
+ args = []
80
+ args << false if Class.method(:const_defined?).arity != 1
81
+ if Google::APIClient::Schema.const_defined?(api_name_string, *args)
78
82
  api_name = Google::APIClient::Schema.const_get(
79
- api_name_string, false
83
+ api_name_string, *args
80
84
  )
81
85
  else
82
86
  api_name = Google::APIClient::Schema.const_set(
83
87
  api_name_string, Module.new
84
88
  )
85
89
  end
86
- if api_name.const_defined?(api_version_string, false)
87
- api_version = api_name.const_get(api_version_string, false)
90
+ if api_name.const_defined?(api_version_string, *args)
91
+ api_version = api_name.const_get(api_version_string, *args)
88
92
  else
89
93
  api_version = api_name.const_set(api_version_string, Module.new)
90
94
  end
91
- if api_version.const_defined?(schema_name, false)
92
- schema_class = api_version.const_get(schema_name, false)
95
+ if api_version.const_defined?(schema_name, *args)
96
+ schema_class = api_version.const_get(schema_name, *args)
93
97
  end
94
98
  end
95
99
 
@@ -36,5 +36,10 @@ module Google
36
36
  # A 5xx class HTTP error occurred.
37
37
  class ServerError < TransmissionError
38
38
  end
39
+
40
+ ##
41
+ # An exception that is raised if an ID token could not be validated.
42
+ class InvalidIDTokenError < StandardError
43
+ end
39
44
  end
40
45
  end
@@ -22,7 +22,7 @@ if !defined?(::Google::APIClient::VERSION)
22
22
  module VERSION
23
23
  MAJOR = 0
24
24
  MINOR = 4
25
- TINY = 1
25
+ TINY = 2
26
26
 
27
27
  STRING = [MAJOR, MINOR, TINY].join('.')
28
28
  end
data/tasks/gem.rake CHANGED
@@ -96,3 +96,5 @@ end
96
96
 
97
97
  desc 'Alias to gem:package'
98
98
  task 'gem' => 'gem:package'
99
+
100
+ task 'gem:release' => 'gem:gemspec'
data/tasks/git.rake CHANGED
@@ -3,9 +3,9 @@ namespace :git do
3
3
  desc 'List tags from the Git repository'
4
4
  task :list do
5
5
  tags = `git tag -l`
6
- tags.gsub!('\r', '')
7
- tags = tags.split('\n').sort {|a, b| b <=> a }
8
- puts tags.join('\n')
6
+ tags.gsub!("\r", '')
7
+ tags = tags.split("\n").sort {|a, b| b <=> a }
8
+ puts tags.join("\n")
9
9
  end
10
10
 
11
11
  desc 'Create a new tag in the Git repository'
@@ -19,6 +19,11 @@ namespace :git do
19
19
  v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
20
20
  abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
21
21
 
22
+ git_status = `git status`
23
+ if git_status !~ /nothing to commit \(working directory clean\)/
24
+ abort "Working directory isn't clean."
25
+ end
26
+
22
27
  tag = "#{PKG_NAME}-#{PKG_VERSION}"
23
28
  msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
24
29
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: google-api-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.1
5
+ version: 0.4.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bob Aman
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-10 00:00:00 Z
13
+ date: 2012-02-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: signet