google-cloud-asset 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,370 @@
1
+ # Copyright 2018 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
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/cloud/asset/v1beta1/asset_service.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+
22
+
23
+ require "json"
24
+ require "pathname"
25
+
26
+ require "google/gax"
27
+ require "google/gax/operation"
28
+ require "google/longrunning/operations_client"
29
+
30
+ require "google/cloud/asset/v1beta1/asset_service_pb"
31
+ require "google/cloud/asset/v1beta1/credentials"
32
+
33
+ module Google
34
+ module Cloud
35
+ module Asset
36
+ module V1beta1
37
+ # Asset service definition.
38
+ #
39
+ # @!attribute [r] asset_service_stub
40
+ # @return [Google::Cloud::Asset::V1beta1::AssetService::Stub]
41
+ class AssetServiceClient
42
+ # @private
43
+ attr_reader :asset_service_stub
44
+
45
+ # The default address of the service.
46
+ SERVICE_ADDRESS = "cloudasset.googleapis.com".freeze
47
+
48
+ # The default port of the service.
49
+ DEFAULT_SERVICE_PORT = 443
50
+
51
+ # The default set of gRPC interceptors.
52
+ GRPC_INTERCEPTORS = []
53
+
54
+ DEFAULT_TIMEOUT = 30
55
+
56
+ # The scopes needed to make gRPC calls to all of the methods defined in
57
+ # this service.
58
+ ALL_SCOPES = [
59
+ "https://www.googleapis.com/auth/cloud-platform"
60
+ ].freeze
61
+
62
+ # @private
63
+ class OperationsClient < Google::Longrunning::OperationsClient
64
+ self::SERVICE_ADDRESS = AssetServiceClient::SERVICE_ADDRESS
65
+ self::GRPC_INTERCEPTORS = AssetServiceClient::GRPC_INTERCEPTORS
66
+ end
67
+
68
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
69
+ "projects/{project}"
70
+ )
71
+
72
+ private_constant :PROJECT_PATH_TEMPLATE
73
+
74
+ # Returns a fully-qualified project resource name string.
75
+ # @param project [String]
76
+ # @return [String]
77
+ def self.project_path project
78
+ PROJECT_PATH_TEMPLATE.render(
79
+ :"project" => project
80
+ )
81
+ end
82
+
83
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
84
+ # Provides the means for authenticating requests made by the client. This parameter can
85
+ # be many types.
86
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
87
+ # authenticating requests made by this client.
88
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
89
+ # credentials for this client.
90
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
91
+ # credentials for this client.
92
+ # A `GRPC::Core::Channel` will be used to make calls through.
93
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
94
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
95
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
96
+ # metadata for requests, generally, to give OAuth credentials.
97
+ # @param scopes [Array<String>]
98
+ # The OAuth scopes for this service. This parameter is ignored if
99
+ # an updater_proc is supplied.
100
+ # @param client_config [Hash]
101
+ # A Hash for call options for each method. See
102
+ # Google::Gax#construct_settings for the structure of
103
+ # this data. Falls back to the default config if not specified
104
+ # or the specified config is missing data points.
105
+ # @param timeout [Numeric]
106
+ # The default timeout, in seconds, for calls made through this client.
107
+ # @param metadata [Hash]
108
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
109
+ # @param exception_transformer [Proc]
110
+ # An optional proc that intercepts any exceptions raised during an API call to inject
111
+ # custom error handling.
112
+ def initialize \
113
+ credentials: nil,
114
+ scopes: ALL_SCOPES,
115
+ client_config: {},
116
+ timeout: DEFAULT_TIMEOUT,
117
+ metadata: nil,
118
+ exception_transformer: nil,
119
+ lib_name: nil,
120
+ lib_version: ""
121
+ # These require statements are intentionally placed here to initialize
122
+ # the gRPC module only when it's required.
123
+ # See https://github.com/googleapis/toolkit/issues/446
124
+ require "google/gax/grpc"
125
+ require "google/cloud/asset/v1beta1/asset_service_services_pb"
126
+
127
+ credentials ||= Google::Cloud::Asset::V1beta1::Credentials.default
128
+
129
+ @operations_client = OperationsClient.new(
130
+ credentials: credentials,
131
+ scopes: scopes,
132
+ client_config: client_config,
133
+ timeout: timeout,
134
+ lib_name: lib_name,
135
+ lib_version: lib_version,
136
+ )
137
+
138
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
139
+ updater_proc = Google::Cloud::Asset::V1beta1::Credentials.new(credentials).updater_proc
140
+ end
141
+ if credentials.is_a?(GRPC::Core::Channel)
142
+ channel = credentials
143
+ end
144
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
145
+ chan_creds = credentials
146
+ end
147
+ if credentials.is_a?(Proc)
148
+ updater_proc = credentials
149
+ end
150
+ if credentials.is_a?(Google::Auth::Credentials)
151
+ updater_proc = credentials.updater_proc
152
+ end
153
+
154
+ package_version = Gem.loaded_specs['google-cloud-asset'].version.version
155
+
156
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
157
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
158
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
159
+ google_api_client << " grpc/#{GRPC::VERSION}"
160
+ google_api_client.freeze
161
+
162
+ headers = { :"x-goog-api-client" => google_api_client }
163
+ headers.merge!(metadata) unless metadata.nil?
164
+ client_config_file = Pathname.new(__dir__).join(
165
+ "asset_service_client_config.json"
166
+ )
167
+ defaults = client_config_file.open do |f|
168
+ Google::Gax.construct_settings(
169
+ "google.cloud.asset.v1beta1.AssetService",
170
+ JSON.parse(f.read),
171
+ client_config,
172
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
173
+ timeout,
174
+ errors: Google::Gax::Grpc::API_ERRORS,
175
+ metadata: headers
176
+ )
177
+ end
178
+
179
+ # Allow overriding the service path/port in subclasses.
180
+ service_path = self.class::SERVICE_ADDRESS
181
+ port = self.class::DEFAULT_SERVICE_PORT
182
+ interceptors = self.class::GRPC_INTERCEPTORS
183
+ @asset_service_stub = Google::Gax::Grpc.create_stub(
184
+ service_path,
185
+ port,
186
+ chan_creds: chan_creds,
187
+ channel: channel,
188
+ updater_proc: updater_proc,
189
+ scopes: scopes,
190
+ interceptors: interceptors,
191
+ &Google::Cloud::Asset::V1beta1::AssetService::Stub.method(:new)
192
+ )
193
+
194
+ @export_assets = Google::Gax.create_api_call(
195
+ @asset_service_stub.method(:export_assets),
196
+ defaults["export_assets"],
197
+ exception_transformer: exception_transformer
198
+ )
199
+ @batch_get_assets_history = Google::Gax.create_api_call(
200
+ @asset_service_stub.method(:batch_get_assets_history),
201
+ defaults["batch_get_assets_history"],
202
+ exception_transformer: exception_transformer
203
+ )
204
+ end
205
+
206
+ # Service calls
207
+
208
+ # Exports assets with time and resource types to a given Cloud Storage
209
+ # location. The output format is newline-delimited JSON.
210
+ # This API implements the {Google::Longrunning::Operation} API allowing you
211
+ # to keep track of the export.
212
+ #
213
+ # @param parent [String]
214
+ # Required. The relative name of the root asset. This can only be an organization
215
+ # number (such as "organizations/123"), a project ID (such as
216
+ # "projects/my-project-id"), or a project number (such as "projects/12345").
217
+ # @param output_config [Google::Cloud::Asset::V1beta1::OutputConfig | Hash]
218
+ # Required. Output configuration indicating where the results will be output
219
+ # to. All results will be in newline delimited JSON format.
220
+ # A hash of the same form as `Google::Cloud::Asset::V1beta1::OutputConfig`
221
+ # can also be provided.
222
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
223
+ # Timestamp to take an asset snapshot. This can only be set to a timestamp in
224
+ # the past or of the current time. If not specified, the current time will be
225
+ # used. Due to delays in resource data collection and indexing, there is a
226
+ # volatile window during which running the same query may get different
227
+ # results.
228
+ # A hash of the same form as `Google::Protobuf::Timestamp`
229
+ # can also be provided.
230
+ # @param asset_types [Array<String>]
231
+ # A list of asset types of which to take a snapshot for. For example:
232
+ # "google.compute.disk". If specified, only matching assets will be returned.
233
+ # @param content_type [Google::Cloud::Asset::V1beta1::ContentType]
234
+ # Asset content type. If not specified, no content but the asset name will be
235
+ # returned.
236
+ # @param options [Google::Gax::CallOptions]
237
+ # Overrides the default settings for this call, e.g, timeout,
238
+ # retries, etc.
239
+ # @return [Google::Gax::Operation]
240
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
241
+ # @example
242
+ # require "google/cloud/asset"
243
+ #
244
+ # asset_service_client = Google::Cloud::Asset.new(version: :v1beta1)
245
+ # formatted_parent = Google::Cloud::Asset::V1beta1::AssetServiceClient.project_path("[PROJECT]")
246
+ #
247
+ # # TODO: Initialize `output_config`:
248
+ # output_config = {}
249
+ #
250
+ # # Register a callback during the method call.
251
+ # operation = asset_service_client.export_assets(formatted_parent, output_config) do |op|
252
+ # raise op.results.message if op.error?
253
+ # op_results = op.results
254
+ # # Process the results.
255
+ #
256
+ # metadata = op.metadata
257
+ # # Process the metadata.
258
+ # end
259
+ #
260
+ # # Or use the return value to register a callback.
261
+ # operation.on_done do |op|
262
+ # raise op.results.message if op.error?
263
+ # op_results = op.results
264
+ # # Process the results.
265
+ #
266
+ # metadata = op.metadata
267
+ # # Process the metadata.
268
+ # end
269
+ #
270
+ # # Manually reload the operation.
271
+ # operation.reload!
272
+ #
273
+ # # Or block until the operation completes, triggering callbacks on
274
+ # # completion.
275
+ # operation.wait_until_done!
276
+
277
+ def export_assets \
278
+ parent,
279
+ output_config,
280
+ read_time: nil,
281
+ asset_types: nil,
282
+ content_type: nil,
283
+ options: nil
284
+ req = {
285
+ parent: parent,
286
+ output_config: output_config,
287
+ read_time: read_time,
288
+ asset_types: asset_types,
289
+ content_type: content_type
290
+ }.delete_if { |_, v| v.nil? }
291
+ req = Google::Gax::to_proto(req, Google::Cloud::Asset::V1beta1::ExportAssetsRequest)
292
+ operation = Google::Gax::Operation.new(
293
+ @export_assets.call(req, options),
294
+ @operations_client,
295
+ Google::Cloud::Asset::V1beta1::ExportAssetsResponse,
296
+ Google::Cloud::Asset::V1beta1::ExportAssetsRequest,
297
+ call_options: options
298
+ )
299
+ operation.on_done { |operation| yield(operation) } if block_given?
300
+ operation
301
+ end
302
+
303
+ # Batch gets the update history of assets that overlap a time window.
304
+ # For RESOURCE content, this API outputs history with asset in both
305
+ # non-delete or deleted status.
306
+ # For IAM_POLICY content, this API outputs history when the asset and its
307
+ # attached IAM POLICY both exist. This can create gaps in the output history.
308
+ #
309
+ # @param parent [String]
310
+ # Required. The relative name of the root asset. It can only be an
311
+ # organization number (such as "organizations/123"), a project ID (such as
312
+ # "projects/my-project-id")", or a project number (such as "projects/12345").
313
+ # @param content_type [Google::Cloud::Asset::V1beta1::ContentType]
314
+ # Required. The content type.
315
+ # @param read_time_window [Google::Cloud::Asset::V1beta1::TimeWindow | Hash]
316
+ # Required. The time window for the asset history. The start time is
317
+ # required. The returned results contain all temporal assets whose time
318
+ # window overlap with read_time_window.
319
+ # A hash of the same form as `Google::Cloud::Asset::V1beta1::TimeWindow`
320
+ # can also be provided.
321
+ # @param asset_names [Array<String>]
322
+ # A list of the full names of the assets. For example:
323
+ # `//compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1`.
324
+ # See [Resource Names](https://cloud.google.com/apis/design/resource_names#full_resource_name)
325
+ # for more info.
326
+ #
327
+ # The request becomes a no-op if the asset name list is empty, and the max
328
+ # size of the asset name list is 100 in one request.
329
+ # @param options [Google::Gax::CallOptions]
330
+ # Overrides the default settings for this call, e.g, timeout,
331
+ # retries, etc.
332
+ # @yield [result, operation] Access the result along with the RPC operation
333
+ # @yieldparam result [Google::Cloud::Asset::V1beta1::BatchGetAssetsHistoryResponse]
334
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
335
+ # @return [Google::Cloud::Asset::V1beta1::BatchGetAssetsHistoryResponse]
336
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
337
+ # @example
338
+ # require "google/cloud/asset"
339
+ #
340
+ # asset_service_client = Google::Cloud::Asset.new(version: :v1beta1)
341
+ # formatted_parent = Google::Cloud::Asset::V1beta1::AssetServiceClient.project_path("[PROJECT]")
342
+ #
343
+ # # TODO: Initialize `content_type`:
344
+ # content_type = :CONTENT_TYPE_UNSPECIFIED
345
+ #
346
+ # # TODO: Initialize `read_time_window`:
347
+ # read_time_window = {}
348
+ # response = asset_service_client.batch_get_assets_history(formatted_parent, content_type, read_time_window)
349
+
350
+ def batch_get_assets_history \
351
+ parent,
352
+ content_type,
353
+ read_time_window,
354
+ asset_names: nil,
355
+ options: nil,
356
+ &block
357
+ req = {
358
+ parent: parent,
359
+ content_type: content_type,
360
+ read_time_window: read_time_window,
361
+ asset_names: asset_names
362
+ }.delete_if { |_, v| v.nil? }
363
+ req = Google::Gax::to_proto(req, Google::Cloud::Asset::V1beta1::BatchGetAssetsHistoryRequest)
364
+ @batch_get_assets_history.call(req, options, &block)
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
@@ -0,0 +1,36 @@
1
+ {
2
+ "interfaces": {
3
+ "google.cloud.asset.v1beta1.AssetService": {
4
+ "retry_codes": {
5
+ "idempotent": [
6
+ "DEADLINE_EXCEEDED",
7
+ "UNAVAILABLE"
8
+ ],
9
+ "non_idempotent": []
10
+ },
11
+ "retry_params": {
12
+ "default": {
13
+ "initial_retry_delay_millis": 100,
14
+ "retry_delay_multiplier": 1.3,
15
+ "max_retry_delay_millis": 60000,
16
+ "initial_rpc_timeout_millis": 20000,
17
+ "rpc_timeout_multiplier": 1.0,
18
+ "max_rpc_timeout_millis": 20000,
19
+ "total_timeout_millis": 600000
20
+ }
21
+ },
22
+ "methods": {
23
+ "ExportAssets": {
24
+ "timeout_millis": 600000,
25
+ "retry_codes_name": "non_idempotent",
26
+ "retry_params_name": "default"
27
+ },
28
+ "BatchGetAssetsHistory": {
29
+ "timeout_millis": 600000,
30
+ "retry_codes_name": "idempotent",
31
+ "retry_params_name": "default"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,61 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/cloud/asset/v1beta1/asset_service.proto
3
+
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'google/api/annotations_pb'
8
+ require 'google/cloud/asset/v1beta1/assets_pb'
9
+ require 'google/longrunning/operations_pb'
10
+ require 'google/protobuf/timestamp_pb'
11
+ Google::Protobuf::DescriptorPool.generated_pool.build do
12
+ add_message "google.cloud.asset.v1beta1.ExportAssetsRequest" do
13
+ optional :parent, :string, 1
14
+ optional :read_time, :message, 2, "google.protobuf.Timestamp"
15
+ repeated :asset_types, :string, 3
16
+ optional :content_type, :enum, 4, "google.cloud.asset.v1beta1.ContentType"
17
+ optional :output_config, :message, 5, "google.cloud.asset.v1beta1.OutputConfig"
18
+ end
19
+ add_message "google.cloud.asset.v1beta1.ExportAssetsResponse" do
20
+ optional :read_time, :message, 1, "google.protobuf.Timestamp"
21
+ optional :output_config, :message, 2, "google.cloud.asset.v1beta1.OutputConfig"
22
+ end
23
+ add_message "google.cloud.asset.v1beta1.BatchGetAssetsHistoryRequest" do
24
+ optional :parent, :string, 1
25
+ repeated :asset_names, :string, 2
26
+ optional :content_type, :enum, 3, "google.cloud.asset.v1beta1.ContentType"
27
+ optional :read_time_window, :message, 4, "google.cloud.asset.v1beta1.TimeWindow"
28
+ end
29
+ add_message "google.cloud.asset.v1beta1.BatchGetAssetsHistoryResponse" do
30
+ repeated :assets, :message, 1, "google.cloud.asset.v1beta1.TemporalAsset"
31
+ end
32
+ add_message "google.cloud.asset.v1beta1.OutputConfig" do
33
+ oneof :destination do
34
+ optional :gcs_destination, :message, 1, "google.cloud.asset.v1beta1.GcsDestination"
35
+ end
36
+ end
37
+ add_message "google.cloud.asset.v1beta1.GcsDestination" do
38
+ optional :uri, :string, 1
39
+ end
40
+ add_enum "google.cloud.asset.v1beta1.ContentType" do
41
+ value :CONTENT_TYPE_UNSPECIFIED, 0
42
+ value :RESOURCE, 1
43
+ value :IAM_POLICY, 2
44
+ end
45
+ end
46
+
47
+ module Google
48
+ module Cloud
49
+ module Asset
50
+ module V1beta1
51
+ ExportAssetsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.ExportAssetsRequest").msgclass
52
+ ExportAssetsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.ExportAssetsResponse").msgclass
53
+ BatchGetAssetsHistoryRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.BatchGetAssetsHistoryRequest").msgclass
54
+ BatchGetAssetsHistoryResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.BatchGetAssetsHistoryResponse").msgclass
55
+ OutputConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.OutputConfig").msgclass
56
+ GcsDestination = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.GcsDestination").msgclass
57
+ ContentType = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.asset.v1beta1.ContentType").enummodule
58
+ end
59
+ end
60
+ end
61
+ end