cloudflare 3.2.1 → 4.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +14 -16
- data/README.md +9 -9
- data/Rakefile +10 -8
- data/cloudflare.gemspec +19 -17
- data/lib/cloudflare.rb +20 -5
- data/lib/cloudflare/{response.rb → accounts.rb} +25 -47
- data/lib/cloudflare/connection.rb +31 -52
- data/lib/cloudflare/dns.rb +91 -0
- data/lib/cloudflare/firewall.rb +80 -0
- data/lib/cloudflare/logs.rb +41 -0
- data/lib/cloudflare/paginate.rb +54 -0
- data/lib/cloudflare/representation.rb +94 -0
- data/lib/cloudflare/rspec/connection.rb +18 -11
- data/lib/cloudflare/user.rb +10 -9
- data/lib/cloudflare/version.rb +1 -1
- data/lib/cloudflare/zones.rb +85 -0
- data/spec/cloudflare/dns_spec.rb +32 -0
- data/spec/cloudflare/firewall_spec.rb +48 -0
- data/spec/cloudflare/zone_spec.rb +23 -124
- data/spec/spec_helper.rb +25 -169
- metadata +37 -19
- data/.rubocop.yml +0 -19
- data/.ruby-version +0 -1
- data/lib/cloudflare/zone.rb +0 -202
- data/spec/fake_cloudflare/cloudflare.rb +0 -17
data/.rubocop.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Naming/UncommunicativeMethodParamName:
|
2
|
-
AllowedNames:
|
3
|
-
- ip
|
4
|
-
- id
|
5
|
-
|
6
|
-
Style/Documentation:
|
7
|
-
Enabled: false
|
8
|
-
|
9
|
-
Metrics/LineLength:
|
10
|
-
Max: 120
|
11
|
-
|
12
|
-
Metrics/MethodLength:
|
13
|
-
Max: 20
|
14
|
-
|
15
|
-
Lint/Debugger:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Gemspec/RequiredRubyVersion:
|
19
|
-
Enabled: false
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.5.0
|
data/lib/cloudflare/zone.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2012, by Marcin Prokop.
|
4
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
5
|
-
# Copyright, 2017, by David Rosenbloom. <http://artifactory.com>
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the "Software"), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in
|
15
|
-
# all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
-
# THE SOFTWARE.
|
24
|
-
|
25
|
-
require_relative 'connection'
|
26
|
-
|
27
|
-
module Cloudflare
|
28
|
-
class Connection < Resource
|
29
|
-
def zones
|
30
|
-
@zones ||= Zones.new(concat_urls(url, 'zones'), options)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class DNSRecord < Resource
|
35
|
-
def initialize(url, record = nil, **options)
|
36
|
-
super(url, **options)
|
37
|
-
|
38
|
-
@record = record || get.result
|
39
|
-
end
|
40
|
-
|
41
|
-
def update_content(content)
|
42
|
-
response = put({ type: @record[:type],
|
43
|
-
name: @record[:name],
|
44
|
-
content: content }.to_json,
|
45
|
-
content_type: 'application/json')
|
46
|
-
response.successful?
|
47
|
-
end
|
48
|
-
|
49
|
-
attr_reader :record
|
50
|
-
|
51
|
-
def to_s
|
52
|
-
"#{@record[:name]} #{@record[:type]} #{@record[:content]}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class DNSRecords < Resource
|
57
|
-
def initialize(url, zone, **options)
|
58
|
-
super(url, **options)
|
59
|
-
|
60
|
-
@zone = zone
|
61
|
-
end
|
62
|
-
|
63
|
-
attr_reader :zone
|
64
|
-
|
65
|
-
def all
|
66
|
-
results = paginate(DNSRecords, url)
|
67
|
-
results.map { |record| DNSRecord.new(concat_urls(url, record[:id]), record, **options) }
|
68
|
-
end
|
69
|
-
|
70
|
-
def find_by_name(name)
|
71
|
-
response = get(params: { name: name })
|
72
|
-
|
73
|
-
return if response.empty?
|
74
|
-
record = response.results.first
|
75
|
-
|
76
|
-
DNSRecord.new(concat_urls(url, record[:id]), record, **options)
|
77
|
-
end
|
78
|
-
|
79
|
-
def find_by_id(id)
|
80
|
-
DNSRecord.new(concat_urls(url, id), **options)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class FirewallRule < Resource
|
85
|
-
def initialize(url, record = nil, **options)
|
86
|
-
super(url, **options)
|
87
|
-
|
88
|
-
@record = record || get.result
|
89
|
-
end
|
90
|
-
|
91
|
-
attr_reader :record
|
92
|
-
|
93
|
-
def to_s
|
94
|
-
"#{@record[:configuration][:value]} - #{@record[:mode]} - #{@record[:notes]}"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class FirewallRules < Resource
|
99
|
-
def initialize(url, zone, **options)
|
100
|
-
super(url, **options)
|
101
|
-
|
102
|
-
@zone = zone
|
103
|
-
end
|
104
|
-
|
105
|
-
attr_reader :zone
|
106
|
-
|
107
|
-
def all(mode = nil, ip = nil, notes = nil)
|
108
|
-
url_args = ''
|
109
|
-
url_args.concat("&mode=#{mode}") if mode
|
110
|
-
url_args.concat("&configuration_value=#{ip}") if ip
|
111
|
-
url_args.concat("¬es=#{notes}") if notes
|
112
|
-
|
113
|
-
results = paginate(FirewallRules, url, url_args)
|
114
|
-
results.map { |record| FirewallRule.new(concat_urls(url, record[:id]), record, **options) }
|
115
|
-
end
|
116
|
-
|
117
|
-
def firewalled_ips(rules)
|
118
|
-
rules.collect { |r| r.record[:configuration][:value] }
|
119
|
-
end
|
120
|
-
|
121
|
-
def blocked_ips
|
122
|
-
firewalled_ips(all('block'))
|
123
|
-
end
|
124
|
-
|
125
|
-
def set(mode, ip, note)
|
126
|
-
data = {
|
127
|
-
mode: mode.to_s,
|
128
|
-
configuration: {
|
129
|
-
target: 'ip',
|
130
|
-
value: ip.to_s,
|
131
|
-
notes: "cloudflare gem firewall_rules [#{mode}] #{note} #{Time.now.strftime('%m/%d/%y')}"
|
132
|
-
}
|
133
|
-
}
|
134
|
-
|
135
|
-
post(data.to_json, content_type: 'application/json')
|
136
|
-
end
|
137
|
-
|
138
|
-
def unset(mode, value)
|
139
|
-
rule = send("find_by_#{mode}", value)
|
140
|
-
rule.delete
|
141
|
-
end
|
142
|
-
|
143
|
-
def find_by_id(id)
|
144
|
-
FirewallRule.new(concat_urls(url, id), **options)
|
145
|
-
end
|
146
|
-
|
147
|
-
def find_by_ip(ip)
|
148
|
-
rule = FirewallRule.new(concat_urls(url, "?configuration_value=#{ip}"), **options)
|
149
|
-
FirewallRule.new(concat_urls(url, rule.record.first[:id]), **options)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
class Zone < Resource
|
154
|
-
DEFAULT_PURGE_CACHE_PARAMS = {
|
155
|
-
purge_everything: true
|
156
|
-
}.freeze
|
157
|
-
|
158
|
-
def initialize(url, record = nil, preload = false, **options)
|
159
|
-
super(url, **options)
|
160
|
-
@record = record || get.result if preload
|
161
|
-
end
|
162
|
-
|
163
|
-
attr_reader :record
|
164
|
-
|
165
|
-
def dns_records
|
166
|
-
@dns_records ||= DNSRecords.new(concat_urls(url, 'dns_records'), self, **options)
|
167
|
-
end
|
168
|
-
|
169
|
-
def firewall_rules
|
170
|
-
@firewall_rules ||= FirewallRules.new(concat_urls(url, 'firewall/access_rules/rules'), self, **options)
|
171
|
-
end
|
172
|
-
|
173
|
-
def purge_cache(params = DEFAULT_PURGE_CACHE_PARAMS)
|
174
|
-
response = self['purge_cache'].post(params.to_json)
|
175
|
-
response.successful?
|
176
|
-
end
|
177
|
-
|
178
|
-
def to_s
|
179
|
-
@record[:name]
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
class Zones < Resource
|
184
|
-
def all
|
185
|
-
results = paginate(Zone, url)
|
186
|
-
results.map { |record| Zone.new(concat_urls(url, record[:id]), record, **options) }
|
187
|
-
end
|
188
|
-
|
189
|
-
def find_by_name(name)
|
190
|
-
response = get(params: { name: name })
|
191
|
-
|
192
|
-
return if response.empty?
|
193
|
-
record = response.results.first
|
194
|
-
|
195
|
-
Zone.new(concat_urls(url, record[:id]), record, true, **options)
|
196
|
-
end
|
197
|
-
|
198
|
-
def find_by_id(id)
|
199
|
-
Zone.new(concat_urls(url, id), **options)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'sinatra/base'
|
4
|
-
|
5
|
-
class FakeCloudFlare < Sinatra::Base
|
6
|
-
get '/zones/:id/dns_records/?page=1&per_page=50&scope_type=organization' do
|
7
|
-
json_response 200, 'get_all_zones.json'
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def json_response(response_code, file_name)
|
13
|
-
content_type :json
|
14
|
-
status response_code
|
15
|
-
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
|
16
|
-
end
|
17
|
-
end
|