Class: CloudflareClient::Zone::Firewall::AccessRule

Inherits:
CloudflareClient::Zone::Firewall show all
Defined in:
lib/cloudflare_client/zone/firewall/access_rule.rb

Constant Summary collapse

VALID_MODES =
%w[block challenge whitelist].freeze
VALID_SCOPE_TYPES =
%w[user organization zone].freeze
VALID_CONFIG_TARGETS =
%w[ip ip_range country].freeze
VALID_ORDERS =
%w[scope_type configuration_target configuration_value mode].freeze
VALID_CASCADES =
%w[none basic aggressive].freeze

Constants inherited from CloudflareClient::Zone

VALID_ZONE_STATUSES

Constants inherited from CloudflareClient

API_BASE, POSSIBLE_API_SETTINGS, VALID_BUNDLE_METHODS, VALID_DIRECTIONS, VALID_MATCHES, VERSION

Instance Attribute Summary

Attributes inherited from Base

#zone_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from CloudflareClient::Zone

#create_zone, #delete_zone, #edit_zone, #purge_zone_cache, #update_zone_settings, #zone, #zone_activation_check, #zone_setting, #zone_settings, #zones

Methods inherited from CloudflareClient

#initialize

Constructor Details

This class inherits a constructor from CloudflareClient::Zone::Base

Instance Method Details

#create(mode:, configuration:, notes: nil) ⇒ Object

create firewall access rule



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cloudflare_client/zone/firewall/access_rule.rb', line 50

def create(mode:, configuration:, notes: nil)
  valid_value_check(:mode, mode, VALID_MODES)
  if configuration.is_a?(Hash)
    unless configuration.keys.map(&:to_sym).sort == [:target, :value]
      raise 'configuration must contain valid a valid target and value'
    end
  else
    raise 'configuration must be a valid configuration object'
  end

  data         = {mode: mode, configuration: configuration}
  data[:notes] = notes unless notes.nil?

  cf_post(path: "/zones/#{zone_id}/firewall/access_rules/rules", data: data)
end

#delete(id:, cascade: 'none') ⇒ Object

delete a firewall access rule



81
82
83
84
85
86
# File 'lib/cloudflare_client/zone/firewall/access_rule.rb', line 81

def delete(id:, cascade: 'none')
  id_check('id', id)
  valid_value_check(:cascade, cascade, VALID_CASCADES)

  cf_delete(path: "/zones/#{zone_id}/firewall/access_rules/rules/#{id}")
end

#list(notes: nil, mode: nil, match: nil, scope_type: nil, configuration_value: nil, order: nil, page: 1, per_page: 50, configuration_target: nil, direction: 'desc') ⇒ Object

firewall_access_rules_for_a_zone



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cloudflare_client/zone/firewall/access_rule.rb', line 10

def list(notes: nil, mode: nil, match: nil, scope_type: nil, configuration_value: nil, order: nil, page: 1, per_page: 50, configuration_target: nil, direction: 'desc')
  params                       = {page: page, per_page: per_page}
  params[:notes]               = notes unless notes.nil?
  params[:configuration_value] = configuration_value unless configuration_value.nil?

  unless mode.nil?
    valid_value_check(:mode, mode, VALID_MODES)
    params[:mode] = mode
  end

  unless match.nil?
    valid_value_check(:match, match, VALID_MATCHES)
    params[:match] = match
  end

  unless scope_type.nil?
    valid_value_check(:scope_type, scope_type, VALID_SCOPE_TYPES)
    params[:scope_type] = scope_type
  end

  unless configuration_target.nil?
    valid_value_check(:configuration_target, configuration_target, VALID_CONFIG_TARGETS)
    params[:configuration_target] = configuration_target
  end

  unless direction.nil?
    valid_value_check(:direction, direction, VALID_DIRECTIONS)
    params[:direction] = direction
  end

  unless order.nil?
    valid_value_check(:order, order, VALID_ORDERS)
    params[:order] = order
  end

  cf_get(path: "/zones/#{zone_id}/firewall/access_rules/rules", params: params)
end

#update(id:, mode: nil, notes: nil) ⇒ Object

updates firewall_access_rule



68
69
70
71
72
73
74
75
76
77
# File 'lib/cloudflare_client/zone/firewall/access_rule.rb', line 68

def update(id:, mode: nil, notes: nil)
  id_check('id', id)
  valid_value_check(:mode, mode, VALID_MODES) unless mode.nil?

  data         = {}
  data[:mode]  = mode unless mode.nil?
  data[:notes] = notes unless notes.nil?

  cf_patch(path: "/zones/#{zone_id}/firewall/access_rules/rules/#{id}", data: data)
end