Skip to content

Commit b5d73a8

Browse files
Warn on EOL Ruby Versions (#159)
1 parent b03268d commit b5d73a8

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.6.5 (2018/08/16)
22

33
* Fix incorrect http verb when revoking credentials.
4+
* Warn on EOL ruby versions.
45

56
## 0.6.4 (2018/08/03)
67

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ access and refresh tokens. Two storage implementations are included:
162162
Custom storage implementations can also be used. See
163163
[token_store.rb](lib/googleauth/token_store.rb) for additional details.
164164

165+
## Supported Ruby Versions
166+
167+
This library is currently supported on Ruby 1.9+.
168+
169+
However, Ruby 2.4 or later is strongly recommended, as earlier releases have
170+
reached or are nearing end-of-life. After March 31, 2019, Google will provide
171+
official support only for Ruby versions that are considered current and
172+
supported by Ruby Core (that is, Ruby versions that are either in normal
173+
maintenance or in security maintenance).
174+
See https://www.ruby-lang.org/en/downloads/branches/ for further details.
175+
165176
## License
166177

167178
This library is licensed under Apache 2.0. Full license text is

lib/googleauth.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,75 @@
3333
require 'googleauth/default_credentials'
3434
require 'googleauth/user_authorizer'
3535
require 'googleauth/web_user_authorizer'
36+
37+
module Google
38+
# Module Auth provides classes that provide Google-specific authorization
39+
# used to access Google APIs.
40+
module Auth
41+
# rubocop:disable MethodDefParentheses
42+
43+
# On March 31, 2019, set supported version to 2.4 and recommended to 2.6.
44+
# Thereafter, follow the MRI support schedule: supported means non-EOL,
45+
# and recommended means in normal (rather than security) maintenance.
46+
# See https://www.ruby-lang.org/en/downloads/branches/
47+
##
48+
# Minimum "supported" Ruby version (non-EOL)
49+
# @private
50+
#
51+
SUPPORTED_VERSION_THRESHOLD = '1.9'.freeze
52+
##
53+
# Minimum "recommended" Ruby version (normal maintenance)
54+
# @private
55+
#
56+
RECOMMENDED_VERSION_THRESHOLD = '2.4'.freeze
57+
##
58+
# Check Ruby version and emit a warning if it is old
59+
# @private
60+
#
61+
def self.warn_on_old_ruby_version
62+
return if ENV['GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS']
63+
cur_version = Gem::Version.new RUBY_VERSION
64+
if cur_version < Gem::Version.new(SUPPORTED_VERSION_THRESHOLD)
65+
warn_unsupported_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
66+
elsif cur_version < Gem::Version.new(RECOMMENDED_VERSION_THRESHOLD)
67+
warn_nonrecommended_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
68+
end
69+
rescue ArgumentError
70+
warn 'Unable to determine current Ruby version.'
71+
end
72+
73+
##
74+
# Print a warning for an EOL version of Ruby
75+
# @private
76+
#
77+
def self.warn_unsupported_ruby cur_version, recommended_version
78+
warn "WARNING: You are running Ruby #{cur_version}, which has reached" \
79+
' end-of-life and is no longer supported by Ruby Core.'
80+
warn 'The Google Cloud API clients work best on supported versions of' \
81+
' Ruby. It is strongly recommended that you upgrade to Ruby' \
82+
" #{recommended_version} or later."
83+
warn 'See https://www.ruby-lang.org/en/downloads/branches/ for more' \
84+
' info on the Ruby maintenance schedule.'
85+
warn 'To suppress this message, set the' \
86+
' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
87+
end
88+
89+
##
90+
# Print a warning for a supported but nearing EOL version of Ruby
91+
# @private
92+
#
93+
def self.warn_nonrecommended_ruby cur_version, recommended_version
94+
warn "WARNING: You are running Ruby #{cur_version}, which is nearing" \
95+
' end-of-life.'
96+
warn 'The Google Cloud API clients work best on supported versions of' \
97+
" Ruby. Consider upgrading to Ruby #{recommended_version} or later."
98+
warn 'See https://www.ruby-lang.org/en/downloads/branches/ for more' \
99+
' info on the Ruby maintenance schedule.'
100+
warn 'To suppress this message, set the' \
101+
' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
102+
end
103+
# rubocop:enable MethodDefParentheses
104+
end
105+
end
106+
107+
Google::Auth.warn_on_old_ruby_version

lib/googleauth/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ module Google
3131
# Module Auth provides classes that provide Google-specific authorization
3232
# used to access Google APIs.
3333
module Auth
34-
VERSION = '0.6.4'.freeze
34+
VERSION = '0.6.5'.freeze
3535
end
3636
end

0 commit comments

Comments
 (0)