record_store 7.1.1 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9f48a40d3262e148fff5aecff8c61e5f4f676bdc7f7bcb64e2964dc221ba078
4
- data.tar.gz: 48a44aa9fc8a431653d09c1c524bcfee73ea09e6148ae9ff0552110b7db51173
3
+ metadata.gz: 7680653d3944e3a5c8de1a31055e38266a379d4caed36f7eb30bb5ae27217d71
4
+ data.tar.gz: 5487a8cbcd8079815fbe3e0276e99360a16d954b02b6ed819639bd73e016bc5e
5
5
  SHA512:
6
- metadata.gz: cb623045bb1b2db82232eb037adaf05a13c234d9d82e760603075ec590b5528f2daeb6dfe1df28bd6cc1987ba379f8ee070547af3336bb11213651012d527f5b
7
- data.tar.gz: 73618a9cbae3b16028bcaa7dba64dda74e4324427fda3e364c7df0087ed72828f36965dae239bc0a2c37c1c7aece20950e0a0556a325e4cd10082e74c2da3429
6
+ metadata.gz: 0ba282fe4046bf7169648d3eecb0137fefd8882dc4c7dbf3c5af0f17cf0ef56ba948d0235668057656c53c709f9372ee155e6aa3aab211c265fdc322e1d9c4ba
7
+ data.tar.gz: f4e9646af425cdbe7a6827f0fd88e8c24717c6ea21921228ab72164a7e1b019071533f2576ba25b77bf02e3477a22e2d00d0a4df0d1cbfb985e6137c562dd1f1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 8.0.1
4
+ - Fix Cloudflare provider to handle paginated returns from API
5
+
6
+ ## 8.0.0
7
+ - Remove api_fqdn from Cloudflare provider config
8
+
3
9
  ## 7.1.1
4
10
  - Bugfix: Cloudflare provider now handles empty record sets properly
5
11
 
@@ -3,8 +3,9 @@ require_relative 'response'
3
3
 
4
4
  module Cloudflare
5
5
  class Client
6
- def initialize(api_fqdn, api_token)
7
- @api_fqdn = api_fqdn
6
+ API_FQDN = 'api.cloudflare.com'.freeze
7
+
8
+ def initialize(api_token)
8
9
  @api_token = api_token
9
10
  end
10
11
 
@@ -88,7 +89,7 @@ module Cloudflare
88
89
 
89
90
  def build_uri(endpoint, params = {})
90
91
  URI::HTTPS.build(
91
- host: @api_fqdn,
92
+ host: API_FQDN,
92
93
  path: endpoint.chomp('/'),
93
94
  query: URI.encode_www_form(params),
94
95
  )
@@ -27,6 +27,14 @@ module Cloudflare
27
27
  result
28
28
  end
29
29
 
30
+ def result_info_raw
31
+ result_info_raw = json['result_info']
32
+
33
+ return if result_info_raw.nil? || result_info_raw.empty? || !success
34
+
35
+ result_info_raw
36
+ end
37
+
30
38
  def success
31
39
  json['success']
32
40
  end
@@ -20,20 +20,50 @@ module RecordStore
20
20
  def retrieve_current_records(zone:, stdout: $stdout)
21
21
  zone_id = zone_name_to_id(zone)
22
22
 
23
- retry_on_connection_errors do
24
- records = client.get("/client/v4/zones/#{zone_id}/dns_records").result_raw || []
25
- records.map { |api_body| build_from_api(api_body) }
23
+ all_records = []
24
+ page = 1
25
+ per_page = 1000
26
+
27
+ loop do
28
+ response = nil
29
+ retry_on_connection_errors do
30
+ response = client.get("/client/v4/zones/#{zone_id}/dns_records", page: page, per_page: per_page)
31
+ end
32
+
33
+ records = response.result_raw || []
34
+ all_records.concat(records)
35
+
36
+ break if page * per_page >= response.result_info_raw['total_count']
37
+
38
+ page += 1
26
39
  end
40
+
41
+ all_records.map { |api_body| build_from_api(api_body) }
27
42
  end
28
43
 
29
44
  # Returns an array of the zones managed by provider as strings
30
45
  # Cloudflare returns zones across all accounts accessible by the API token
31
46
  # Can implement filtering in request if needed
32
47
  def zones
33
- retry_on_connection_errors do
34
- zones = client.get('/client/v4/zones').result_raw || []
35
- zones.map { |zone| zone['name'] }
48
+ all_zones = []
49
+ page = 1
50
+ per_page = 50
51
+
52
+ loop do
53
+ response = nil
54
+ retry_on_connection_errors do
55
+ response = client.get('/client/v4/zones', page: page, per_page: per_page)
56
+ end
57
+
58
+ zones = response.result_raw || []
59
+ all_zones.concat(zones)
60
+
61
+ break if page * per_page >= response.result_info_raw['total_count']
62
+
63
+ page += 1
36
64
  end
65
+
66
+ all_zones.map { |zone| zone['name'] }
37
67
  end
38
68
 
39
69
  def apply_changeset(changeset, stdout = $stdout)
@@ -167,14 +197,14 @@ module RecordStore
167
197
 
168
198
  def client
169
199
  Cloudflare::Client.new(
170
- secrets['api_fqdn'],
171
200
  secrets['api_token'],
172
201
  )
173
202
  end
174
203
 
175
204
  def zone_name_to_id(zone_name)
176
205
  retry_on_connection_errors do
177
- matching_zones = client.get('/client/v4/zones').result_raw.select { |zone| zone['name'] == zone_name }
206
+ params = { name: zone_name }
207
+ matching_zones = client.get("/client/v4/zones", params).result_raw
178
208
 
179
209
  case matching_zones.size
180
210
  when 0
@@ -1,3 +1,3 @@
1
1
  module RecordStore
2
- VERSION = '7.1.1'.freeze
2
+ VERSION = '8.0.1'.freeze
3
3
  end
@@ -25,7 +25,6 @@
25
25
  "client_x509_cert_url": "client_x509_cert_url"
26
26
  },
27
27
  "cloudflare": {
28
- "api_fqdn": "api.cloudflare.com",
29
28
  "api_token": "local-dev-key"
30
29
  }
31
30
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 8.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-10-22 00:00:00.000000000 Z
12
+ date: 2024-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel