google-cloud-recaptcha_enterprise 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,140 @@
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 "google/gax"
17
+ require "pathname"
18
+
19
+ module Google
20
+ module Cloud
21
+ # rubocop:disable LineLength
22
+
23
+ ##
24
+ # # Ruby Client for reCAPTCHA Enterprise API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
25
+ #
26
+ # [reCAPTCHA Enterprise API][Product Documentation]:
27
+ #
28
+ # - [Product Documentation][]
29
+ #
30
+ # ## Quick Start
31
+ # In order to use this library, you first need to go through the following
32
+ # steps:
33
+ #
34
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
35
+ # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
36
+ # 3. [Enable the reCAPTCHA Enterprise API.](https://console.cloud.google.com/apis/library/recaptchaenterprise.googleapis.com)
37
+ # 4. [Setup Authentication.](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
38
+ #
39
+ # ### Installation
40
+ # ```
41
+ # $ gem install google-cloud-recaptcha_enterprise
42
+ # ```
43
+ #
44
+ # ### Next Steps
45
+ # - Read the [reCAPTCHA Enterprise API Product documentation][Product Documentation]
46
+ # to learn more about the product and see How-to Guides.
47
+ # - View this [repository's main README](https://github.com/googleapis/google-cloud-ruby/blob/master/README.md)
48
+ # to see the full list of Cloud APIs that we cover.
49
+ #
50
+ # [Product Documentation]: https://cloud.google.com/recaptchaenterprise
51
+ #
52
+ # ## Enabling Logging
53
+ #
54
+ # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
55
+ # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
56
+ # or a [`Google::Cloud::Logging::Logger`](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
57
+ # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
58
+ # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
59
+ #
60
+ # Configuring a Ruby stdlib logger:
61
+ #
62
+ # ```ruby
63
+ # require "logger"
64
+ #
65
+ # module MyLogger
66
+ # LOGGER = Logger.new $stderr, level: Logger::WARN
67
+ # def logger
68
+ # LOGGER
69
+ # end
70
+ # end
71
+ #
72
+ # # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
73
+ # module GRPC
74
+ # extend MyLogger
75
+ # end
76
+ # ```
77
+ #
78
+ module RecaptchaEnterprise
79
+ # rubocop:enable LineLength
80
+
81
+ FILE_DIR = File.realdirpath(Pathname.new(__FILE__).join("..").join("recaptcha_enterprise"))
82
+
83
+ AVAILABLE_VERSIONS = Dir["#{FILE_DIR}/*"]
84
+ .select { |file| File.directory?(file) }
85
+ .select { |dir| Google::Gax::VERSION_MATCHER.match(File.basename(dir)) }
86
+ .select { |dir| File.exist?(dir + ".rb") }
87
+ .map { |dir| File.basename(dir) }
88
+
89
+ ##
90
+ # Service to determine the likelihood an event is legitimate.
91
+ #
92
+ # @param version [Symbol, String]
93
+ # The major version of the service to be used. By default :v1beta1
94
+ # is used.
95
+ # @overload new(version:, credentials:, scopes:, client_config:, timeout:)
96
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
97
+ # Provides the means for authenticating requests made by the client. This parameter can
98
+ # be many types.
99
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
100
+ # authenticating requests made by this client.
101
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
102
+ # credentials for this client.
103
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
104
+ # credentials for this client.
105
+ # A `GRPC::Core::Channel` will be used to make calls through.
106
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
107
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
108
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
109
+ # metadata for requests, generally, to give OAuth credentials.
110
+ # @param scopes [Array<String>]
111
+ # The OAuth scopes for this service. This parameter is ignored if
112
+ # an updater_proc is supplied.
113
+ # @param client_config [Hash]
114
+ # A Hash for call options for each method. See
115
+ # Google::Gax#construct_settings for the structure of
116
+ # this data. Falls back to the default config if not specified
117
+ # or the specified config is missing data points.
118
+ # @param timeout [Numeric]
119
+ # The default timeout, in seconds, for calls made through this client.
120
+ # @param metadata [Hash]
121
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
122
+ # @param exception_transformer [Proc]
123
+ # An optional proc that intercepts any exceptions raised during an API call to inject
124
+ # custom error handling.
125
+ def self.new(*args, version: :v1beta1, **kwargs)
126
+ unless AVAILABLE_VERSIONS.include?(version.to_s.downcase)
127
+ raise "The version: #{version} is not available. The available versions " \
128
+ "are: [#{AVAILABLE_VERSIONS.join(", ")}]"
129
+ end
130
+
131
+ require "#{FILE_DIR}/#{version.to_s.downcase}"
132
+ version_module = Google::Cloud::RecaptchaEnterprise
133
+ .constants
134
+ .select {|sym| sym.to_s.downcase == version.to_s.downcase}
135
+ .first
136
+ Google::Cloud::RecaptchaEnterprise.const_get(version_module).new(*args, **kwargs)
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,138 @@
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 "google/cloud/recaptcha_enterprise/v1beta1/recaptcha_enterprise_client"
17
+ require "google/cloud/recaptcha_enterprise/v1beta1/helpers"
18
+
19
+ module Google
20
+ module Cloud
21
+ module RecaptchaEnterprise
22
+ # rubocop:disable LineLength
23
+
24
+ ##
25
+ # # Ruby Client for reCAPTCHA Enterprise API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
26
+ #
27
+ # [reCAPTCHA Enterprise API][Product Documentation]:
28
+ #
29
+ # - [Product Documentation][]
30
+ #
31
+ # ## Quick Start
32
+ # In order to use this library, you first need to go through the following
33
+ # steps:
34
+ #
35
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
36
+ # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
37
+ # 3. [Enable the reCAPTCHA Enterprise API.](https://console.cloud.google.com/apis/library/recaptchaenterprise.googleapis.com)
38
+ # 4. [Setup Authentication.](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
39
+ #
40
+ # ### Installation
41
+ # ```
42
+ # $ gem install google-cloud-recaptcha_enterprise
43
+ # ```
44
+ #
45
+ # ### Next Steps
46
+ # - Read the [reCAPTCHA Enterprise API Product documentation][Product Documentation]
47
+ # to learn more about the product and see How-to Guides.
48
+ # - View this [repository's main README](https://github.com/googleapis/google-cloud-ruby/blob/master/README.md)
49
+ # to see the full list of Cloud APIs that we cover.
50
+ #
51
+ # [Product Documentation]: https://cloud.google.com/recaptchaenterprise
52
+ #
53
+ # ## Enabling Logging
54
+ #
55
+ # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
56
+ # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
57
+ # or a [`Google::Cloud::Logging::Logger`](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
58
+ # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
59
+ # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
60
+ #
61
+ # Configuring a Ruby stdlib logger:
62
+ #
63
+ # ```ruby
64
+ # require "logger"
65
+ #
66
+ # module MyLogger
67
+ # LOGGER = Logger.new $stderr, level: Logger::WARN
68
+ # def logger
69
+ # LOGGER
70
+ # end
71
+ # end
72
+ #
73
+ # # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
74
+ # module GRPC
75
+ # extend MyLogger
76
+ # end
77
+ # ```
78
+ #
79
+ module V1beta1
80
+ # rubocop:enable LineLength
81
+
82
+ ##
83
+ # Service to determine the likelihood an event is legitimate.
84
+ #
85
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
86
+ # Provides the means for authenticating requests made by the client. This parameter can
87
+ # be many types.
88
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
89
+ # authenticating requests made by this client.
90
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
91
+ # credentials for this client.
92
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
93
+ # credentials for this client.
94
+ # A `GRPC::Core::Channel` will be used to make calls through.
95
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
96
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
97
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
98
+ # metadata for requests, generally, to give OAuth credentials.
99
+ # @param scopes [Array<String>]
100
+ # The OAuth scopes for this service. This parameter is ignored if
101
+ # an updater_proc is supplied.
102
+ # @param client_config [Hash]
103
+ # A Hash for call options for each method. See
104
+ # Google::Gax#construct_settings for the structure of
105
+ # this data. Falls back to the default config if not specified
106
+ # or the specified config is missing data points.
107
+ # @param timeout [Numeric]
108
+ # The default timeout, in seconds, for calls made through this client.
109
+ # @param metadata [Hash]
110
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
111
+ # @param exception_transformer [Proc]
112
+ # An optional proc that intercepts any exceptions raised during an API call to inject
113
+ # custom error handling.
114
+ def self.new \
115
+ credentials: nil,
116
+ scopes: nil,
117
+ client_config: nil,
118
+ timeout: nil,
119
+ metadata: nil,
120
+ exception_transformer: nil,
121
+ lib_name: nil,
122
+ lib_version: nil
123
+ kwargs = {
124
+ credentials: credentials,
125
+ scopes: scopes,
126
+ client_config: client_config,
127
+ timeout: timeout,
128
+ metadata: metadata,
129
+ exception_transformer: exception_transformer,
130
+ lib_name: lib_name,
131
+ lib_version: lib_version
132
+ }.select { |_, v| v != nil }
133
+ Google::Cloud::RecaptchaEnterprise::V1beta1::RecaptchaEnterpriseClient.new(**kwargs)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -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 RecaptchaEnterprise
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(RECAPTCHA_ENTERPRISE_CREDENTIALS
27
+ RECAPTCHA_ENTERPRISE_KEYFILE
28
+ GOOGLE_CLOUD_CREDENTIALS
29
+ GOOGLE_CLOUD_KEYFILE
30
+ GCLOUD_KEYFILE)
31
+ JSON_ENV_VARS = %w(RECAPTCHA_ENTERPRISE_CREDENTIALS_JSON
32
+ RECAPTCHA_ENTERPRISE_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,153 @@
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 Recaptchaenterprise
19
+ module V1beta1
20
+ # The create assessment request message.
21
+ # @!attribute [rw] parent
22
+ # @return [String]
23
+ # Required. The name of the project in which the assessment will be created,
24
+ # in the format "projects/\\{project_number}".
25
+ # @!attribute [rw] assessment
26
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::Assessment]
27
+ # The asessment details.
28
+ class CreateAssessmentRequest; end
29
+
30
+ # The request message to annotate an Assessment.
31
+ # @!attribute [rw] name
32
+ # @return [String]
33
+ # Required. The resource name of the Assessment, in the format
34
+ # "projects/\\{project_number}/assessments/\\{assessment_id}".
35
+ # @!attribute [rw] annotation
36
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::AnnotateAssessmentRequest::Annotation]
37
+ # The annotation that will be assigned to the Event.
38
+ class AnnotateAssessmentRequest
39
+ # Enum that reprensents the types of annotations.
40
+ module Annotation
41
+ # Default unspecified type.
42
+ ANNOTATION_UNSPECIFIED = 0
43
+
44
+ # Provides information that the event turned out to be legitimate.
45
+ LEGITIMATE = 1
46
+
47
+ # Provides information that the event turned out to be fraudulent.
48
+ FRAUDULENT = 2
49
+ end
50
+ end
51
+
52
+ # Empty response for AnnotateAssessment.
53
+ class AnnotateAssessmentResponse; end
54
+
55
+ # A recaptcha assessment resource.
56
+ # @!attribute [rw] name
57
+ # @return [String]
58
+ # Output only. The resource name for the Assessment in the format
59
+ # "projects/\\{project_number}/assessments/\\{assessment_id}".
60
+ # @!attribute [rw] event
61
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::Event]
62
+ # The event being assessed.
63
+ # @!attribute [rw] score
64
+ # @return [Float]
65
+ # Output only. Legitimate event score from 0.0 to 1.0.
66
+ # (1.0 means very likely legitimate traffic while 0.0 means very likely
67
+ # non-legitimate traffic).
68
+ # @!attribute [rw] token_properties
69
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::TokenProperties]
70
+ # Output only. Properties of the provided event token.
71
+ # @!attribute [rw] reasons
72
+ # @return [Array<Google::Cloud::Recaptchaenterprise::V1beta1::Assessment::ClassificationReason>]
73
+ # Output only. Reasons contributing to the risk analysis verdict.
74
+ class Assessment
75
+ # LINT.IfChange(classification_reason)
76
+ # Reasons contributing to the risk analysis verdict.
77
+ module ClassificationReason
78
+ # Default unspecified type.
79
+ CLASSIFICATION_REASON_UNSPECIFIED = 0
80
+
81
+ # The event appeared to be automated.
82
+ AUTOMATION = 1
83
+
84
+ # The event was not made from the proper context on the real site.
85
+ UNEXPECTED_ENVIRONMENT = 2
86
+
87
+ # Browsing behavior leading up to the event was generated was out of the
88
+ # ordinary.
89
+ UNEXPECTED_USAGE_PATTERNS = 4
90
+
91
+ # Too little traffic has been received from this site thus far to generate
92
+ # quality risk analysis.
93
+ PROVISIONAL_RISK_ANALYSIS = 5
94
+ end
95
+ end
96
+
97
+ # @!attribute [rw] token
98
+ # @return [String]
99
+ # The user response token provided by the reCAPTCHA client-side integration
100
+ # on your site.
101
+ # @!attribute [rw] site_key
102
+ # @return [String]
103
+ # The site key that was used to invoke reCAPTCHA on your site and generate
104
+ # the token.
105
+ class Event; end
106
+
107
+ # @!attribute [rw] valid
108
+ # @return [true, false]
109
+ # Output only. Whether the provided user response token is valid.
110
+ # @!attribute [rw] invalid_reason
111
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::TokenProperties::InvalidReason]
112
+ # Output only. Reason associated with the response when valid = false.
113
+ # @!attribute [rw] create_time
114
+ # @return [Google::Protobuf::Timestamp]
115
+ # Output only. The timestamp corresponding to the generation of the token.
116
+ # @!attribute [rw] hostname
117
+ # @return [String]
118
+ # Output only. The hostname of the page on which the token was generated.
119
+ # @!attribute [rw] action
120
+ # @return [String]
121
+ # Output only. Action name provided at token generation.
122
+ class TokenProperties
123
+ # Enum that represents the types of invalid token reasons.
124
+ module InvalidReason
125
+ # Default unspecified type.
126
+ INVALID_REASON_UNSPECIFIED = 0
127
+
128
+ # If the failure reason was not accounted for.
129
+ UNKNOWN_INVALID_REASON = 1
130
+
131
+ # The provided user verification token was malformed.
132
+ MALFORMED = 2
133
+
134
+ # The user verification token had expired.
135
+ EXPIRED = 3
136
+
137
+ # The user verification had already been seen.
138
+ DUPE = 4
139
+
140
+ # The user verification token did not match the provided site secret.
141
+ # This may be a configuration error (e.g. development keys used in
142
+ # production) or end users trying to use verification tokens from other
143
+ # sites.
144
+ SITE_MISMATCH = 5
145
+
146
+ # The user verification token was not present. It is a required input.
147
+ MISSING = 6
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end