google-cloud-debugger 0.28.2 → 0.29.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
- SHA1:
3
- metadata.gz: 4f6c7702998c26106d5d7d8c9da1da90a23a85a9
4
- data.tar.gz: 9e792c21da0a3224c17df88921f635eddbdd8b90
2
+ SHA256:
3
+ metadata.gz: cf39367a4bd468a04d05cb1169183b0929f2f025dc96a26b5b679be501a62eeb
4
+ data.tar.gz: e17347af976df5273d21140bd2657087de7e057bec738241cc541b074eadba68
5
5
  SHA512:
6
- metadata.gz: 10b6cf1fbdfa245b73e5d40f83736e5e74444060484d13a18352be3ffcbb14dc0cba4fa9502e845b82874f04bde6ccce2eb52b56e2ebcdb0ee04d57c62526754
7
- data.tar.gz: 4e249d586c912cc55b971547268b5ab79fe975892c84ac5e24e46eb29a98749e8b4f21155815f9b735515fbf70f525eb41779c072532e80d4c7f628ab694b3b5
6
+ metadata.gz: fa34cd85cfdb7c417e0d951ce2b4b401c20939b74f32670718d0ae50ac68d8087ddf257b44c0cbb83538dbd2f2e682364eda16f827ccf8f8ab91a106fcdbdccb
7
+ data.tar.gz: ec77ef51189b469857211c6b74f2d7eef3084f3cb4f15a0d371a3dde62abbdb7796a7c1954069500db86903b8c16fd47ec81613f4f693cb3fe9379078ca790d9
data/README.md CHANGED
@@ -28,14 +28,14 @@ gem "google-cloud-debugger"
28
28
  $ bundle install
29
29
  ```
30
30
 
31
- Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
31
+ Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
32
32
  the `google-cloud-debugger` gem.
33
33
 
34
34
  ## Enable Stackdriver Debugger API
35
35
 
36
- The Stackdriver Debugger agent needs the [Stackdriver Debugger
37
- API](https://console.cloud.google.com/apis/library/clouddebugger.googleapis.com)
38
- to be enabled on your Google Cloud project. Make sure it's enabled if not
36
+ The Stackdriver Debugger agent needs the [Stackdriver Debugger
37
+ API](https://console.cloud.google.com/apis/library/clouddebugger.googleapis.com)
38
+ to be enabled on your Google Cloud project. Make sure it's enabled if not
39
39
  already.
40
40
 
41
41
  ## Enabling the Debugger agent
@@ -47,7 +47,7 @@ frameworks, such as Ruby on Rails and Sinatra.
47
47
 
48
48
  ### With Ruby on Rails
49
49
 
50
- You can load the Railtie that comes with the library into your Ruby
50
+ You can load the Railtie that comes with the library into your Ruby
51
51
  on Rails application by explicitly requiring it during the application startup:
52
52
 
53
53
  ```ruby
@@ -55,12 +55,12 @@ on Rails application by explicitly requiring it during the application startup:
55
55
  require "google/cloud/debugger/rails"
56
56
  ```
57
57
 
58
- If you're using the `stackdriver` gem, it automatically loads the Railtie into
58
+ If you're using the `stackdriver` gem, it automatically loads the Railtie into
59
59
  your application when it starts.
60
60
 
61
61
  ### With other Rack-based frameworks
62
62
 
63
- Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
63
+ Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
64
64
  provided by the library:
65
65
 
66
66
  ```ruby
@@ -80,66 +80,66 @@ Google::Cloud::Debugger.new.start
80
80
 
81
81
  ### Configuring the agent
82
82
 
83
- You can customize the behavior of the Stackdriver Debugger agent. See the
84
- [agent configuration](../stackdriver/docs/configuration.md) for a list of
83
+ You can customize the behavior of the Stackdriver Debugger agent. See the
84
+ [agent configuration](../stackdriver/docs/configuration.md) for a list of
85
85
  possible configuration options.
86
86
 
87
87
  ## Running on Google Cloud Platform
88
88
 
89
- The Stackdriver Debugger agent should work without you manually providing
90
- authentication credentials for instances running on Google Cloud Platform, as
89
+ The Stackdriver Debugger agent should work without you manually providing
90
+ authentication credentials for instances running on Google Cloud Platform, as
91
91
  long as the Stackdriver Debugger API access scope is enabled on that instance.
