google-cloud-webrisk 0.1.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.
@@ -0,0 +1,41 @@
1
+ # Copyright 2019 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 "googleauth"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Webrisk
21
+ module V1beta1
22
+ class Credentials < Google::Auth::Credentials
23
+ SCOPE = [
24
+ "https://www.googleapis.com/auth/cloud-platform"
25
+ ].freeze
26
+ PATH_ENV_VARS = %w(WEBRISK_CREDENTIALS
27
+ WEBRISK_KEYFILE
28
+ GOOGLE_CLOUD_CREDENTIALS
29
+ GOOGLE_CLOUD_KEYFILE
30
+ GCLOUD_KEYFILE)
31
+ JSON_ENV_VARS = %w(WEBRISK_CREDENTIALS_JSON
32
+ WEBRISK_KEYFILE_JSON
33
+ GOOGLE_CLOUD_CREDENTIALS_JSON
34
+ GOOGLE_CLOUD_KEYFILE_JSON
35
+ GCLOUD_KEYFILE_JSON)
36
+ DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,258 @@
1
+ # Copyright 2019 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
+ module Google
17
+ module Cloud
18
+ module Webrisk
19
+ module V1beta1
20
+ # Describes an API diff request.
21
+ # @!attribute [rw] threat_type
22
+ # @return [Google::Cloud::Webrisk::V1beta1::ThreatType]
23
+ # Required. The ThreatList to update.
24
+ # @!attribute [rw] version_token
25
+ # @return [String]
26
+ # The current version token of the client for the requested list (the
27
+ # client version that was received from the last successful diff).
28
+ # @!attribute [rw] constraints
29
+ # @return [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffRequest::Constraints]
30
+ # The constraints associated with this request.
31
+ class ComputeThreatListDiffRequest
32
+ # The constraints for this diff.
33
+ # @!attribute [rw] max_diff_entries
34
+ # @return [Integer]
35
+ # The maximum size in number of entries. The diff will not contain more
36
+ # entries than this value. This should be a power of 2 between 2**10 and
37
+ # 2**20. If zero, no diff size limit is set.
38
+ # @!attribute [rw] max_database_entries
39
+ # @return [Integer]
40
+ # Sets the maximum number of entries that the client is willing to have
41
+ # in the local database. This should be a power of 2 between 2**10 and
42
+ # 2**20. If zero, no database size limit is set.
43
+ # @!attribute [rw] supported_compressions
44
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::CompressionType>]
45
+ # The compression types supported by the client.
46
+ class Constraints; end
47
+ end
48
+
49
+ # @!attribute [rw] response_type
50
+ # @return [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffResponse::ResponseType]
51
+ # The type of response. This may indicate that an action is required by the
52
+ # client when the response is received.
53
+ # @!attribute [rw] additions
54
+ # @return [Google::Cloud::Webrisk::V1beta1::ThreatEntryAdditions]
55
+ # A set of entries to add to a local threat type's list.
56
+ # @!attribute [rw] removals
57
+ # @return [Google::Cloud::Webrisk::V1beta1::ThreatEntryRemovals]
58
+ # A set of entries to remove from a local threat type's list.
59
+ # This field may be empty.
60
+ # @!attribute [rw] new_version_token
61
+ # @return [String]
62
+ # The new opaque client version token.
63
+ # @!attribute [rw] checksum
64
+ # @return [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffResponse::Checksum]
65
+ # The expected SHA256 hash of the client state; that is, of the sorted list
66
+ # of all hashes present in the database after applying the provided diff.
67
+ # If the client state doesn't match the expected state, the client must
68
+ # disregard this diff and retry later.
69
+ # @!attribute [rw] recommended_next_diff
70
+ # @return [Google::Protobuf::Timestamp]
71
+ # The soonest the client should wait before issuing any diff
72
+ # request. Querying sooner is unlikely to produce a meaningful diff.
73
+ # Waiting longer is acceptable considering the use case.
74
+ # If this field is not set clients may update as soon as they want.
75
+ class ComputeThreatListDiffResponse
76
+ # The expected state of a client's local database.
77
+ # @!attribute [rw] sha256
78
+ # @return [String]
79
+ # The SHA256 hash of the client state; that is, of the sorted list of all
80
+ # hashes present in the database.
81
+ class Checksum; end
82
+
83
+ # The type of response sent to the client.
84
+ module ResponseType
85
+ # Unknown.
86
+ RESPONSE_TYPE_UNSPECIFIED = 0
87
+
88
+ # Partial updates are applied to the client's existing local database.
89
+ DIFF = 1
90
+
91
+ # Full updates resets the client's entire local database. This means
92
+ # that either the client had no state, was seriously out-of-date,
93
+ # or the client is believed to be corrupt.
94
+ RESET = 2
95
+ end
96
+ end
97
+
98
+ # Request to check URI entries against threatLists.
99
+ # @!attribute [rw] uri
100
+ # @return [String]
101
+ # The URI to be checked for matches.
102
+ # @!attribute [rw] threat_types
103
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
104
+ # Required. The ThreatLists to search in.
105
+ class SearchUrisRequest; end
106
+
107
+ # @!attribute [rw] threat
108
+ # @return [Google::Cloud::Webrisk::V1beta1::SearchUrisResponse::ThreatUri]
109
+ # The threat list matches. This may be empty if the URI is on no list.
110
+ class SearchUrisResponse
111
+ # Contains threat information on a matching uri.
112
+ # @!attribute [rw] threat_types
113
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
114
+ # The ThreatList this threat belongs to.
115
+ # @!attribute [rw] expire_time
116
+ # @return [Google::Protobuf::Timestamp]
117
+ # The cache lifetime for the returned match. Clients must not cache this
118
+ # response past this timestamp to avoid false positives.
119
+ class ThreatUri; end
120
+ end
121
+
122
+ # Request to return full hashes matched by the provided hash prefixes.
123
+ # @!attribute [rw] hash_prefix
124
+ # @return [String]
125
+ # A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
126
+ # hash. For JSON requests, this field is base64-encoded.
127
+ # @!attribute [rw] threat_types
128
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
129
+ # Required. The ThreatLists to search in.
130
+ class SearchHashesRequest; end
131
+
132
+ # @!attribute [rw] threats
133
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::SearchHashesResponse::ThreatHash>]
134
+ # The full hashes that matched the requested prefixes.
135
+ # The hash will be populated in the key.
136
+ # @!attribute [rw] negative_expire_time
137
+ # @return [Google::Protobuf::Timestamp]
138
+ # For requested entities that did not match the threat list, how long to
139
+ # cache the response until.
140
+ class SearchHashesResponse
141
+ # Contains threat information on a matching hash.
142
+ # @!attribute [rw] threat_types
143
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
144
+ # The ThreatList this threat belongs to.
145
+ # This must contain at least one entry.
146
+ # @!attribute [rw] hash
147
+ # @return [String]
148
+ # A 32 byte SHA256 hash. This field is in binary format. For JSON
149
+ # requests, hashes are base64-encoded.
150
+ # @!attribute [rw] expire_time
151
+ # @return [Google::Protobuf::Timestamp]
152
+ # The cache lifetime for the returned match. Clients must not cache this
153
+ # response past this timestamp to avoid false positives.
154
+ class ThreatHash; end
155
+ end
156
+
157
+ # Contains the set of entries to add to a local database.
158
+ # May contain a combination of compressed and raw data in a single response.
159
+ # @!attribute [rw] raw_hashes
160
+ # @return [Array<Google::Cloud::Webrisk::V1beta1::RawHashes>]
161
+ # The raw SHA256-formatted entries.
162
+ # Repeated to allow returning sets of hashes with different prefix sizes.
163
+ # @!attribute [rw] rice_hashes
164
+ # @return [Google::Cloud::Webrisk::V1beta1::RiceDeltaEncoding]
165
+ # The encoded 4-byte prefixes of SHA256-formatted entries, using a
166
+ # Golomb-Rice encoding. The hashes are converted to uint32, sorted in
167
+ # ascending order, then delta encoded and stored as encoded_data.
168
+ class ThreatEntryAdditions; end
169
+
170
+ # Contains the set of entries to remove from a local database.
171
+ # @!attribute [rw] raw_indices
172
+ # @return [Google::Cloud::Webrisk::V1beta1::RawIndices]
173
+ # The raw removal indices for a local list.
174
+ # @!attribute [rw] rice_indices
175
+ # @return [Google::Cloud::Webrisk::V1beta1::RiceDeltaEncoding]
176
+ # The encoded local, lexicographically-sorted list indices, using a
177
+ # Golomb-Rice encoding. Used for sending compressed removal indices. The
178
+ # removal indices (uint32) are sorted in ascending order, then delta encoded
179
+ # and stored as encoded_data.
180
+ class ThreatEntryRemovals; end
181
+
182
+ # A set of raw indices to remove from a local list.
183
+ # @!attribute [rw] indices
184
+ # @return [Array<Integer>]
185
+ # The indices to remove from a lexicographically-sorted local list.
186
+ class RawIndices; end
187
+
188
+ # The uncompressed threat entries in hash format.
189
+ # Hashes can be anywhere from 4 to 32 bytes in size. A large majority are 4
190
+ # bytes, but some hashes are lengthened if they collide with the hash of a
191
+ # popular URI.
192
+ #
193
+ # Used for sending ThreatEntryAdditons to clients that do not support
194
+ # compression, or when sending non-4-byte hashes to clients that do support
195
+ # compression.
196
+ # @!attribute [rw] prefix_size
197
+ # @return [Integer]
198
+ # The number of bytes for each prefix encoded below. This field can be
199
+ # anywhere from 4 (shortest prefix) to 32 (full SHA256 hash).
200
+ # @!attribute [rw] raw_hashes
201
+ # @return [String]
202
+ # The hashes, in binary format, concatenated into one long string. Hashes are
203
+ # sorted in lexicographic order. For JSON API users, hashes are
204
+ # base64-encoded.
205
+ class RawHashes; end
206
+
207
+ # The Rice-Golomb encoded data. Used for sending compressed 4-byte hashes or
208
+ # compressed removal indices.
209
+ # @!attribute [rw] first_value
210
+ # @return [Integer]
211
+ # The offset of the first entry in the encoded data, or, if only a single
212
+ # integer was encoded, that single integer's value. If the field is empty or
213
+ # missing, assume zero.
214
+ # @!attribute [rw] rice_parameter
215
+ # @return [Integer]
216
+ # The Golomb-Rice parameter, which is a number between 2 and 28. This field
217
+ # is missing (that is, zero) if `num_entries` is zero.
218
+ # @!attribute [rw] entry_count
219
+ # @return [Integer]
220
+ # The number of entries that are delta encoded in the encoded data. If only a
221
+ # single integer was encoded, this will be zero and the single value will be
222
+ # stored in `first_value`.
223
+ # @!attribute [rw] encoded_data
224
+ # @return [String]
225
+ # The encoded deltas that are encoded using the Golomb-Rice coder.
226
+ class RiceDeltaEncoding; end
227
+
228
+ # The ways in which threat entry sets can be compressed.
229
+ module CompressionType
230
+ # Unknown.
231
+ COMPRESSION_TYPE_UNSPECIFIED = 0
232
+
233
+ # Raw, uncompressed data.
234
+ RAW = 1
235
+
236
+ # Rice-Golomb encoded data.
237
+ RICE = 2
238
+ end
239
+
240
+ # The type of threat. This maps dirrectly to the threat list a threat may
241
+ # belong to.
242
+ module ThreatType
243
+ # Unknown.
244
+ THREAT_TYPE_UNSPECIFIED = 0
245
+
246
+ # Malware targeting any platform.
247
+ MALWARE = 1
248
+
249
+ # Social engineering targeting any platform.
250
+ SOCIAL_ENGINEERING = 2
251
+
252
+ # Unwanted software targeting any platform.
253
+ UNWANTED_SOFTWARE = 3
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright 2019 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
+ module Google
17
+ module Protobuf
18
+ # A Timestamp represents a point in time independent of any time zone
19
+ # or calendar, represented as seconds and fractions of seconds at
20
+ # nanosecond resolution in UTC Epoch time. It is encoded using the
21
+ # Proleptic Gregorian Calendar which extends the Gregorian calendar
22
+ # backwards to year one. It is encoded assuming all minutes are 60
23
+ # seconds long, i.e. leap seconds are "smeared" so that no leap second
24
+ # table is needed for interpretation. Range is from
25
+ # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
26
+ # By restricting to that range, we ensure that we can convert to
27
+ # and from RFC 3339 date strings.
28
+ # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
29
+ #
30
+ # = Examples
31
+ #
32
+ # Example 1: Compute Timestamp from POSIX `time()`.
33
+ #
34
+ # Timestamp timestamp;
35
+ # timestamp.set_seconds(time(NULL));
36
+ # timestamp.set_nanos(0);
37
+ #
38
+ # Example 2: Compute Timestamp from POSIX `gettimeofday()`.
39
+ #
40
+ # struct timeval tv;
41
+ # gettimeofday(&tv, NULL);
42
+ #
43
+ # Timestamp timestamp;
44
+ # timestamp.set_seconds(tv.tv_sec);
45
+ # timestamp.set_nanos(tv.tv_usec * 1000);
46
+ #
47
+ # Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
48
+ #
49
+ # FILETIME ft;
50
+ # GetSystemTimeAsFileTime(&ft);
51
+ # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
52
+ #
53
+ # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
54
+ # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
55
+ # Timestamp timestamp;
56
+ # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
57
+ # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
58
+ #
59
+ # Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
60
+ #
61
+ # long millis = System.currentTimeMillis();
62
+ #
63
+ # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
64
+ # .setNanos((int) ((millis % 1000) * 1000000)).build();
65
+ #
66
+ #
67
+ # Example 5: Compute Timestamp from current time in Python.
68
+ #
69
+ # timestamp = Timestamp()
70
+ # timestamp.GetCurrentTime()
71
+ #
72
+ # = JSON Mapping
73
+ #
74
+ # In JSON format, the Timestamp type is encoded as a string in the
75
+ # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
76
+ # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
77
+ # where {year} is always expressed using four digits while {month}, {day},
78
+ # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
79
+ # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
80
+ # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
81
+ # is required. A proto3 JSON serializer should always use UTC (as indicated by
82
+ # "Z") when printing the Timestamp type and a proto3 JSON parser should be
83
+ # able to accept both UTC and other timezones (as indicated by an offset).
84
+ #
85
+ # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
86
+ # 01:30 UTC on January 15, 2017.
87
+ #
88
+ # In JavaScript, one can convert a Date object to this format using the
89
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
90
+ # method. In Python, a standard `datetime.datetime` object can be converted
91
+ # to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
92
+ # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
93
+ # can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
94
+ # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
95
+ # ) to obtain a formatter capable of generating timestamps in this format.
96
+ # @!attribute [rw] seconds
97
+ # @return [Integer]
98
+ # Represents seconds of UTC time since Unix epoch
99
+ # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
100
+ # 9999-12-31T23:59:59Z inclusive.
101
+ # @!attribute [rw] nanos
102
+ # @return [Integer]
103
+ # Non-negative fractions of a second at nanosecond resolution. Negative
104
+ # second values with fractions must still have non-negative nanos values
105
+ # that count forward in time. Must be from 0 to 999,999,999
106
+ # inclusive.
107
+ class Timestamp; end
108
+ end
109
+ end
@@ -0,0 +1,309 @@
1
+ # Copyright 2019 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/webrisk/v1beta1/webrisk.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
+
28
+ require "google/cloud/webrisk/v1beta1/webrisk_pb"
29
+ require "google/cloud/webrisk/v1beta1/credentials"
30
+
31
+ module Google
32
+ module Cloud
33
+ module Webrisk
34
+ module V1beta1
35
+ # Web Risk v1beta1 API defines an interface to detect malicious URLs on your
36
+ # website and in client applications.
37
+ #
38
+ # @!attribute [r] web_risk_service_v1_beta1_stub
39
+ # @return [Google::Cloud::Webrisk::V1beta1::WebRiskServiceV1Beta1::Stub]
40
+ class WebRiskServiceV1Beta1Client
41
+ # @private
42
+ attr_reader :web_risk_service_v1_beta1_stub
43
+
44
+ # The default address of the service.
45
+ SERVICE_ADDRESS = "webrisk.googleapis.com".freeze
46
+
47
+ # The default port of the service.
48
+ DEFAULT_SERVICE_PORT = 443
49
+
50
+ # The default set of gRPC interceptors.
51
+ GRPC_INTERCEPTORS = []
52
+
53
+ DEFAULT_TIMEOUT = 30
54
+
55
+ # The scopes needed to make gRPC calls to all of the methods defined in
56
+ # this service.
57
+ ALL_SCOPES = [
58
+ "https://www.googleapis.com/auth/cloud-platform"
59
+ ].freeze
60
+
61
+
62
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
63
+ # Provides the means for authenticating requests made by the client. This parameter can
64
+ # be many types.
65
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
66
+ # authenticating requests made by this client.
67
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
68
+ # credentials for this client.
69
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
70
+ # credentials for this client.
71
+ # A `GRPC::Core::Channel` will be used to make calls through.
72
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
73
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
74
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
75
+ # metadata for requests, generally, to give OAuth credentials.
76
+ # @param scopes [Array<String>]
77
+ # The OAuth scopes for this service. This parameter is ignored if
78
+ # an updater_proc is supplied.
79
+ # @param client_config [Hash]
80
+ # A Hash for call options for each method. See
81
+ # Google::Gax#construct_settings for the structure of
82
+ # this data. Falls back to the default config if not specified
83
+ # or the specified config is missing data points.
84
+ # @param timeout [Numeric]
85
+ # The default timeout, in seconds, for calls made through this client.
86
+ # @param metadata [Hash]
87
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
88
+ # @param exception_transformer [Proc]
89
+ # An optional proc that intercepts any exceptions raised during an API call to inject
90
+ # custom error handling.
91
+ def initialize \
92
+ credentials: nil,
93
+ scopes: ALL_SCOPES,
94
+ client_config: {},
95
+ timeout: DEFAULT_TIMEOUT,
96
+ metadata: nil,
97
+ exception_transformer: nil,
98
+ lib_name: nil,
99
+ lib_version: ""
100
+ # These require statements are intentionally placed here to initialize
101
+ # the gRPC module only when it's required.
102
+ # See https://github.com/googleapis/toolkit/issues/446
103
+ require "google/gax/grpc"
104
+ require "google/cloud/webrisk/v1beta1/webrisk_services_pb"
105
+
106
+ credentials ||= Google::Cloud::Webrisk::V1beta1::Credentials.default
107
+
108
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
109
+ updater_proc = Google::Cloud::Webrisk::V1beta1::Credentials.new(credentials).updater_proc
110
+ end
111
+ if credentials.is_a?(GRPC::Core::Channel)
112
+ channel = credentials
113
+ end
114
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
115
+ chan_creds = credentials
116
+ end
117
+ if credentials.is_a?(Proc)
118
+ updater_proc = credentials
119
+ end
120
+ if credentials.is_a?(Google::Auth::Credentials)
121
+ updater_proc = credentials.updater_proc
122
+ end
123
+
124
+ package_version = Gem.loaded_specs['google-cloud-webrisk'].version.version
125
+
126
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
127
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
128
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
129
+ google_api_client << " grpc/#{GRPC::VERSION}"
130
+ google_api_client.freeze
131
+
132
+ headers = { :"x-goog-api-client" => google_api_client }
133
+ headers.merge!(metadata) unless metadata.nil?
134
+ client_config_file = Pathname.new(__dir__).join(
135
+ "web_risk_service_v1_beta1_client_config.json"
136
+ )
137
+ defaults = client_config_file.open do |f|
138
+ Google::Gax.construct_settings(
139
+ "google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1",
140
+ JSON.parse(f.read),
141
+ client_config,
142
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
143
+ timeout,
144
+ errors: Google::Gax::Grpc::API_ERRORS,
145
+ metadata: headers
146
+ )
147
+ end
148
+
149
+ # Allow overriding the service path/port in subclasses.
150
+ service_path = self.class::SERVICE_ADDRESS
151
+ port = self.class::DEFAULT_SERVICE_PORT
152
+ interceptors = self.class::GRPC_INTERCEPTORS
153
+ @web_risk_service_v1_beta1_stub = Google::Gax::Grpc.create_stub(
154
+ service_path,
155
+ port,
156
+ chan_creds: chan_creds,
157
+ channel: channel,
158
+ updater_proc: updater_proc,
159
+ scopes: scopes,
160
+ interceptors: interceptors,
161
+ &Google::Cloud::Webrisk::V1beta1::WebRiskServiceV1Beta1::Stub.method(:new)
162
+ )
163
+
164
+ @compute_threat_list_diff = Google::Gax.create_api_call(
165
+ @web_risk_service_v1_beta1_stub.method(:compute_threat_list_diff),
166
+ defaults["compute_threat_list_diff"],
167
+ exception_transformer: exception_transformer
168
+ )
169
+ @search_uris = Google::Gax.create_api_call(
170
+ @web_risk_service_v1_beta1_stub.method(:search_uris),
171
+ defaults["search_uris"],
172
+ exception_transformer: exception_transformer
173
+ )
174
+ @search_hashes = Google::Gax.create_api_call(
175
+ @web_risk_service_v1_beta1_stub.method(:search_hashes),
176
+ defaults["search_hashes"],
177
+ exception_transformer: exception_transformer
178
+ )
179
+ end
180
+
181
+ # Service calls
182
+
183
+ # Gets the most recent threat list diffs.
184
+ #
185
+ # @param threat_type [Google::Cloud::Webrisk::V1beta1::ThreatType]
186
+ # Required. The ThreatList to update.
187
+ # @param constraints [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffRequest::Constraints | Hash]
188
+ # The constraints associated with this request.
189
+ # A hash of the same form as `Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffRequest::Constraints`
190
+ # can also be provided.
191
+ # @param version_token [String]
192
+ # The current version token of the client for the requested list (the
193
+ # client version that was received from the last successful diff).
194
+ # @param options [Google::Gax::CallOptions]
195
+ # Overrides the default settings for this call, e.g, timeout,
196
+ # retries, etc.
197
+ # @yield [result, operation] Access the result along with the RPC operation
198
+ # @yieldparam result [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffResponse]
199
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
200
+ # @return [Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffResponse]
201
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
202
+ # @example
203
+ # require "google/cloud/webrisk"
204
+ #
205
+ # web_risk_service_v1_beta1_client = Google::Cloud::Webrisk.new(version: :v1beta1)
206
+ #
207
+ # # TODO: Initialize `threat_type`:
208
+ # threat_type = :THREAT_TYPE_UNSPECIFIED
209
+ #
210
+ # # TODO: Initialize `constraints`:
211
+ # constraints = {}
212
+ # response = web_risk_service_v1_beta1_client.compute_threat_list_diff(threat_type, constraints)
213
+
214
+ def compute_threat_list_diff \
215
+ threat_type,
216
+ constraints,
217
+ version_token: nil,
218
+ options: nil,
219
+ &block
220
+ req = {
221
+ threat_type: threat_type,
222
+ constraints: constraints,
223
+ version_token: version_token
224
+ }.delete_if { |_, v| v.nil? }
225
+ req = Google::Gax::to_proto(req, Google::Cloud::Webrisk::V1beta1::ComputeThreatListDiffRequest)
226
+ @compute_threat_list_diff.call(req, options, &block)
227
+ end
228
+
229
+ # This method is used to check whether a URI is on a given threatList.
230
+ #
231
+ # @param uri [String]
232
+ # The URI to be checked for matches.
233
+ # @param threat_types [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
234
+ # Required. The ThreatLists to search in.
235
+ # @param options [Google::Gax::CallOptions]
236
+ # Overrides the default settings for this call, e.g, timeout,
237
+ # retries, etc.
238
+ # @yield [result, operation] Access the result along with the RPC operation
239
+ # @yieldparam result [Google::Cloud::Webrisk::V1beta1::SearchUrisResponse]
240
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
241
+ # @return [Google::Cloud::Webrisk::V1beta1::SearchUrisResponse]
242
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
243
+ # @example
244
+ # require "google/cloud/webrisk"
245
+ #
246
+ # web_risk_service_v1_beta1_client = Google::Cloud::Webrisk.new(version: :v1beta1)
247
+ #
248
+ # # TODO: Initialize `uri`:
249
+ # uri = ''
250
+ #
251
+ # # TODO: Initialize `threat_types`:
252
+ # threat_types = []
253
+ # response = web_risk_service_v1_beta1_client.search_uris(uri, threat_types)
254
+
255
+ def search_uris \
256
+ uri,
257
+ threat_types,
258
+ options: nil,
259
+ &block
260
+ req = {
261
+ uri: uri,
262
+ threat_types: threat_types
263
+ }.delete_if { |_, v| v.nil? }
264
+ req = Google::Gax::to_proto(req, Google::Cloud::Webrisk::V1beta1::SearchUrisRequest)
265
+ @search_uris.call(req, options, &block)
266
+ end
267
+
268
+ # Gets the full hashes that match the requested hash prefix.
269
+ # This is used after a hash prefix is looked up in a threatList
270
+ # and there is a match. The client side threatList only holds partial hashes
271
+ # so the client must query this method to determine if there is a full
272
+ # hash match of a threat.
273
+ #
274
+ # @param hash_prefix [String]
275
+ # A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
276
+ # hash. For JSON requests, this field is base64-encoded.
277
+ # @param threat_types [Array<Google::Cloud::Webrisk::V1beta1::ThreatType>]
278
+ # Required. The ThreatLists to search in.
279
+ # @param options [Google::Gax::CallOptions]
280
+ # Overrides the default settings for this call, e.g, timeout,
281
+ # retries, etc.
282
+ # @yield [result, operation] Access the result along with the RPC operation
283
+ # @yieldparam result [Google::Cloud::Webrisk::V1beta1::SearchHashesResponse]
284
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
285
+ # @return [Google::Cloud::Webrisk::V1beta1::SearchHashesResponse]
286
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
287
+ # @example
288
+ # require "google/cloud/webrisk"
289
+ #
290
+ # web_risk_service_v1_beta1_client = Google::Cloud::Webrisk.new(version: :v1beta1)
291
+ # response = web_risk_service_v1_beta1_client.search_hashes
292
+
293
+ def search_hashes \
294
+ hash_prefix: nil,
295
+ threat_types: nil,
296
+ options: nil,
297
+ &block
298
+ req = {
299
+ hash_prefix: hash_prefix,
300
+ threat_types: threat_types
301
+ }.delete_if { |_, v| v.nil? }
302
+ req = Google::Gax::to_proto(req, Google::Cloud::Webrisk::V1beta1::SearchHashesRequest)
303
+ @search_hashes.call(req, options, &block)
304
+ end
305
+ end
306
+ end
307
+ end
308
+ end
309
+ end