googleauth 0.5.1 → 0.14.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.
Files changed (80) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +7 -0
  3. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +5 -4
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +36 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  6. data/.github/ISSUE_TEMPLATE/support_request.md +7 -0
  7. data/.kokoro/build.bat +16 -0
  8. data/.kokoro/build.sh +4 -0
  9. data/.kokoro/continuous/common.cfg +24 -0
  10. data/.kokoro/continuous/linux.cfg +25 -0
  11. data/.kokoro/continuous/osx.cfg +8 -0
  12. data/.kokoro/continuous/post.cfg +30 -0
  13. data/.kokoro/continuous/windows.cfg +29 -0
  14. data/.kokoro/osx.sh +4 -0
  15. data/.kokoro/presubmit/common.cfg +24 -0
  16. data/.kokoro/presubmit/linux.cfg +24 -0
  17. data/.kokoro/presubmit/osx.cfg +8 -0
  18. data/.kokoro/presubmit/windows.cfg +29 -0
  19. data/.kokoro/release.cfg +94 -0
  20. data/.kokoro/trampoline.bat +10 -0
  21. data/.kokoro/trampoline.sh +4 -0
  22. data/.repo-metadata.json +5 -0
  23. data/.rubocop.yml +19 -1
  24. data/CHANGELOG.md +112 -19
  25. data/CODE_OF_CONDUCT.md +43 -0
  26. data/Gemfile +19 -13
  27. data/{COPYING → LICENSE} +0 -0
  28. data/README.md +58 -18
  29. data/Rakefile +126 -9
  30. data/googleauth.gemspec +28 -25
  31. data/integration/helper.rb +31 -0
  32. data/integration/id_tokens/key_source_test.rb +74 -0
  33. data/lib/googleauth.rb +7 -96
  34. data/lib/googleauth/application_default.rb +81 -0
  35. data/lib/googleauth/client_id.rb +21 -19
  36. data/lib/googleauth/compute_engine.rb +70 -43
  37. data/lib/googleauth/credentials.rb +442 -0
  38. data/lib/googleauth/credentials_loader.rb +117 -43
  39. data/lib/googleauth/default_credentials.rb +93 -0
  40. data/lib/googleauth/iam.rb +11 -11
  41. data/lib/googleauth/id_tokens.rb +233 -0
  42. data/lib/googleauth/id_tokens/errors.rb +71 -0
  43. data/lib/googleauth/id_tokens/key_sources.rb +394 -0
  44. data/lib/googleauth/id_tokens/verifier.rb +144 -0
  45. data/lib/googleauth/json_key_reader.rb +50 -0
  46. data/lib/googleauth/scope_util.rb +12 -12
  47. data/lib/googleauth/service_account.rb +74 -63
  48. data/lib/googleauth/signet.rb +55 -13
  49. data/lib/googleauth/stores/file_token_store.rb +8 -8
  50. data/lib/googleauth/stores/redis_token_store.rb +22 -22
  51. data/lib/googleauth/token_store.rb +6 -6
  52. data/lib/googleauth/user_authorizer.rb +80 -68
  53. data/lib/googleauth/user_refresh.rb +44 -35
  54. data/lib/googleauth/version.rb +1 -1
  55. data/lib/googleauth/web_user_authorizer.rb +77 -68
  56. data/rakelib/devsite_builder.rb +45 -0
  57. data/rakelib/link_checker.rb +64 -0
  58. data/rakelib/repo_metadata.rb +59 -0
  59. data/spec/googleauth/apply_auth_examples.rb +74 -50
  60. data/spec/googleauth/client_id_spec.rb +75 -55
  61. data/spec/googleauth/compute_engine_spec.rb +98 -46
  62. data/spec/googleauth/credentials_spec.rb +478 -0
  63. data/spec/googleauth/get_application_default_spec.rb +149 -111
  64. data/spec/googleauth/iam_spec.rb +25 -25
  65. data/spec/googleauth/scope_util_spec.rb +26 -24
  66. data/spec/googleauth/service_account_spec.rb +269 -144
  67. data/spec/googleauth/signet_spec.rb +101 -30
  68. data/spec/googleauth/stores/file_token_store_spec.rb +12 -13
  69. data/spec/googleauth/stores/redis_token_store_spec.rb +11 -11
  70. data/spec/googleauth/stores/store_examples.rb +16 -16
  71. data/spec/googleauth/user_authorizer_spec.rb +153 -124
  72. data/spec/googleauth/user_refresh_spec.rb +186 -121
  73. data/spec/googleauth/web_user_authorizer_spec.rb +82 -69
  74. data/spec/spec_helper.rb +21 -19
  75. data/test/helper.rb +33 -0
  76. data/test/id_tokens/key_sources_test.rb +240 -0
  77. data/test/id_tokens/verifier_test.rb +269 -0
  78. metadata +87 -34
  79. data/.rubocop_todo.yml +0 -32
  80. data/.travis.yml +0 -37
@@ -0,0 +1,10 @@
1
+
2
+ SET url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/trampoline.bat"
3
+
4
+ SET "download=powershell -C Invoke-WebRequest -Uri %url% -OutFile master-trampoline.bat"
5
+
6
+ SET EXIT_STATUS=1
7
+
8
+ %download% && master-trampoline.bat && SET EXIT_STATUS=0
9
+
10
+ EXIT %EXIT_STATUS%
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ script_url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/trampoline.sh"
4
+ curl -o master-trampoline.sh $script_url && source master-trampoline.sh
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "googleauth",
3
+ "language": "ruby",
4
+ "distribution-name": "googleauth"
5
+ }
@@ -1 +1,19 @@
1
- inherit_from: .rubocop_todo.yml
1
+ inherit_gem:
2
+ google-style: google-style.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - "Rakefile"
7
+ - "integration/**/*"
8
+ - "rakelib/**/*"
9
+ - "spec/**/*"
10
+ - "test/**/*"
11
+ Metrics/ClassLength:
12
+ Max: 200
13
+ Metrics/ModuleLength:
14
+ Max: 110
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "googleauth.gemspec"
18
+ Style/SafeNavigation:
19
+ Enabled: false
@@ -1,21 +1,121 @@
1
- ## 0.5.1 (06/01/2016)
1
+ # Release History
2
2
 