92
92
 
93
93
  ### App Engine
94
94
 
95
- On Google App Engine, the Stackdriver Debugger API access scope is enabled by
96
- default, and the Stackdriver Debugger agent can be used without providing
95
+ On Google App Engine, the Stackdriver Debugger API access scope is enabled by
96
+ default, and the Stackdriver Debugger agent can be used without providing
97
97
  credentials or a project ID.
98
98
 
99
99
  ### Container Engine
100
100
 
101
- On Google Container Engine, you must explicitly add the `cloud_debugger` OAuth
101
+ On Google Container Engine, you must explicitly add the `cloud_debugger` OAuth
102
102
  scope when creating the cluster:
103
103
 
104
104
  ```sh
105
105
  $ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud_debugger
106
106
  ```
107
107
 
108
- You can also do this through the Google Cloud Platform Console. Select
108
+ You can also do this through the Google Cloud Platform Console. Select
109
109
  **Enabled** in the Cloud Platform section of **Create a container cluster**.
110
110
 
111
111
  ### Compute Engine
112
112
 
113
- To use Stackdriver Debugger, Compute Engine VM instances should have one of the
114
- following access scopes. These are only relevant when you use Compute Engine's
113
+ To use Stackdriver Debugger, Compute Engine VM instances should have one of the
114
+ following access scopes. These are only relevant when you use Compute Engine's
115
115
  default service account:
116
116
 
117
117
  * `https://www.googleapis.com/auth/cloud-platform`
118
118
  * `https://www.googleapis.com/auth/cloud_debugger`
119
119
 
120
- The `cloud-platform` access scope can be supplied when creating a new instance
121
- through the Google Cloud Platform Console. Select **Allow full access to all
122
- Cloud APIs** in the **Identity and API access** section of **Create an
120
+ The `cloud-platform` access scope can be supplied when creating a new instance
121
+ through the Google Cloud Platform Console. Select **Allow full access to all
122
+ Cloud APIs** in the **Identity and API access** section of **Create an
123
123
  instance**.
124
124
 
125
- The `cloud_debugger` access scope must be supplied manually using the SDK's
126
- `gcloud compute instances create` command or the `gcloud compute instances
125
+ The `cloud_debugger` access scope must be supplied manually using the SDK's
126
+ `gcloud compute instances create` command or the `gcloud compute instances
127
127
  set-service-account` command.
128
128
 
129
129
  ## Running locally and elsewhere
130
130
 
131
- To run the Stackdriver Debugger agent outside of Google Cloud Platform, you must
132
- supply your GCP project ID and appropriate service account credentials directly
133
- to the Stackdriver Debugger agent. This applies to running the agent on your own
134
- workstation, on your datacenter's computers, or on the VM instances of another
135
- cloud provider. See the [Authentication section](#authentication) for
131
+ To run the Stackdriver Debugger agent outside of Google Cloud Platform, you must
132
+ supply your GCP project ID and appropriate service account credentials directly
133
+ to the Stackdriver Debugger agent. This applies to running the agent on your own
134
+ workstation, on your datacenter's computers, or on the VM instances of another
135
+ cloud provider. See the [Authentication section](#authentication) for
136
136
  instructions on how to do so.
137
137
 
138
138
  ## Authentication
139
139
 
140
140
  This library uses Service Account credentials to connect to Google Cloud
141
- services. When running on Compute Engine the credentials will be discovered
142
- automatically. When running on other environments the Service Account
141
+ services. When running on Compute Engine the credentials will be discovered
142
+ automatically. When running on other environments the Service Account
143
143
  credentials can be specified by providing in several ways.
144
144
 
145
145
  The best way to provide authentication information if you're using Ruby on Rails
@@ -159,7 +159,7 @@ end
159
159
 
160
160
  Other Rack-based applications that are loading the Rack Middleware directly can use
161
161
  the configration interface:
162
-
162
+
163
163
  ```ruby
164
164
  require "google/cloud/debugger"
165
165
  Google::Cloud.configure do |config|
@@ -177,11 +177,11 @@ Or provide the parameters to the Stackdriver Debugger agent when it starts:
177
177
  ```ruby
178
178
  require "google/cloud/debugger"
179
179
  Google::Cloud::Debugger.new(project_id: "your-project-id",
180
- keyfile: "/path/to/key.json").start
180
+ credentials: "/path/to/key.json").start
181
181
  ```
182
182
 
183
- This library also supports the other authentication methods provided by the
184
- `google-cloud-ruby` suite. Instructions and configuration options are covered
183
+ This library also supports the other authentication methods provided by the
184
+ `google-cloud-ruby` suite. Instructions and configuration options are covered
185
185
  in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/authentication).
186
186
 
187
187
  ## Supported Ruby Versions
@@ -13,9 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  ##
16
- # This file is here to be autorequired by bundler, so that the .debugger and
17
- # #debugger methods can be available, but the library and all dependencies won't
18
- # be loaded until required and used.
16
+ # This file is here to be autorequired by bundler, so that the
17
+ # Google::Cloud.debugger and Google::Cloud#debugger methods can be available,
18
+ # but the library and all dependencies won't be loaded until required and used.
19
19
 
20
20
 
21
21
  gem "google-cloud-core"
@@ -81,10 +81,12 @@ module Google
81
81
  # For more information on connecting to Google Cloud see the [Authentication
82
82
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
83
83
  #
84
- # @param [String] project Project identifier for the Stackdriver Debugger
85
- # service you are connecting to.
86
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
87
- # file path the file must be readable.
84
+ # @param [String] project_id Project identifier for the Stackdriver Debugger
85
+ # service you are connecting to. If not present, the default project for
86
+ # the credentials is used.
87
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
88
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
89
+ # Google::Auth::Credentials object. (See {Debugger::Credentials})
88
90
  # @param [String] service_name Name for the debuggee application. Optional.
89
91
  # @param [String] service_version Version identifier for the debuggee
90
92
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
@@ -108,11 +110,12 @@ module Google
108
110
  #
109
111
  # debugger.start
110
112
  #
111
- def self.debugger project = nil, keyfile = nil, service_name: nil,
113
+ def self.debugger project_id = nil, credentials = nil, service_name: nil,
112
114
  service_version: nil, scope: nil, timeout: nil,
113
115
  client_config: nil
114
116
  require "google/cloud/debugger"
115
- Google::Cloud::Debugger.new project: project, keyfile: keyfile,
117
+ Google::Cloud::Debugger.new project_id: project_id,
118
+ credentials: credentials,
116
119
  service_name: service_name,
117
120
  service_version: service_version,
118
121
  scope: scope, timeout: timeout,
@@ -339,10 +339,12 @@ module Google
339
339
  # [Authentication
340
340
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
341
341
  #
342
- # @param [String] project Project identifier for the Stackdriver Debugger
343
- # service.
344
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud:
345
- # either the JSON data or the path to a readable file.
342
+ # @param [String] project_id Project identifier for the Stackdriver
343
+ # Debugger service you are connecting to. If not present, the default
344
+ # project for the credentials is used.
345
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
346
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
347
+ # Google::Auth::Credentials object. (See {Debugger::Credentials})
346
348
  # @param [String] service_name Name for the debuggee application.
347
349
  # Optional.
348
350
  # @param [String] service_version Version identifier for the debuggee
@@ -353,6 +355,10 @@ module Google
353
355
  # APIs](https://developers.google.com/identity/protocols/OAuth2).
354
356
  # The default scope is `https://www.googleapis.com/auth/cloud-platform`
355
357
  # @param [Integer] timeout Default timeout to use in requests. Optional.
358
+ # @param [String] project Project identifier for the Stackdriver Debugger
359
+ # service.
360
+ # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud:
361
+ # either the JSON data or the path to a readable file.
356
362
  #
357
363
  # @return [Google::Cloud::Debugger::Project]
358
364
  #
@@ -362,32 +368,32 @@ module Google
362
368
  # debugger = Google::Cloud::Debugger.new
363
369
  # debugger.start
364
370
  #
365
- def self.new project: nil, keyfile: nil, service_name: nil,
371
+ def self.new project_id: nil, credentials: nil, service_name: nil,
366
372
  service_version: nil, scope: nil, timeout: nil,
