google-cloud-core 1.2.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd3cf2a2e538cb37ffd2daae810180a7cf19dcad051f1fdce8d6b6c6dd13a566
4
- data.tar.gz: e197ffcd7a014052eaeabba0f744ce0c3c86da7be88639bd9e91338eb122b7e4
3
+ metadata.gz: 0da3f7e70a825960a1eefff5508fadf4e4e58005a16c1ee0cf3f1c9f04af65bb
4
+ data.tar.gz: 82b1d53b8a7339152f8a65a2c0ded58ac4edc1549c24eeff03c9bdaae0f10c56
5
5
  SHA512:
6
- metadata.gz: 27e11063ff53977170fa53a5559d272ac324225ee0ee9bc85f2b696b5b6f31f0719b605283eae7b73d12808a8326a97f9dd5308d89fab5b89df22dac5fdca8b3
7
- data.tar.gz: 4ba78b2ef42de56f09660dd30c40eee1fcd7c74a6ba5c57fc126dcd05cb9af59e9087caa8f9745a44f8e332c67a6e8b16252ef8f600655ff811c74314635011b
6
+ metadata.gz: 9c29b01b9004f1cbe7a93a56e69286bce35a582f012ba819876f41667dc8b7b19d92c4f1108c314099d56882c9fe1022fe4a38d05dd76a70fda5bd48d78a0365
7
+ data.tar.gz: af2334493f6309401623c8c3c6b4712f421a3ce12563b1cf6a8ffa5dc03380e8afb043590d0a56fe397ef645aa89458af57df718cf0fd9a01f2ac5291fb09ed1
data/.yardopts CHANGED
@@ -1,7 +1,12 @@
1
1
  --no-private
2
2
  --title=Google Cloud Core
3
3
  --markup markdown
4
+ --markup-provider redcarpet
4
5
 
5
6
  ./lib/**/*.rb
6
7
  -
7
8
  README.md