3
- ### Changes
3
+ ### 0.14.0 / 2020-10-09
4
+
5
+ * Honor GCE_METADATA_HOST environment variable
6
+ * Fix errors in some environments when requesting an access token for multiple scopes
7
+
8
+ ### 0.13.1 / 2020-07-30
9
+
10
+ * Support scopes when using GCE Metadata Server authentication ([@ball-hayden][])
11
+
12
+ ### 0.13.0 / 2020-06-17
13
+
14
+ * Support for validating ID tokens.
15
+ * Fixed header application of ID tokens from service accounts.
16
+
17
+ ### 0.12.0 / 2020-04-08
18
+
19
+ * Support for ID token credentials.
20
+ * Support reading quota_id_project from service account credentials.
21
+
22
+ ### 0.11.0 / 2020-02-24
23
+
24
+ * Support Faraday 1.x.
25
+ * Allow special "postmessage" value for redirect_uri.
26
+
27
+ ### 0.10.0 / 2019-10-09
28
+
29
+ Note: This release now requires Ruby 2.4 or later
30
+
31
+ * Increase metadata timeout to improve reliability in some hosting environments
32
+ * Support an environment variable to suppress Cloud SDK credentials warnings
33
+ * Make the header check case insensitive
34
+ * Set instance variables at initialization to avoid spamming warnings
35
+ * Pass "Metadata-Flavor" header to metadata server when checking for GCE
36
+
37
+ ### 0.9.0 / 2019-08-05
38
+
39
+ * Restore compatibility with Ruby 2.0. This is the last release that will work on end-of-lifed versions of Ruby. The 0.10 release will require Ruby 2.4 or later.
40
+ * Update Credentials to use methods for values that are intended to be changed by users, replacing constants.
41
+ * Add retry on error for fetch_access_token
42
+ * Allow specifying custom state key-values
43
+ * Add verbosity none to gcloud command
44
+ * Make arity of WebUserAuthorizer#get_credentials compatible with the base class
45
+
46
+ ### 0.8.1 / 2019-03-27
47
+
48
+ * Silence unnecessary gcloud warning
49
+ * Treat empty credentials environment variables as unset
50
+
51
+ ### 0.8.0 / 2019-01-02
52
+
53
+ * Support connection options :default_connection and :connection_builder when creating credentials that need to refresh OAuth tokens. This lets clients provide connection objects with custom settings, such as proxies, needed for the client environment.
54
+ * Removed an unnecessary warning about project IDs.
55
+
56
+ ### 0.7.1 / 2018-10-25
57
+
58
+ * Make load_gcloud_project_id module function.
59
+
60
+ ### 0.7.0 / 2018-10-24
61
+
62
+ * Add project_id instance variable to UserRefreshCredentials, ServiceAccountCredentials, and Credentials.
63
+
64
+ ### 0.6.7 / 2018-10-16
65
+
66
+ * Update memoist dependency to ~> 0.16.
67
+
68
+ ### 0.6.6 / 2018-08-22
69
+
70
+ * Remove ruby version warnings.
71
+
72
+ ### 0.6.5 / 2018-08-16
73
+
74
+ * Fix incorrect http verb when revoking credentials.
75
+ * Warn on EOL ruby versions.
76
+
77
+ ### 0.6.4 / 2018-08-03
78
+
79
+ * Resolve issue where DefaultCredentials constant was undefined.
80
+
81
+ ### 0.6.3 / 2018-08-02
82
+
83
+ * Resolve issue where token_store was being written to twice
84
+
85
+ ### 0.6.2 / 2018-08-01
86
+
87
+ * Add warning when using cloud sdk credentials
88
+
89
+ ### 0.6.1 / 2017-10-18
90
+
91
+ * Fix file permissions
92
+
93
+ ### 0.6.0 / 2017-10-17
94
+
95
+ * Support ruby-jwt 2.0
96
+ * Add simple credentials class
97
+
98
+ ### 0.5.3 / 2017-07-21
99
+
100
+ * Fix file permissions on the gem's `.rb` files.
101
+
102
+ ### 0.5.2 / 2017-07-19
103
+
104
+ * Add retry mechanism when fetching access tokens in `GCECredentials` and `UserRefreshCredentials` classes.
105
+ * Update Google API OAuth2 token credential URI to v4.
106
+
107
+ ### 0.5.1 / 2016-01-06
4
108
 
5
109
  * Change header name emitted by `Client#apply` from "Authorization" to "authorization" ([@murgatroid99][])
6
110
  * Fix ADC not working on some windows machines ([@vsubramani][])