367
- client_config: nil
368
- project ||= Debugger::Project.default_project
369
- project = project.to_s # Always cast to a string
373
+ client_config: nil, project: nil, keyfile: nil
374
+ project_id ||= (project || Debugger::Project.default_project_id)
375
+ project_id = project_id.to_s # Always cast to a string
370
376
  service_name ||= Debugger::Project.default_service_name
371
377
  service_name = service_name.to_s
372
378
  service_version ||= Debugger::Project.default_service_version
373
379
  service_version = service_version.to_s
374
380
 
375
- fail ArgumentError, "project is missing" if project.empty?
381
+ fail ArgumentError, "project_id is missing" if project_id.empty?
376
382
  fail ArgumentError, "service_name is missing" if service_name.empty?
377
383
  fail ArgumentError, "service_version is missing" if service_version.nil?
378
384
 
379
- credentials = Credentials.credentials_with_scope keyfile, scope
385
+ credentials ||= (keyfile || Debugger::Credentials.default(scope: scope))
386
+ unless credentials.is_a? Google::Auth::Credentials
387
+ credentials = Debugger::Credentials.new credentials, scope: scope
388
+ end
380
389
 
381
- Google::Cloud::Debugger::Project.new(
382
- Google::Cloud::Debugger::Service.new(
383
- project, credentials, timeout: timeout,
384
- client_config: client_config),
390
+ Debugger::Project.new(
391
+ Debugger::Service.new(project_id, credentials,
392
+ timeout: timeout, client_config: client_config),
385
393
  service_name: service_name,
386
- service_version: service_version
387
- )
394
+ service_version: service_version)
388
395
  end
389
396
 
390
-
391
397
  ##
392
398
  # Configure the Stackdriver Debugger agent.
393
399
  #
@@ -13,29 +13,46 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/credentials"
16
+ require "googleauth"
17
+ require "google/cloud/logging/credentials"
17
18
 
18
19
  module Google
19
20
  module Cloud
20
21
  module Debugger
21
22
  ##
22
- # @private Represents the OAuth 2.0 signing logic for Debugger.
23
- class Credentials < Google::Cloud::Credentials
23
+ # # Credentials
24
+ #
25
+ # Represents the authentication and authorization used to connect to the
26
+ # Stackdriver Debugger service.
27
+ #
28
+ # @example
29
+ # require "google/cloud/debugger"
30
+ #
31
+ # keyfile = "/path/to/keyfile.json"
32
+ # creds = Google::Cloud::Debugger::Credentials.new keyfile
33
+ #
34
+ # debugger = Google::Cloud::Debugger.new(
35
+ # project_id: "my-project",
36
+ # credentials: creds
37
+ # )
38
+ #
39
+ # debugger.project_id #=> "my-project"
40
+ #
41
+ class Credentials < Google::Auth::Credentials
24
42
  SCOPE = ["https://www.googleapis.com/auth/cloud_debugger"] +
25
43
  Google::Cloud::Logging::Credentials::SCOPE