9
+ AUTHENTICATION.md
10
+ CONTRIBUTING.md
11
+ CODE_OF_CONDUCT.md
12
+ LICENSE
data/AUTHENTICATION.md ADDED
@@ -0,0 +1,41 @@
1
+ ## With `google-cloud-ruby`
2
+
3
+ With `google-cloud-ruby` it's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis.
4
+
5
+ ### Google Cloud Platform environments
6
+
7
+ While running on Google Cloud Platform (GCP), including Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud Functions (GCF) and Cloud Run, no extra work is needed. The **Project ID** and **Credentials** and are discovered automatically. Code should be written as if already authenticated.
8
+
9
+ ### Project and Credential Lookup
10
+
11
+ The google-cloud library aims to make authentication as simple as possible, and provides several mechanisms to configure your system without providing **Project ID** and **Service Account Credentials** directly in code.
12
+
13
+ **Project ID** is discovered in the following order:
14
+
15
+ 1. Specify project ID in code
16
+ 2. Discover project ID in environment variables
17
+ 3. Discover GCE project ID
18
+
19
+ **Credentials** are discovered in the following order:
20
+
21
+ 1. Specify credentials in code
22
+ 2. Discover credentials path in environment variables
23
+ 3. Discover credentials JSON in environment variables
24
+ 4. Discover credentials file in the Cloud SDK's path
25
+ 5. Discover GCE credentials
26
+
27
+ ### Environment Variables
28
+
29
+ The **Project ID** and **Credentials JSON** can be placed in environment variables instead of declaring them directly in code. Each service has its own environment variable, allowing for different service accounts to be used for different services. The path to the **Credentials JSON** file can be stored in the environment variable, or the **Credentials JSON** itself can be stored for environments such as Docker containers where writing files is difficult or not encouraged.
30
+
31
+ Here are the environment variables (in the order they are checked) for project ID:
32
+
33
+ 1. `GOOGLE_CLOUD_PROJECT`
34
+
35
+ Here are the environment variables (in the order they are checked) for credentials:
36
+
37
+ 1. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file
38
+ 2. `GOOGLE_CLOUD_KEYFILE_JSON` - JSON contents
39
+
40
+
41
+
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,141 @@
1
+ # Contributing to Google Cloud
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud requires Ruby 2.5+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Google Cloud dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-core/
48
+ $ bundle install
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-core/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Google Cloud Tests
65
+
66
+ Tests are very important part of google-cloud. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-core/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Google Cloud Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Google Cloud unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-core/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Google Cloud Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Google Cloud documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-core/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ## Coding Style
120
+
121
+ Please follow the established coding style in the library. The style is is
122
+ largely based on [The Ruby Style
123
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
124
+ on seattle-style:
125
+
126
+ * Avoid parenthesis when possible, including in method definitions.
127
+ * Always use double quotes strings. ([Option
128
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
129
+
130
+ You can check your code against these rules by running Rubocop like so:
131
+
132
+ ```sh
133
+ $ cd google-cloud-core/
134
+ $ bundle exec rake rubocop
135
+ ```
136
+
137
+ ## Code of Conduct
138
+
139
+ Please note that this project is released with a Contributor Code of Conduct. By
140
+ participating in this project you agree to abide by its terms. See
141
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/README.md CHANGED
@@ -1,32 +1,52 @@
1
1
  # google-cloud-core
2
2
 
3
- This library contains shared types, such as error classes, for the google-cloud project. Please see the top-level project [README](../README.md) for general information.
3
+ This library contains shared types, such as error classes, for the google-cloud
4
+ project. Please see the [GitHub
5
+ repository](https://github.com/googleapis/google-cloud-ruby) for more
6
+ information about the individual google-cloud gems.
4
7
 
5
- - [google-cloud-core API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-core/latest)
8
+ - [google-cloud-core API documentation](https://googleapis.dev/ruby/google-cloud-core/latest)
6
9
 
7
10
  ## Supported Ruby Versions
8
11
 
9
- This library is supported on Ruby 2.0+.
12
+ This library is supported on Ruby 2.5+.
13
+
14
+ Google provides official support for Ruby versions that are actively supported
15
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
16
+ security maintenance, and not end of life. Currently, this means Ruby 2.5 and
17
+ later. Older versions of Ruby _may_ still work, but are unsupported and not
18
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
19
+ about the Ruby support schedule.
10
20
 
11
21
  ## Versioning
12
22
 
13
23
  This library follows [Semantic Versioning](http://semver.org/).
14
24
 
15
- It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
25
+ It is currently in major version zero (0.y.z), which means that anything may
26
+ change at any time and the public API should not be considered stable.
16
27
 
17
28
  ## Contributing
18
29
 
19
30
  Contributions to this library are always welcome and highly encouraged.
20
31
 
21
- See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.
32
+ See the [Contributing
33
+ Guide](https://googleapis.dev/ruby/google-cloud-core/latest/file.CONTRIBUTING.html)
34
+ for more information on how to get started.
22
35
 
23
- Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
36
+ Please note that this project is released with a Contributor Code of Conduct. By
37
+ participating in this project you agree to abide by its terms. See [Code of
38
+ Conduct](https://googleapis.dev/ruby/google-cloud-core/latest/file.CODE_OF_CONDUCT.html)
39
+ for more information.
24
40
 
25
41
  ## License
26
42
 
27
- This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
43
+ This library is licensed under Apache 2.0. Full license text is available in
44
+ [LICENSE](https://googleapis.dev/ruby/google-cloud-core/latest/file.LICENSE.html).
28
45
 
29
46
  ## Support
30
47
 
31
- Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
32
- Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
48
+ Please [report bugs at the project on
49
+ Github](https://github.com/googleapis/google-cloud-ruby/issues). Don't
50
+ hesitate to [ask
51
+ questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
52
+ about the client or APIs on [StackOverflow](http://stackoverflow.com).
data/lib/google/cloud.rb CHANGED
@@ -30,19 +30,15 @@ require "google/cloud/core/version"
30
30
  # App Engine and Google Kubernetes Engine. In other environments you can
31
31
  # configure authentication easily, either directly in your code or via
32
32
  # environment variables. Read more about the options for connecting in the
33
- # [Authentication
34
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
35
- #
36
- # You can learn more about various options for connection on the [Authentication
37
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
33
+ # {file:AUTHENTICATION.md Authentication Guide}.
38
34
  #
39
35
  module Google
40
36
  module Cloud
41
37
  ##
42
38
  # Creates a new object for connecting to Google Cloud.
43
39
  #
44
- # For more information on connecting to Google Cloud see the [Authentication
45
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
40
+ # For more information on connecting to Google Cloud see the
41
+ # {file:AUTHENTICATION.md Authentication Guide}.
46
42
  #
47
43
  # @param [String] project_id Project identifier for the service you are
48
44
  # connecting to.
@@ -85,6 +81,9 @@ module Google
85
81
  # when running from GCP environments.
86
82
  # * `credentials`: The service account JSON file path. Automatically
87
83
  # discovered when running from GCP environments.
84
+ # * `on_error`: A Proc to be run when an error is encountered during on a
85
+ # background thread. The Proc must take the error object as
86
+ # the single argument.
88
87
  #
89
88
  # @return [Google::Cloud::Config] The top-level configuration object for
90
89
  # Google::Cloud libraries.
@@ -96,28 +95,76 @@ module Google
96
95
 
97
96
  @config
98
97
  end
98
+
99
+ ##
100
+ # Initialize toplevel configuration
101
+ # @private
102
+ #
103
+ def self.init_configuration
104
+ configure do |config|
105
+ default_project = Google::Cloud::Config.deferred do
106
+ ENV["GOOGLE_CLOUD_PROJECT"] || ENV["GCLOUD_PROJECT"]
107
+ end
108
+ default_creds = Google::Cloud::Config.deferred do
109
+ Google::Cloud::Config.credentials_from_env \
110
+ "GOOGLE_CLOUD_CREDENTIALS", "GOOGLE_CLOUD_CREDENTIALS_JSON",
111
+ "GOOGLE_CLOUD_KEYFILE", "GOOGLE_CLOUD_KEYFILE_JSON",
112
+ "GCLOUD_KEYFILE", "GCLOUD_KEYFILE_JSON"
113
+ end
114
+
115
+ config.add_field! :project_id, default_project,
116
+ match: String, allow_nil: true
117
+ config.add_alias! :project, :project_id
118
+ config.add_field! :credentials, default_creds, match: Object
119
+ config.add_alias! :keyfile, :credentials
120
+ config.add_field! :on_error, nil, match: Proc
121
+ end
122
+ end
123
+
124
+ ##
125
+ # Safely load all google-cloud-* gems.
126
+ # @private
127
+ #
128
+ def self.auto_load_gems
129
+ currently_loaded_files = loaded_files
130
+
131
+ auto_load_files.each do |auto_load_file|
132
+ auto_load_file = File.realpath auto_load_file
133
+ next if currently_loaded_files.include? auto_load_file
134
+ require auto_load_file
135
+ end
136
+ end
137
+
138
+ ##
139
+ # Find files that are currently loaded.
140
+ # @private
141
+ #
142
+ def self.loaded_files
143
+ files = Array(caller).map do |backtrace_line|
144
+ until backtrace_line.split(":").size < 2 || File.file?(backtrace_line)
145
+ backtrace_line = backtrace_line.split(":")[0..-2].join ":"
146
+ end
147
+ backtrace_line
148
+ end
149
+ files.uniq!
150
+ files.select! { |file| File.file? file }
151
+ files.map { |file| File.realpath file }
152
+ end
153
+
154
+ ##
155
+ # Find all google-cloud-* files for available gems.
156
+ # @private
157
+ #
158
+ def self.auto_load_files
159
+ return Gem.find_latest_files "google-cloud-*.rb" if Gem.respond_to? :find_latest_files
160
+ # Ruby 2.0 does not have Gem.find_latest_files
161
+ Gem.find_files "google-cloud-*.rb"
162
+ end
99
163
  end
100
164
  end
101
165
 
102
166
  # Set the default top-level configuration
103
- Google::Cloud.configure do |config|
104
- default_project = Google::Cloud::Config.deferred do
105
- ENV["GOOGLE_CLOUD_PROJECT"] || ENV["GCLOUD_PROJECT"]
106
- end
107
- default_creds = Google::Cloud::Config.deferred do
108
- Google::Cloud::Config.credentials_from_env \
109
- "GOOGLE_CLOUD_CREDENTIALS", "GOOGLE_CLOUD_CREDENTIALS_JSON",
110
- "GOOGLE_CLOUD_KEYFILE", "GOOGLE_CLOUD_KEYFILE_JSON",
111
- "GCLOUD_KEYFILE", "GCLOUD_KEYFILE_JSON"
112
- end
113
-
114
- config.add_field! :project_id, default_project, match: String, allow_nil: true
115
- config.add_alias! :project, :project_id
116
- config.add_field! :credentials, default_creds, match: Object
117
- config.add_alias! :keyfile, :credentials
118
- end
167
+ Google::Cloud.init_configuration
119
168
 
120
169
  # Auto-load all Google Cloud service gems.
121
- Gem.find_files("google-cloud-*.rb").each do |google_cloud_service|
122
- require google_cloud_service
123
- end
170
+ Google::Cloud.auto_load_gems
@@ -308,9 +308,7 @@ module Google
308
308
  #
309
309
  def [] key
310
310
  key = resolve_key! key
311
- unless @validators.key? key
312
- warn! "Key #{key.inspect} does not exist. Returning nil."
313
- end
311
+ warn! "Key #{key.inspect} does not exist. Returning nil." unless @validators.key? key
314
312
  value = @values[key]
315
313
  value = value.call if Config::DeferredValue === value
316
314
  value
@@ -338,6 +336,7 @@ module Google
338
336
  def field? key
339
337
  @validators[key.to_sym].is_a? ::Proc
340
338
  end
339
+ alias respond_to? field?
341
340
 
342
341
  ##
343
342
  # Check if the given key has been explicitly added as a subconfig name.
@@ -397,11 +396,12 @@ module Google
397
396
  def to_s!
398
397
  elems = @validators.keys.map do |k|
399
398
  v = @values[k]
400
- vstr = Config.config?(v) ? v.to_s! : value.inspect
399
+ vstr = Config.config?(v) ? v.to_s! : v.inspect
401
400
  " #{k}=#{vstr}"
402
401
  end
403
402
  "<Config:#{elems.join}>"
404
403
  end
404
+ alias inspect to_s!
405
405
 
406
406
  ##
407
407
  # Returns a nested hash representation of this configuration state,
@@ -458,8 +458,8 @@ module Google
458
458
  def method_missing name, *args
459
459
  name_str = name.to_s
460
460
  super unless name_str =~ /^[a-zA-Z]\w*=?$/
461
- if name_str.chomp! "="
462
- self[name_str] = args.first
461
+ if name_str.end_with? "="
462
+ self[name_str[0...-1]] = args.first
463
463
  else
464
464
  self[name]
465
465
  end
@@ -489,22 +489,22 @@ module Google
489
489
  ##
490
490
  # @private A validator that allows all values
491
491
  #
492
- OPEN_VALIDATOR = ::Proc.new { true }
492
+ OPEN_VALIDATOR = proc { true }
493
493
 
494
494
  ##
495
495
  # @private a list of key names that are technically illegal because
496
496
  # they clash with method names.
497
497
  #
498
- ILLEGAL_KEYS = %i[
499
- add_options
500
- initialize
501
- instance_eval
502
- instance_exec
503
- method_missing
504
- singleton_method_added
505
- singleton_method_removed
506
- singleton_method_undefined
507
- ].freeze
498
+ ILLEGAL_KEYS = [:add_options,
499
+ :initialize,
500
+ :inspect,
501
+ :instance_eval,
502
+ :instance_exec,
503
+ :method_missing,
504
+ :send,
505
+ :singleton_method_added,
506
+ :singleton_method_removed,
507
+ :singleton_method_undefined].freeze
508
508
 
509
509
  ##
510
510
  # @private sentinel indicating a subconfig in the validators hash
@@ -524,9 +524,7 @@ module Google
524
524
  warn! "Illegal key name: #{key_str.inspect}. Method dispatch will" \
525
525
  " not work for this key."
526
526
  end
527
- if @validators.key? key
528
- warn! "Key #{key.inspect} already exists. It will be replaced."
529
- end
527
+ warn! "Key #{key.inspect} already exists. It will be replaced." if @validators.key? key
530
528
  key
531
529
  end
532
530
 
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Core
19
- VERSION = "1.2.0".freeze
19
+ VERSION = "1.6.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -30,12 +30,12 @@ module Google
30
30
  # This class is intended to be inherited by API-specific classes
31
31
  # which overrides the SCOPE constant.
32
32
  class Credentials
33
- TOKEN_CREDENTIAL_URI = "https://accounts.google.com/o/oauth2/token"
34
- AUDIENCE = "https://accounts.google.com/o/oauth2/token"
35
- SCOPE = []
36
- PATH_ENV_VARS = %w[GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE]
37
- JSON_ENV_VARS = %w[GOOGLE_CLOUD_KEYFILE_JSON GCLOUD_KEYFILE_JSON]
38
- DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
33
+ TOKEN_CREDENTIAL_URI = "https://oauth2.googleapis.com/token".freeze
34
+ AUDIENCE = "https://oauth2.googleapis.com/token".freeze
35
+ SCOPE = [].freeze
36
+ PATH_ENV_VARS = ["GOOGLE_CLOUD_KEYFILE", "GCLOUD_KEYFILE"].freeze
37
+ JSON_ENV_VARS = ["GOOGLE_CLOUD_KEYFILE_JSON", "GCLOUD_KEYFILE_JSON"].freeze
38
+ DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"].freeze
39
39
 
40
40
  attr_accessor :client
41
41
 
@@ -48,9 +48,10 @@ module Google
48
48
 
49
49
  def initialize keyfile, scope: nil
50
50
  verify_keyfile_provided! keyfile
51
- if keyfile.is_a? Signet::OAuth2::Client
51
+ case keyfile
52
+ when Signet::OAuth2::Client
52
53
  @client = keyfile
53
- elsif keyfile.is_a? Hash
54
+ when Hash
54
55
  hash = stringify_hash_keys keyfile
55
56
  hash["scope"] ||= scope
56
57
  @client = init_client hash
@@ -114,7 +115,7 @@ module Google
114
115
  ##
115
116
  # returns a new Hash with string keys instead of symbol keys.
116
117
  def stringify_hash_keys hash
117
- Hash[hash.map { |k, v| [k.to_s, v] }]
118
+ hash.transform_keys(&:to_s)
118
119
  end
119
120
 
120
121
  def client_options options
@@ -125,10 +126,10 @@ module Google
125
126
 
126
127
  # client options for initializing signet client
127
128
  { token_credential_uri: options["token_credential_uri"],
128
- audience: options["audience"],
129
- scope: Array(options["scope"]),
130
- issuer: options["client_email"],
131
- signing_key: OpenSSL::PKey::RSA.new(options["private_key"]) }
129
+ audience: options["audience"],
130
+ scope: Array(options["scope"]),
131
+ issuer: options["client_email"],
132
+ signing_key: OpenSSL::PKey::RSA.new(options["private_key"]) }
132
133
  end
133
134
  end
134
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-27 00:00:00.000000000 Z
12
+ date: 2021-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-env
@@ -26,63 +26,77 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: minitest
29
+ name: google-cloud-errors
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: autotest-suffix
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: '5.10'
48
+ version: '1.1'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: '5.10'
55
+ version: '1.1'
42
56
  - !ruby/object:Gem::Dependency
43
- name: minitest-autotest
57
+ name: google-style
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
60
  - - "~>"
47
61
  - !ruby/object:Gem::Version
48
- version: '1.0'
62
+ version: 1.25.1
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - "~>"
54
68
  - !ruby/object:Gem::Version
55
- version: '1.0'
69
+ version: 1.25.1
56
70
  - !ruby/object:Gem::Dependency
57
- name: minitest-focus
71
+ name: minitest
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
74
  - - "~>"
61
75
  - !ruby/object:Gem::Version
62
- version: '1.1'
76
+ version: '5.14'
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - "~>"
68
82
  - !ruby/object:Gem::Version
69
- version: '1.1'
83
+ version: '5.14'
70
84
  - !ruby/object:Gem::Dependency
71
- name: minitest-rg
85
+ name: minitest-autotest
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '5.2'
90
+ version: '1.0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '5.2'
97
+ version: '1.0'
84
98
  - !ruby/object:Gem::Dependency
85
- name: autotest-suffix
99
+ name: minitest-focus
86
100
  requirement: !ruby/object:Gem::Requirement
87
101
  requirements:
88
102
  - - "~>"
@@ -96,19 +110,33 @@ dependencies:
96
110
  - !ruby/object:Gem::Version
97
111
  version: '1.1'
98
112
  - !ruby/object:Gem::Dependency
99
- name: rubocop
113
+ name: minitest-rg
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '5.2'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '5.2'
126
+ - !ruby/object:Gem::Dependency
127
+ name: redcarpet
100
128
  requirement: !ruby/object:Gem::Requirement
101
129
  requirements:
102
130
  - - "~>"
103
131
  - !ruby/object:Gem::Version
104
- version: 0.50.0
132
+ version: '3.0'
105
133
  type: :development
106
134
  prerelease: false
107
135
  version_requirements: !ruby/object:Gem::Requirement
108
136
  requirements:
109
137
  - - "~>"
110
138
  - !ruby/object:Gem::Version
111
- version: 0.50.0
139
+ version: '3.0'
112
140
  - !ruby/object:Gem::Dependency
113
141
  name: simplecov
114
142
  requirement: !ruby/object:Gem::Requirement
@@ -141,16 +169,16 @@ dependencies:
141
169
  name: yard-doctest
142
170
  requirement: !ruby/object:Gem::Requirement
143
171
  requirements:
144
- - - "<="
172
+ - - "~>"
145
173
  - !ruby/object:Gem::Version
146
- version: 0.1.8
174
+ version: 0.1.13
147
175
  type: :development
148
176
  prerelease: false
149
177
  version_requirements: !ruby/object:Gem::Requirement
150
178
  requirements:
151
- - - "<="
179
+ - - "~>"
152
180
  - !ruby/object:Gem::Version
153
- version: 0.1.8
181
+ version: 0.1.13
154
182
  description: google-cloud-core is the internal shared library for google-cloud-ruby.
155
183
  email:
156
184
  - mike@blowmage.com
@@ -160,14 +188,16 @@ extensions: []
160
188
  extra_rdoc_files: []
161
189
  files:
162
190
  - ".yardopts"
191
+ - AUTHENTICATION.md
192
+ - CODE_OF_CONDUCT.md
193
+ - CONTRIBUTING.md
163
194
  - LICENSE
164
195
  - README.md
165
196
  - lib/google/cloud.rb
166
197
  - lib/google/cloud/config.rb
167
198
  - lib/google/cloud/core/version.rb
168
199
  - lib/google/cloud/credentials.rb
169
- - lib/google/cloud/errors.rb
170
- homepage: https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-core
200
+ homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-core
171
201
  licenses:
172
202
  - Apache-2.0
173
203
  metadata: {}
@@ -179,15 +209,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
209
  requirements:
180
210
  - - ">="
181
211
  - !ruby/object:Gem::Version
182
- version: 2.0.0
212
+ version: '2.5'
183
213
  required_rubygems_version: !ruby/object:Gem::Requirement
184
214
  requirements:
185
215
  - - ">="
186
216
  - !ruby/object:Gem::Version
187
217
  version: '0'
188
218
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.7.6
219
+ rubygems_version: 3.2.13
191
220
  signing_key:
192
221
  specification_version: 4
193
222
  summary: Internal shared library for google-cloud-ruby
@@ -1,324 +0,0 @@
1
- # Copyright 2015 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "English"
17
-
18
- module Google
19
- module Cloud
20
- ##
21
- # Base google-cloud exception class.
22
- class Error < StandardError
23
- ##
24
- # Construct a new Google::Cloud::Error object, optionally passing in a
25
- # message.
26
- def initialize msg = nil
27
- super
28
- @cause = $ERROR_INFO
29
- end
30
-
31
- # Add Error#cause (introduced in 2.1) to Ruby 2.0.
32
- unless respond_to?(:cause)
33
- ##
34
- # The previous exception at the time this exception was raised. This is
35
- # useful for wrapping exceptions and retaining the original exception
36
- # information.
37
- define_method(:cause) do
38
- @cause
39
- end
40
- end
41
-
42
- ##
43
- # Returns the value of `status_code` from the underlying cause error
44
- # object, if both are present. Otherwise returns `nil`.
45
- #
46
- # This is typically present on errors originating from calls to an API
47
- # over HTTP/REST.
48
- #
49
- # @returns [Object, nil]
50
- def status_code
51
- return nil unless cause && cause.respond_to?(:status_code)
52
- cause.status_code
53
- end
54
-
55
- ##
56
- # Returns the value of `body` from the underlying cause error
57
- # object, if both are present. Otherwise returns `nil`.
58
- #
59
- # This is typically present on errors originating from calls to an API
60
- # over HTTP/REST.
61
- #
62
- # @returns [Object, nil]
63
- def body
64
- return nil unless cause && cause.respond_to?(:body)
65
- cause.body
66
- end
67
-
68
- ##
69
- # Returns the value of `header` from the underlying cause error
70
- # object, if both are present. Otherwise returns `nil`.
71
- #
72
- # This is typically present on errors originating from calls to an API
73
- # over HTTP/REST.
74
- #
75
- # @returns [Object, nil]
76
- def header
77
- return nil unless cause && cause.respond_to?(:header)
78
- cause.header
79
- end
80
-
81
- ##
82
- # Returns the value of `code` from the underlying cause error
83
- # object, if both are present. Otherwise returns `nil`.
84
- #
85
- # This is typically present on errors originating from calls to an API
86
- # over gRPC.
87
- #
88
- # @returns [Object, nil]
89
- def code
90
- return nil unless cause && cause.respond_to?(:code)
91
- cause.code
92
- end
93
-
94
- ##
95
- # Returns the value of `details` from the underlying cause error
96
- # object, if both are present. Otherwise returns `nil`.
97
- #
98
- # This is typically present on errors originating from calls to an API
99
- # over gRPC.
100
- #
101
- # @returns [Object, nil]
102
- def details
103
- return nil unless cause && cause.respond_to?(:details)
104
- cause.details
105
- end
106
-
107
- ##
108
- # Returns the value of `metadata` from the underlying cause error
109
- # object, if both are present. Otherwise returns `nil`.
110
- #
111
- # This is typically present on errors originating from calls to an API
112
- # over gRPC.
113
- #
114
- # @returns [Object, nil]
115
- def metadata
116
- return nil unless cause && cause.respond_to?(:metadata)
117
- cause.metadata
118
- end
119
-
120
- ##
121
- # Returns the value of `status_details` from the underlying cause error
122
- # object, if both are present. Otherwise returns `nil`.
123
- #
124
- # This is typically present on errors originating from calls to an API
125
- # over gRPC.
126
- #
127
- # @returns [Object, nil]
128
- def status_details
129
- return nil unless cause && cause.respond_to?(:status_details)
130
- cause.status_details
131
- end
132
-
133
- # @private Create a new error object from a client error
134
- def self.from_error error
135
- klass = if error.respond_to? :code
136
- grpc_error_class_for error.code
137
- elsif error.respond_to? :status_code
138
- gapi_error_class_for error.status_code
139
- else
140
- self
141
- end
142
- klass.new error.message
143
- end
144
-
145
- # @private Identify the subclass for a gRPC error
146
- def self.grpc_error_class_for grpc_error_code
147
- # The gRPC status code 0 is for a successful response.
148
- # So there is no error subclass for a 0 status code, use current class.
149
- [
150
- self, CanceledError, UnknownError, InvalidArgumentError,
151
- DeadlineExceededError, NotFoundError, AlreadyExistsError,
152
- PermissionDeniedError, ResourceExhaustedError,
153
- FailedPreconditionError, AbortedError, OutOfRangeError,
154
- UnimplementedError, InternalError, UnavailableError, DataLossError,
155
- UnauthenticatedError
156
- ][grpc_error_code] || self
157
- end
158
-
159
- # @private Identify the subclass for a Google API Client error
160
- def self.gapi_error_class_for http_status_code
161
- # The http status codes mapped to their error classes.
162
- {
163
- 400 => InvalidArgumentError, # FailedPreconditionError/OutOfRangeError
164
- 401 => UnauthenticatedError,
165
- 403 => PermissionDeniedError,
166
- 404 => NotFoundError,
167
- 409 => AlreadyExistsError, # AbortedError
168
- 412 => FailedPreconditionError,
169
- 429 => ResourceExhaustedError,
170
- 499 => CanceledError,
171
- 500 => InternalError, # UnknownError/DataLossError
172
- 501 => UnimplementedError,
173
- 503 => UnavailableError,
174
- 504 => DeadlineExceededError
175
- }[http_status_code] || self
176
- end
177
- end
178
-
179
- ##
180
- # Canceled indicates the operation was cancelled (typically by the caller).
181
- class CanceledError < Error
182
- end
183
-
184
- ##
185
- # Unknown error. An example of where this error may be returned is
186
- # if a Status value received from another address space belongs to
187
- # an error-space that is not known in this address space. Also
188
- # errors raised by APIs that do not return enough error information
189
- # may be converted to this error.
190
- class UnknownError < Error
191
- end
192
-
193
- ##
194
- # InvalidArgument indicates client specified an invalid argument.
195
- # Note that this differs from FailedPrecondition. It indicates arguments
196
- # that are problematic regardless of the state of the system
197
- # (e.g., a malformed file name).
198
- class InvalidArgumentError < Error
199
- end
200
-
201
- ##
202
- # DeadlineExceeded means operation expired before completion.
203
- # For operations that change the state of the system, this error may be
204
- # returned even if the operation has completed successfully. For
205
- # example, a successful response from a server could have been delayed
206
- # long enough for the deadline to expire.
207
- class DeadlineExceededError < Error
208
- end
209
-
210
- ##
211
- # NotFound means some requested entity (e.g., file or directory) was
212
- # not found.
213
- class NotFoundError < Error
214
- end
215
-
216
- ##
217
- # AlreadyExists means an attempt to create an entity failed because one
218
- # already exists.
219
- class AlreadyExistsError < Error
220
- end
221
-
222
- ##
223
- # PermissionDenied indicates the caller does not have permission to
224
- # execute the specified operation. It must not be used for rejections
225
- # caused by exhausting some resource (use ResourceExhausted
226
- # instead for those errors). It must not be
227
- # used if the caller cannot be identified (use Unauthenticated
228
- # instead for those errors).
229
- class PermissionDeniedError < Error
230
- end
231
-
232
- ##
233
- # Unauthenticated indicates the request does not have valid
234
- # authentication credentials for the operation.
235
- class UnauthenticatedError < Error
236
- end
237
-
238
- ##
239
- # ResourceExhausted indicates some resource has been exhausted, perhaps
240
- # a per-user quota, or perhaps the entire file system is out of space.
241
- class ResourceExhaustedError < Error
242
- end
243
-
244
- ##
245
- # FailedPrecondition indicates operation was rejected because the
246
- # system is not in a state required for the operation's execution.
247
- # For example, directory to be deleted may be non-empty, an rmdir
248
- # operation is applied to a non-directory, etc.
249
- #
250
- # A litmus test that may help a service implementor in deciding
251
- # between FailedPrecondition, Aborted, and Unavailable:
252
- # (a) Use Unavailable if the client can retry just the failing call.
253
- # (b) Use Aborted if the client should retry at a higher-level
254
- # (e.g., restarting a read-modify-write sequence).
255
- # (c) Use FailedPrecondition if the client should not retry until
256
- # the system state has been explicitly fixed. E.g., if an "rmdir"
257
- # fails because the directory is non-empty, FailedPrecondition
258
- # should be returned since the client should not retry unless
259
- # they have first fixed up the directory by deleting files from it.
260
- # (d) Use FailedPrecondition if the client performs conditional
261
- # REST Get/Update/Delete on a resource and the resource on the
262
- # server does not match the condition. E.g., conflicting
263
- # read-modify-write on the same resource.
264
- class FailedPreconditionError < Error
265
- end
266
-
267
- ##
268
- # Aborted indicates the operation was aborted, typically due to a
269
- # concurrency issue like sequencer check failures, transaction aborts,
270
- # etc.
271
- #
272
- # See litmus test above for deciding between FailedPrecondition,
273
- # Aborted, and Unavailable.
274
- class AbortedError < Error
275
- end
276
-
277
- ##
278
- # OutOfRange means operation was attempted past the valid range.
279
- # E.g., seeking or reading past end of file.
280
- #
281
- # Unlike InvalidArgument, this error indicates a problem that may
282
- # be fixed if the system state changes. For example, a 32-bit file
283
- # system will generate InvalidArgument if asked to read at an
284
- # offset that is not in the range [0,2^32-1], but it will generate
285
- # OutOfRange if asked to read from an offset past the current
286
- # file size.
287
- #
288
- # There is a fair bit of overlap between FailedPrecondition and
289
- # OutOfRange. We recommend using OutOfRange (the more specific
290
- # error) when it applies so that callers who are iterating through
291
- # a space can easily look for an OutOfRange error to detect when
292
- # they are done.
293
- class OutOfRangeError < Error
294
- end
295
-
296
- ##
297
- # Unimplemented indicates operation is not implemented or not
298
- # supported/enabled in this service.
299
- class UnimplementedError < Error
300
- end
301
-
302
- ##
303
- # Internal errors. Means some invariants expected by underlying
304
- # system has been broken. If you see one of these errors,
305
- # something is very broken.
306
- class InternalError < Error
307
- end
308
-
309
- ##
310
- # Unavailable indicates the service is currently unavailable.
311
- # This is a most likely a transient condition and may be corrected
312
- # by retrying with a backoff.
313
- #
314
- # See litmus test above for deciding between FailedPrecondition,
315
- # Aborted, and Unavailable.
316
- class UnavailableError < Error
317
- end
318
-
319
- ##
320
- # DataLoss indicates unrecoverable data loss or corruption.
321
- class DataLossError < Error
322
- end
323
- end
324
- end