7
111
  [#55](https://github.com/google/google-auth-library-ruby/issues/55)
8
112
 
9
- ## 0.5.0 (12/10/2015)
10
-
11
- ### Changes
113
+ ### 0.5.0 / 2015-10-12
12
114
 
13
115
  * Initial support for user credentials ([@sqrrrl][])
14
116
  * Update Signet to 0.7
15
117
 
16
- ## 0.4.2 (05/08/2015)
17
-
18
- ### Changes
118
+ ### 0.4.2 / 2015-08-05
19
119
 
20
120
  * Updated UserRefreshCredentials hash to use string keys ([@haabaato][])
21
121
  [#36](https://github.com/google/google-auth-library-ruby/issues/36)
@@ -29,27 +129,19 @@
29
129
  * Relax the constraint of dependent version of multi_json ([@igrep][])
30
130
  [#30](https://github.com/google/google-auth-library-ruby/issues/30)
31
131
 
32
- ### Changes
33
-
34
132
  * Enables passing credentials via environment variables. ([@haabaato][])
35
133
  [#27](https://github.com/google/google-auth-library-ruby/issues/27)
36
134
 
37
- ## 0.4.1 (25/04/2015)
38
-
39
- ### Changes
135
+ ### 0.4.1 / 2015-04-25
40
136
 
41
137
  * Improves handling of --no-scopes GCE authorization ([@tbetbetbe][])
42
138
  * Refactoring and cleanup ([@joneslee85][])
43
139
 
44
- ## 0.4.0 (25/03/2015)
45
-
46
- ### Changes
140
+ ### 0.4.0 / 2015-03-25
47
141
 
48
142
  * Adds an implementation of JWT header auth ([@tbetbetbe][])
49
143
 
50
- ## 0.3.0 (23/03/2015)
51
-
52
- ### Changes
144
+ ### 0.3.0 / 2015-03-23
53
145
 
54
146
  * makes the scope parameter's optional in all APIs. ([@tbetbetbe][])
55
147
  * changes the scope parameter's position in various constructors. ([@tbetbetbe][])
@@ -62,3 +154,4 @@
62
154
  [@tbetbetbe]: https://github.com/tbetbetbe
63
155
  [@murgatroid99]: https://github.com/murgatroid99
64
156
  [@vsubramani]: https://github.com/vsubramani
157
+ [@ball-hayden]: https://github.com/ball-hayden
@@ -0,0 +1,43 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project,
4
+ and in the interest of fostering an open and welcoming community,
5
+ we pledge to respect all people who contribute through reporting issues,
6
+ posting feature requests, updating documentation,
7
+ submitting pull requests or patches, and other activities.
8
+
9
+ We are committed to making participation in this project
10
+ a harassment-free experience for everyone,
11
+ regardless of level of experience, gender, gender identity and expression,
12
+ sexual orientation, disability, personal appearance,
13
+ body size, race, ethnicity, age, religion, or nationality.
14
+
15
+ Examples of unacceptable behavior by participants include:
16
+
17
+ * The use of sexualized language or imagery
18
+ * Personal attacks
19
+ * Trolling or insulting/derogatory comments
20
+ * Public or private harassment
21
+ * Publishing other's private information,
22
+ such as physical or electronic
23
+ addresses, without explicit permission
24
+ * Other unethical or unprofessional conduct.
25
+
26
+ Project maintainers have the right and responsibility to remove, edit, or reject
27
+ comments, commits, code, wiki edits, issues, and other contributions
28
+ that are not aligned to this Code of Conduct.
29
+ By adopting this Code of Conduct,
30
+ project maintainers commit themselves to fairly and consistently
31
+ applying these principles to every aspect of managing this project.
32
+ Project maintainers who do not follow or enforce the Code of Conduct
33
+ may be permanently removed from the project team.
34
+
35
+ This code of conduct applies both within project spaces and in public spaces
36
+ when an individual is representing the project or its community.
37
+
38
+ Instances of abusive, harassing, or otherwise unacceptable behavior
39
+ may be reported by opening an issue
40
+ or contacting one or more of the project maintainers.
41
+
42
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
43
+ available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile CHANGED
@@ -1,24 +1,30 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in googleauth.gemspec
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem 'bundler', '~> 1.9'
8
- gem 'simplecov', '~> 0.9'
9
- gem 'coveralls', '~> 0.7'
10
- gem 'fakefs', '~> 0.6'
11
- gem 'rake', '~> 10.0'
12
- gem 'rubocop', '~> 0.30'
13
- gem 'rspec', '~> 3.0'
14
- gem 'redis', '~> 3.2'
15
- gem 'fakeredis', '~> 0.5'
16
- gem 'webmock', '~> 1.21'
17
- gem 'rack-test', '~> 0.6'
18
- gem 'sinatra'
7
+ gem "bundler", ">= 1.9"
8
+ gem "coveralls", "~> 0.7"
9
+ gem "fakefs", "~> 0.6"
10
+ gem "fakeredis", "~> 0.5"
11
+ gem "google-style", "~> 1.24.0"
12
+ gem "logging", "~> 2.0"
13
+ gem "minitest", "~> 5.14"
14
+ gem "minitest-focus", "~> 1.1"
15
+ gem "rack-test", "~> 0.6"
16
+ gem "rake", "~> 13.0"
17
+ gem "redis", "~> 3.2"
18
+ gem "rspec", "~> 3.0"
19
+ gem "simplecov", "~> 0.9"
20
+ gem "sinatra"
21
+ gem "webmock", "~> 3.8"
19
22
  end
20
23
 
21
24
  platforms :jruby do
22
25
  group :development do
23
26
  end
24
27
  end
28
+
29
+ gem "faraday", "~> 0.17"
30
+ gem "gems", "~> 1.2"
File without changes
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
1
  # Google Auth Library for Ruby
2
2
 
3
3
  <dl>
4
- <dt>Homepage</dt><dd><a href="http://www.github.com/google/google-auth-library-ruby">http://www.github.com/google/google-auth-library-ruby</a></dd>
4
+ <dt>Homepage</dt><dd><a href="http://www.github.com/googleapis/google-auth-library-ruby">http://www.github.com/googleapis/google-auth-library-ruby</a></dd>
5
5
  <dt>Authors</dt><dd><a href="mailto:temiola@google.com">Tim Emiola</a></dd>
6
6
  <dt>Copyright</dt><dd>Copyright © 2015 Google, Inc.</dd>
7
7
  <dt>License</dt><dd>Apache 2.0</dd>
8
8
  </dl>
9
9
 
10
10
  [![Gem Version](https://badge.fury.io/rb/googleauth.svg)](http://badge.fury.io/rb/googleauth)
11
- [![Build Status](https://secure.travis-ci.org/google/google-auth-library-ruby.png)](http://travis-ci.org/google/google-auth-library-ruby)
12
- [![Coverage Status](https://coveralls.io/repos/google/google-auth-library-ruby/badge.png)](https://coveralls.io/r/google/google-auth-library-ruby)
13
- [![Dependency Status](https://gemnasium.com/google/google-auth-library-ruby.png)](https://gemnasium.com/google/google-auth-library-ruby)
14
11
 
15
12
  ## Description
16
13
 
@@ -70,7 +67,7 @@ a generic authorizer useful for command line apps or custom integrations as
70
67
  well as a web variant tailored toward Rack-based applications.
71
68
 
72
69
  The authorizers are intended for authorization use cases. For sign-on,
73
- see [Google Idenity Platform](https://developers.google.com/identity/)
70
+ see [Google Identity Platform](https://developers.google.com/identity/)
74
71
 
75
72
  ### Example (Web)
76
73
 
@@ -92,7 +89,7 @@ get('/authorize') do
92
89
  user_id = request.session['user_id']
93
90
  credentials = authorizer.get_credentials(user_id, request)
94
91
  if credentials.nil?
95
- redirect authorizer.get_authorization_url(user_id: user_id, request: request)
92
+ redirect authorizer.get_authorization_url(login_hint: user_id, request: request)
96
93
  end
97
94
  # Credentials are valid, can call APIs
98
95
  # ...
@@ -111,6 +108,8 @@ end
111
108
  require 'googleauth'
112
109
  require 'googleauth/stores/file_token_store'
113
110
 
111
+ OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
112
+
114
113
  scope = 'https://www.googleapis.com/auth/drive'
115
114
  client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
116
115
  token_store = Google::Auth::Stores::FileTokenStore.new(
@@ -119,7 +118,7 @@ authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
119
118
 
120
119
  credentials = authorizer.get_credentials(user_id)
121
120
  if credentials.nil?
122
- url = authorizer.get_authorization_url(base_url: 'urn:ietf:wg:oauth:2.0:oob')
121
+ url = authorizer.get_authorization_url(base_url: OOB_URI )
123
122
  puts "Open #{url} in your browser and enter the resulting code:"
124
123
  code = gets
125
124
  credentials = authorizer.get_and_store_credentials_from_code(
@@ -129,6 +128,47 @@ end
129
128
  # OK to use credentials
130
129
  ```
131
130
 
131
+ ### Example (Service Account)
132
+
133
+ ```ruby
134
+ scope = 'https://www.googleapis.com/auth/androidpublisher'
135
+
136
+ authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
137
+ json_key_io: File.open('/path/to/service_account_json_key.json'),
138
+ scope: scope)
139
+
140
+ authorizer.fetch_access_token!
141
+ ```
142
+
143
+ ### Example (Environment Variables)
144
+
145
+ ```bash
146
+ export GOOGLE_ACCOUNT_TYPE=service_account
147
+ export GOOGLE_CLIENT_ID=000000000000000000000
148
+ export GOOGLE_CLIENT_EMAIL=xxxx@xxxx.iam.gserviceaccount.com
149
+ export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
150
+ ```
151
+
152
+ ```ruby
153
+ require 'googleauth'
154
+ require 'google/apis/drive_v3'
155
+
156
+ Drive = ::Google::Apis::DriveV3
157
+ drive = Drive::DriveService.new
158
+
159
+ # Auths with ENV vars:
160
+ # "GOOGLE_CLIENT_ID",
161
+ # "GOOGLE_CLIENT_EMAIL",
162
+ # "GOOGLE_ACCOUNT_TYPE",
163
+ # "GOOGLE_PRIVATE_KEY"
164
+ auth = ::Google::Auth::ServiceAccountCredentials
165
+ .make_creds(scope: 'https://www.googleapis.com/auth/drive')
166
+ drive.authorization = auth
167
+
168
+ list_files = drive.list_files()
169
+
170
+ ```
171
+
132
172
  ### Storage
133
173
 
134
174
  Authorizers require a storage instance to manage long term persistence of
@@ -138,15 +178,16 @@ access and refresh tokens. Two storage implementations are included:
138
178
  * Google::Auth::Stores::RedisTokenStore
139
179
 
140
180
  Custom storage implementations can also be used. See
141
- [token_store.rb](lib/googleauth/token_store.rb) for additional details.
181
+ [token_store.rb](https://googleapis.dev/ruby/googleauth/latest/Google/Auth/TokenStore.html) for additional details.
182
+
183
+ ## Supported Ruby Versions
142
184
 
143
- ## What about auth in google-apis-ruby-client?
185
+ This library requires Ruby 2.4 or later.
144
186
 
145
- The goal is for all auth done by
146
- [google-apis-ruby-client][google-apis-ruby-client] to be performed by this
147
- library. I.e, eventually google-apis-ruby-client will just take a dependency
148
- on this library. This update is a work in progress, but should be completed
149
- by Q2 2015.
187
+ In general, this library supports Ruby versions that are considered current and
188
+ supported by Ruby Core (that is, Ruby versions that are either in normal
189
+ maintenance or in security maintenance).
190
+ See https://www.ruby-lang.org/en/downloads/branches/ for further details.
150
191
 
151
192
  ## License
152
193
 
@@ -165,7 +206,6 @@ hesitate to
165
206
  [ask questions](http://stackoverflow.com/questions/tagged/google-auth-library-ruby)
166
207
  about the client or APIs on [StackOverflow](http://stackoverflow.com).
167
208
 
168
- [google-apis-ruby-client]: (https://github.com/google/google-api-ruby-client)
169
- [application default credentials]: (https://developers.google.com/accounts/docs/application-default-credentials)
170
- [contributing]: https://github.com/google/google-auth-library-ruby/tree/master/CONTRIBUTING.md
171
- [copying]: https://github.com/google/google-auth-library-ruby/tree/master/COPYING
209
+ [application default credentials]: https://developers.google.com/accounts/docs/application-default-credentials
210
+ [contributing]: https://github.com/googleapis/google-auth-library-ruby/tree/master/.github/CONTRIBUTING.md
211
+ [copying]: https://github.com/googleapis/google-auth-library-ruby/tree/master/COPYING
data/Rakefile CHANGED
@@ -1,15 +1,132 @@
1
1
  # -*- ruby -*-
2
- require 'rspec/core/rake_task'
3
- require 'rubocop/rake_task'
4
- require 'bundler/gem_tasks'
2
+ require "json"
3
+ require "bundler/gem_tasks"
5
4
 
6
- desc 'Run Rubocop to check for style violations'
5
+ require "rubocop/rake_task"
7
6
  RuboCop::RakeTask.new
8
7
 
9
- desc 'Run rake task'
10
- RSpec::Core::RakeTask.new(:spec)
8
+ require "rake/testtask"
11
9
 
12
- desc 'Does rubocop lint and runs the specs'
13
- task all: [:rubocop, :spec]
10
+ desc "Run tests."
11
+ Rake::TestTask.new do |t|
12
+ t.libs << "test"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ t.warning = false
15
+ end
14
16
 
15
- task default: :all
17
+ desc "Run integration tests."
18
+ Rake::TestTask.new("integration") do |t|
19
+ t.libs << "integration"
20
+ t.test_files = FileList["integration/**/*_test.rb"]
21
+ t.warning = false
22
+ end
23
+
24
+ task :ci do
25
+ header "Using Ruby - #{RUBY_VERSION}"
26
+ sh "bundle exec rubocop"
27
+ Rake::Task["test"].invoke
28
+ Rake::Task["integration"].invoke
29
+ sh "bundle exec rspec"
30
+ end
31
+
32
+ task :release_gem, :tag do |_t, args|
33
+ tag = args[:tag]
34
+ raise "You must provide a tag to release." if tag.nil?
35
+
36
+ # Verify the tag format "vVERSION"
37
+ m = tag.match /v(?<version>\S*)/
38
+ raise "Tag #{tag} does not match the expected format." if m.nil?
39
+
40
+ version = m[:version]
41
+ raise "You must provide a version." if version.nil?
42
+
43
+ api_token = ENV["RUBYGEMS_API_TOKEN"]
44
+
45
+ require "gems"
46
+ if api_token
47
+ ::Gems.configure do |config|
48
+ config.key = api_token
49
+ end
50
+ end
51
+
52
+ Bundler.with_clean_env do
53
+ sh "rm -rf pkg"
54
+ sh "bundle update"
55
+ sh "bundle exec rake build"
56
+ end
57
+
58
+ path_to_be_pushed = "pkg/googleauth-#{version}.gem"
59
+ gem_was_published = nil
60
+ if File.file? path_to_be_pushed
61
+ begin
62
+ response = ::Gems.push File.new(path_to_be_pushed)
63
+ puts response
64
+ raise unless response.include? "Successfully registered gem:"
65
+ gem_was_published = true
66
+ puts "Successfully built and pushed googleauth for version #{version}"
67
+ rescue StandardError => e
68
+ gem_was_published = false
69
+ puts "Error while releasing googleauth version #{version}: #{e.message}"
70
+ end
71
+ else
72
+ raise "Cannot build googleauth for version #{version}"
73
+ end
74
+
75
+ Rake::Task["kokoro:publish_docs"].invoke if gem_was_published
76
+ end
77
+
78
+ namespace :kokoro do
79
+ task :load_env_vars do
80
+ service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
81
+ ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
82
+ filename = "#{ENV['KOKORO_GFILE_DIR']}/env_vars.json"
83
+ env_vars = JSON.parse File.read(filename)
84
+ env_vars.each { |k, v| ENV[k] = v }
85
+ end
86
+
87
+ task :presubmit do
88
+ Rake::Task["ci"].invoke
89
+ end
90
+
91
+ task :continuous do
92
+ Rake::Task["ci"].invoke
93
+ end
94
+
95
+ task :post do
96
+ require_relative "rakelib/link_checker.rb"
97
+
98
+ link_checker = LinkChecker.new
99
+ link_checker.run
100
+ exit link_checker.exit_status
101
+ end
102
+
103
+ task :nightly do
104
+ Rake::Task["ci"].invoke
105
+ end
106
+
107
+ task :release do
108
+ version = "0.1.0"
109
+ Bundler.with_clean_env do
110
+ version = `bundle exec gem list`
111
+ .split("\n").select { |line| line.include? "googleauth" }
112
+ .first.split("(").last.split(")").first || "0.1.0"
113
+ end
114
+ Rake::Task["kokoro:load_env_vars"].invoke
115
+ Rake::Task["release_gem"].invoke "v#{version}"
116
+ end
117
+
118
+ task :publish_docs do
119
+ require_relative "rakelib/devsite_builder.rb"
120
+
121
+ DevsiteBuilder.new(__dir__).publish
122
+ end
123
+ end
124
+
125
+ def header str, token = "#"
126
+ line_length = str.length + 8
127
+ puts ""
128
+ puts token * line_length
129
+ puts "#{token * 3} #{str} #{token * 3}"
130
+ puts token * line_length
131
+ puts ""
132
+ end