26
- PATH_ENV_VARS = %w(DEBUGGER_KEYFILE GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE)
27
- JSON_ENV_VARS = %w(DEBUGGER_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON
44
+ PATH_ENV_VARS = %w(DEBUGGER_CREDENTIALS
45
+ GOOGLE_CLOUD_CREDENTIALS
46
+ DEBUGGER_KEYFILE
47
+ GOOGLE_CLOUD_KEYFILE
48
+ GCLOUD_KEYFILE)
49
+ JSON_ENV_VARS = %w(DEBUGGER_CREDENTIALS_JSON
50
+ GOOGLE_CLOUD_CREDENTIALS_JSON
51
+ DEBUGGER_KEYFILE_JSON
52
+ GOOGLE_CLOUD_KEYFILE_JSON
28
53
  GCLOUD_KEYFILE_JSON)
29
-
30
- ##
31
- # @private Create credentials with given scope and/or keyfile
32
- def self.credentials_with_scope keyfile, scope = nil
33
- if keyfile.nil?
34
- default(scope: scope)
35
- else
36
- new(keyfile, scope: scope)
37
- end
38
- end
54
+ DEFAULT_PATHS = \
55
+ ["~/.config/gcloud/application_default_credentials.json"]
39
56
  end
40
57
  end
41
58
  end
@@ -17,6 +17,7 @@ require "digest/sha1"
17
17
  require "google/cloud/debugger/backoff"
18
18
  require "google/cloud/debugger/debuggee/app_uniquifier_generator"
19
19
  require "google/cloud/debugger/version"
20
+ require "google/cloud/env"
20
21
  require "json"
21
22
 
22
23
  module Google
@@ -68,6 +69,7 @@ module Google
68
69
  @service = service
69
70
  @service_name = service_name
70
71
  @service_version = service_version
72
+ @env = Google::Cloud.env
71
73
  @computed_uniquifier = nil
72
74
  @id = nil
73
75
  @register_backoff = Google::Cloud::Debugger::Backoff.new
@@ -123,7 +125,7 @@ module Google
123
125
  # @private Build the parameters for this debuggee
124
126
  def build_request_arg
125
127
  debuggee_args = {
126
- project: project_id,
128
+ project: project_id_for_request_arg,
127
129
  description: description,
128
130
  labels: labels,
129
131
  agent_version: agent_version
@@ -177,6 +179,19 @@ module Google
177
179
  service.project
178
180
  end
179
181
 
182
+ ##
183
+ # @private
184
+ # Get project to send as a debuggee argument. This is the numeric
185
+ # project ID if available (and if it matches the project set in the
186
+ # configuration). Otherwise, use the configured project.
187
+ def project_id_for_request_arg
188
+ if project_id == @env.project_id
189
+ numeric_id = @env.numeric_project_id
190
+ return numeric_id.to_s if numeric_id
191
+ end
192
+ project_id
193
+ end
194
+
180
195
  ##
181
196
  # @private Build debuggee agent version identifier
182
197
  def agent_version
@@ -116,7 +116,7 @@ module Google
116
116
  # Fallback to default configuration values if not defined already
117
117
  def init_default_config
118
118
  configuration.project_id ||= Cloud.configure.project_id ||
119
- Debugger::Project.default_project
119
+ Debugger::Project.default_project_id
120
120
  configuration.keyfile ||= Cloud.configure.keyfile
121
121
 
122
122
  configuration.service_name ||= Debugger::Project.default_service_name
@@ -65,19 +65,20 @@ module Google
65
65
  # require "google/cloud/debugger"
66
66
  #
67
67
  # debugger = Google::Cloud::Debugger.new(
68
- # project: "my-project",
69
- # keyfile: "/path/to/keyfile.json"
68
+ # project_id: "my-project",
69
+ # credentials: "/path/to/keyfile.json"
70
70
  # )
71
71
  #
72
- # debugger.project #=> "my-project"
72
+ # debugger.project_id #=> "my-project"
73
73
  #
74
- def project
74
+ def project_id
75
75
  service.project
76
76
  end
77
+ alias_method :project, :project_id
77
78
 
78
79
  ##
79
80
  # @private Default project.
80
- def self.default_project
81
+ def self.default_project_id
81
82
  ENV["DEBUGGER_PROJECT"] ||
82
83
  ENV["GOOGLE_CLOUD_PROJECT"] ||
83
84
  ENV["GCLOUD_PROJECT"] ||
@@ -110,16 +110,22 @@ module Google
110
110
  # Fallback to default config values if config parameters not provided.
111
111
  def self.init_default_config
112
112
  config = Debugger.configure
113
- config.project_id ||= Debugger::Project.default_project
113
+ config.project_id ||= Debugger::Project.default_project_id
114
114
  config.service_name ||= Debugger::Project.default_service_name
115
115
  config.service_version ||= Debugger::Project.default_service_version
116
116
  end
117
117
 
118
118
  ##
119
119
  # @private Verify credentials
120
- def self.valid_credentials? project_id, keyfile
120
+ def self.valid_credentials? project_id, credentials
121
121
  begin
122
- Debugger::Credentials.credentials_with_scope keyfile
122
+ # if credentials is nil, get default
123
+ credentials ||= Debugger::Credentials.default(scope: scope)
124
+ # only create a new Credentials object if the val isn't one already
125
+ unless credentials.is_a? Google::Auth::Credentials
126
+ # if credentials is not a Credentials object, create one
127
+ Debugger::Credentials.new credentials, scope: scope
128
+ end
123
129
  rescue => e
124
130
  STDOUT.puts "Note: Google::Cloud::Debugger is disabled because " \
125
131
  "it failed to authorize with the service. (#{e.message})"