|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Auth0 |
| 4 | + module AttackProtection |
| 5 | + module CaptchaPolicies |
| 6 | + class Client |
| 7 | + # @param client [Auth0::Internal::Http::RawClient] |
| 8 | + # |
| 9 | + # @return [void] |
| 10 | + def initialize(client:) |
| 11 | + @client = client |
| 12 | + end |
| 13 | + |
| 14 | + # Retrieve all CAPTCHA attack protection policies for the tenant, sorted by priority ascending. |
| 15 | + # |
| 16 | + # @param request_options [Hash] |
| 17 | + # @param _params [Hash] |
| 18 | + # @option request_options [String] :base_url |
| 19 | + # @option request_options [Hash{String => Object}] :additional_headers |
| 20 | + # @option request_options [Hash{String => Object}] :additional_query_parameters |
| 21 | + # @option request_options [Hash{String => Object}] :additional_body_parameters |
| 22 | + # @option request_options [Integer] :timeout_in_seconds |
| 23 | + # |
| 24 | + # @example |
| 25 | + # client.attack_protection.captcha_policies.list |
| 26 | + # |
| 27 | + # @return [Array[Auth0::Types::AttackProtectionCaptchaPolicy]] |
| 28 | + def list(request_options: {}, **_params) |
| 29 | + request = Auth0::Internal::JSON::Request.new( |
| 30 | + base_url: request_options[:base_url], |
| 31 | + method: "GET", |
| 32 | + path: "attack-protection/captcha/policies", |
| 33 | + request_options: request_options |
| 34 | + ) |
| 35 | + begin |
| 36 | + response = @client.send(request) |
| 37 | + rescue Net::HTTPRequestTimeout |
| 38 | + raise Auth0::Errors::TimeoutError |
| 39 | + end |
| 40 | + code = response.code.to_i |
| 41 | + if code.between?(200, 299) |
| 42 | + (response.body.to_s.empty? ? nil : Auth0::Types::ListAttackProtectionCaptchaPoliciesResponseContent.load(response.body)) |
| 43 | + else |
| 44 | + error_class = Auth0::Errors::ResponseError.subclass_for_code(code) |
| 45 | + raise error_class.new(response.body, code: code) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + # Create a new CAPTCHA attack protection policy for the tenant. The maximum number of policies per tenant is |
| 50 | + # determined by the tenant's subscription. |
| 51 | + # |
| 52 | + # @param request_options [Hash] |
| 53 | + # @param params [Auth0::AttackProtection::CaptchaPolicies::Types::CreateAttackProtectionCaptchaPolicyRequestContent] |
| 54 | + # @option request_options [String] :base_url |
| 55 | + # @option request_options [Hash{String => Object}] :additional_headers |
| 56 | + # @option request_options [Hash{String => Object}] :additional_query_parameters |
| 57 | + # @option request_options [Hash{String => Object}] :additional_body_parameters |
| 58 | + # @option request_options [Integer] :timeout_in_seconds |
| 59 | + # |
| 60 | + # @example |
| 61 | + # client.attack_protection.captcha_policies.create( |
| 62 | + # name: "name", |
| 63 | + # priority: 1, |
| 64 | + # match: {}, |
| 65 | + # action: {} |
| 66 | + # ) |
| 67 | + # |
| 68 | + # @return [Auth0::Types::AttackProtectionCaptchaPolicy] |
| 69 | + def create(request_options: {}, **params) |
| 70 | + params = Auth0::Internal::Types::Utils.normalize_keys(params) |
| 71 | + request = Auth0::Internal::JSON::Request.new( |
| 72 | + base_url: request_options[:base_url], |
| 73 | + method: "POST", |
| 74 | + path: "attack-protection/captcha/policies", |
| 75 | + body: Auth0::AttackProtection::CaptchaPolicies::Types::CreateAttackProtectionCaptchaPolicyRequestContent.new(params).to_h, |
| 76 | + request_options: request_options |
| 77 | + ) |
| 78 | + begin |
| 79 | + response = @client.send(request) |
| 80 | + rescue Net::HTTPRequestTimeout |
| 81 | + raise Auth0::Errors::TimeoutError |
| 82 | + end |
| 83 | + code = response.code.to_i |
| 84 | + if code.between?(200, 299) |
| 85 | + (response.body.to_s.empty? ? nil : Auth0::Types::AttackProtectionCaptchaPolicy.load(response.body)) |
| 86 | + else |
| 87 | + error_class = Auth0::Errors::ResponseError.subclass_for_code(code) |
| 88 | + raise error_class.new(response.body, code: code) |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + # Retrieve a single CAPTCHA attack protection policy for the tenant by ID. |
| 93 | + # |
| 94 | + # @param request_options [Hash] |
| 95 | + # @param params [Hash] |
| 96 | + # @option request_options [String] :base_url |
| 97 | + # @option request_options [Hash{String => Object}] :additional_headers |
| 98 | + # @option request_options [Hash{String => Object}] :additional_query_parameters |
| 99 | + # @option request_options [Hash{String => Object}] :additional_body_parameters |
| 100 | + # @option request_options [Integer] :timeout_in_seconds |
| 101 | + # @option params [String] :id |
| 102 | + # |
| 103 | + # @example |
| 104 | + # client.attack_protection.captcha_policies.get(id: "id") |
| 105 | + # |
| 106 | + # @return [Auth0::Types::AttackProtectionCaptchaPolicy] |
| 107 | + def get(request_options: {}, **params) |
| 108 | + params = Auth0::Internal::Types::Utils.normalize_keys(params) |
| 109 | + request = Auth0::Internal::JSON::Request.new( |
| 110 | + base_url: request_options[:base_url], |
| 111 | + method: "GET", |
| 112 | + path: "attack-protection/captcha/policies/#{URI.encode_uri_component(params[:id].to_s)}", |
| 113 | + request_options: request_options |
| 114 | + ) |
| 115 | + begin |
| 116 | + response = @client.send(request) |
| 117 | + rescue Net::HTTPRequestTimeout |
| 118 | + raise Auth0::Errors::TimeoutError |
| 119 | + end |
| 120 | + code = response.code.to_i |
| 121 | + if code.between?(200, 299) |
| 122 | + (response.body.to_s.empty? ? nil : Auth0::Types::AttackProtectionCaptchaPolicy.load(response.body)) |
| 123 | + else |
| 124 | + error_class = Auth0::Errors::ResponseError.subclass_for_code(code) |
| 125 | + raise error_class.new(response.body, code: code) |
| 126 | + end |
| 127 | + end |
| 128 | + |
| 129 | + # Delete a CAPTCHA attack protection policy for the tenant. |
| 130 | + # |
| 131 | + # @param request_options [Hash] |
| 132 | + # @param params [Hash] |
| 133 | + # @option request_options [String] :base_url |
| 134 | + # @option request_options [Hash{String => Object}] :additional_headers |
| 135 | + # @option request_options [Hash{String => Object}] :additional_query_parameters |
| 136 | + # @option request_options [Hash{String => Object}] :additional_body_parameters |
| 137 | + # @option request_options [Integer] :timeout_in_seconds |
| 138 | + # @option params [String] :id |
| 139 | + # |
| 140 | + # @example |
| 141 | + # client.attack_protection.captcha_policies.delete(id: "id") |
| 142 | + # |
| 143 | + # @return [untyped] |
| 144 | + def delete(request_options: {}, **params) |
| 145 | + params = Auth0::Internal::Types::Utils.normalize_keys(params) |
| 146 | + request = Auth0::Internal::JSON::Request.new( |
| 147 | + base_url: request_options[:base_url], |
| 148 | + method: "DELETE", |
| 149 | + path: "attack-protection/captcha/policies/#{URI.encode_uri_component(params[:id].to_s)}", |
| 150 | + request_options: request_options |
| 151 | + ) |
| 152 | + begin |
| 153 | + response = @client.send(request) |
| 154 | + rescue Net::HTTPRequestTimeout |
| 155 | + raise Auth0::Errors::TimeoutError |
| 156 | + end |
| 157 | + code = response.code.to_i |
| 158 | + return if code.between?(200, 299) |
| 159 | + |
| 160 | + error_class = Auth0::Errors::ResponseError.subclass_for_code(code) |
| 161 | + raise error_class.new(response.body, code: code) |
| 162 | + end |
| 163 | + |
| 164 | + # Partially update a CAPTCHA attack protection policy. Only the provided fields are modified. A provided match |
| 165 | + # or action replaces the stored value in full rather than merging with it; within action, a provider secret or |
| 166 | + # API key that is omitted from a provided provider block keeps its stored value. |
| 167 | + # |
| 168 | + # @param request_options [Hash] |
| 169 | + # @param params [Auth0::AttackProtection::CaptchaPolicies::Types::UpdateAttackProtectionCaptchaPolicyRequestContent] |
| 170 | + # @option request_options [String] :base_url |
| 171 | + # @option request_options [Hash{String => Object}] :additional_headers |
| 172 | + # @option request_options [Hash{String => Object}] :additional_query_parameters |
| 173 | + # @option request_options [Hash{String => Object}] :additional_body_parameters |
| 174 | + # @option request_options [Integer] :timeout_in_seconds |
| 175 | + # @option params [String] :id |
| 176 | + # |
| 177 | + # @example |
| 178 | + # client.attack_protection.captcha_policies.update(id: "id") |
| 179 | + # |
| 180 | + # @return [Auth0::Types::AttackProtectionCaptchaPolicy] |
| 181 | + def update(request_options: {}, **params) |
| 182 | + params = Auth0::Internal::Types::Utils.normalize_keys(params) |
| 183 | + request_data = Auth0::AttackProtection::CaptchaPolicies::Types::UpdateAttackProtectionCaptchaPolicyRequestContent.new(params).to_h |
| 184 | + non_body_param_names = %w[id] |
| 185 | + body = request_data.except(*non_body_param_names) |
| 186 | + |
| 187 | + request = Auth0::Internal::JSON::Request.new( |
| 188 | + base_url: request_options[:base_url], |
| 189 | + method: "PATCH", |
| 190 | + path: "attack-protection/captcha/policies/#{URI.encode_uri_component(params[:id].to_s)}", |
| 191 | + body: body, |
| 192 | + request_options: request_options |
| 193 | + ) |
| 194 | + begin |
| 195 | + response = @client.send(request) |
| 196 | + rescue Net::HTTPRequestTimeout |
| 197 | + raise Auth0::Errors::TimeoutError |
| 198 | + end |
| 199 | + code = response.code.to_i |
| 200 | + if code.between?(200, 299) |
| 201 | + (response.body.to_s.empty? ? nil : Auth0::Types::AttackProtectionCaptchaPolicy.load(response.body)) |
| 202 | + else |
| 203 | + error_class = Auth0::Errors::ResponseError.subclass_for_code(code) |
| 204 | + raise error_class.new(response.body, code: code) |
| 205 | + end |
| 206 | + end |
| 207 | + end |
| 208 | + end |
| 209 | + end |
| 210 | +end |
0 commit comments