cloudflair 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +38 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +10 -0
- data/Gemfile +2 -0
- data/README.md +4 -7
- data/Rakefile +2 -0
- data/VERSION +1 -0
- data/cloudflair.gemspec +9 -9
- data/lib/cloudflair/api/railguns.rb +2 -0
- data/lib/cloudflair/api/zone/analytics.rb +2 -0
- data/lib/cloudflair/api/zone/available_plan.rb +2 -0
- data/lib/cloudflair/api/zone/available_rate_plan.rb +2 -0
- data/lib/cloudflair/api/zone/custom_hostname.rb +19 -0
- data/lib/cloudflair/api/zone/dns_record.rb +3 -0
- data/lib/cloudflair/api/zone/purge_cache.rb +4 -2
- data/lib/cloudflair/api/zone/railgun.rb +2 -0
- data/lib/cloudflair/api/zone/settings/advanced_ddos.rb +2 -0
- data/lib/cloudflair/api/zone/settings/always_online.rb +2 -0
- data/lib/cloudflair/api/zone/settings/browser_cache_ttl.rb +2 -0
- data/lib/cloudflair/api/zone/settings/browser_check.rb +2 -0
- data/lib/cloudflair/api/zone/settings/cache_level.rb +2 -0
- data/lib/cloudflair/api/zone/settings/challenge_ttl.rb +2 -0
- data/lib/cloudflair/api/zone/settings/development_mode.rb +2 -0
- data/lib/cloudflair/api/zone/settings/email_obfuscation.rb +2 -0
- data/lib/cloudflair/api/zone/settings/hotlink_protection.rb +2 -0
- data/lib/cloudflair/api/zone/settings/ip_geolocation.rb +2 -0
- data/lib/cloudflair/api/zone/settings/ipv6.rb +2 -0
- data/lib/cloudflair/api/zone/settings/minify.rb +2 -0
- data/lib/cloudflair/api/zone/settings/mirage.rb +2 -0
- data/lib/cloudflair/api/zone/settings/mobile_redirect.rb +2 -0
- data/lib/cloudflair/api/zone/settings/origin_error_page_pass_thru.rb +2 -0
- data/lib/cloudflair/api/zone/settings/polish.rb +2 -0
- data/lib/cloudflair/api/zone/settings/prefetch_preload.rb +2 -0
- data/lib/cloudflair/api/zone/settings/response_buffering.rb +2 -0
- data/lib/cloudflair/api/zone/settings/rocket_loader.rb +2 -0
- data/lib/cloudflair/api/zone/settings/security_header.rb +2 -0
- data/lib/cloudflair/api/zone/settings/security_level.rb +2 -0
- data/lib/cloudflair/api/zone/settings/server_side_exclude.rb +2 -0
- data/lib/cloudflair/api/zone/settings/sort_query_string_for_cache.rb +2 -0
- data/lib/cloudflair/api/zone/settings/ssl.rb +2 -0
- data/lib/cloudflair/api/zone/settings/tls_1_2_only.rb +2 -0
- data/lib/cloudflair/api/zone/settings/tls_1_3.rb +2 -0
- data/lib/cloudflair/api/zone/settings/tls_client_auth.rb +2 -0
- data/lib/cloudflair/api/zone/settings/true_client_ip_header.rb +2 -0
- data/lib/cloudflair/api/zone/settings/waf.rb +2 -0
- data/lib/cloudflair/api/zone/settings/websockets.rb +2 -0
- data/lib/cloudflair/api/zone/settings.rb +30 -28
- data/lib/cloudflair/api/zone.rb +3 -0
- data/lib/cloudflair/api/zone__available_plans.rb +2 -0
- data/lib/cloudflair/api/zone__custom_hostnames.rb +31 -0
- data/lib/cloudflair/api/zone__dns_records.rb +2 -2
- data/lib/cloudflair/api/zone__railguns.rb +2 -0
- data/lib/cloudflair/api.rb +2 -0
- data/lib/cloudflair/communication.rb +23 -20
- data/lib/cloudflair/connection.rb +21 -12
- data/lib/cloudflair/entity.rb +41 -42
- data/lib/cloudflair/error/cloudflair_error.rb +2 -0
- data/lib/cloudflair/error/cloudflare_error.rb +2 -0
- data/lib/cloudflair/version.rb +2 -1
- data/lib/cloudflair.rb +4 -2
- metadata +35 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 966bf25156f0cedddd418a9b070227eb819e128984175fe2da2aaca46189da7a
|
4
|
+
data.tar.gz: 2da3f8e7083bc2534ef799125b57294521030581724dd6247327f8fb93b47195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de912a3e2901d8f4d70caf78fe489789953100b0afa83b19743ab9c648f3e7bf8674454a62db79d58e83163b7e9da54100ce01cb456a931de1380ac90ffb68e9
|
7
|
+
data.tar.gz: a36444251a1c61347f2c5990ac9ba749002cbba09e62be188a881a645ca30da4ddf43cbd8dbaadb77a3b421c57eabf5ced3789b45991d87c8ac9607da67eb8ea
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- 'bin/**/*'
|
8
|
+
- 'db/**/*'
|
9
|
+
TargetRubyVersion: 2.6.1
|
10
|
+
|
11
|
+
Layout/AlignHash:
|
12
|
+
EnforcedColonStyle: table
|
13
|
+
EnforcedHashRocketStyle: table
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Exclude:
|
17
|
+
- Guardfile
|
18
|
+
- 'spec/**/*spec.rb'
|
19
|
+
|
20
|
+
Metrics/LineLength:
|
21
|
+
Exclude:
|
22
|
+
- Guardfile
|
23
|
+
Max: 110
|
24
|
+
|
25
|
+
Rails:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Rails/HttpPositionalArguments:
|
29
|
+
Exclude:
|
30
|
+
|
31
|
+
Rails/SkipsModelValidations:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
RSpec/MultipleExpectations:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cloudflair
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.5
|
data/.travis.yml
CHANGED
@@ -9,3 +9,13 @@ notifications:
|
|
9
9
|
on_success: never
|
10
10
|
slack:
|
11
11
|
secure: o1rlXNKZgQUIIfpzz//KpClcUS/ea5ECbbTaexQYHn84hqPNlsBdWhSrLg2s6MIJ1zSml4NBKQgwQJCV/6keel06XeNPvGPdQLVmSsBCWS4EJ/CvAAsXadghmSDYdsZlTaXvwa2ZdIaCHrM/SncZYi7I+KIiGsbV0KJgYVTlWGPWuN1kh3od1Ixw6W+TFUKONz8OqVFGo2yCr68zDtxUvrY8G/TNRRtWUINHPSIHL7+7JxzOtDZKOITptcLii8tmqi07HtmU7+78lDMlze8ejhchEDKoycTwVOQDRxjjLbDKZsV33nqG5XYRqW8FQv6zJ2c3eCfd2M2Lm+WkPe/ZBQ25Ok4/wK35T0oPt5lW6LKRNt202nQiI6vqn54489knOUpvA60z2r6taIgI3Os8kCdG8rX95Hob4gpU4zLqPNz26vqGiB0vz4DFSJWpRlYK15YT7SpEEMW2luPcTGHaclRSUFgjo/JkVH6zg+1rcMW4ZbKoxJZoNu+nmk9m1Xaz0r5tfJHBzB5XguRcKakRWkhb0rV4Nvo1as1PFtpxt9tiZsIXNTDNtf+upQeJs1Tevm6z4zBGXOIp//MIJEUyUkJ7Fkb+pyRbDOh30JSQJs0Z1y+/LA0rNkbQ+/jjeoKAepnFvawsXZF6UVWZxsBzAkIWTe+bwghnxX4Gm454RiI=
|
12
|
+
deploy:
|
13
|
+
provider: rubygems
|
14
|
+
api_key:
|
15
|
+
secure: GisVn77etjRfIwmjsktJVFU182lSuZqbQBsb8jkMoBr0/01fE/tWpZHOMNnKU5JoIaaQAGA0F1w+OXk/eAldvWHbu++074/XcgGerMBV5kxhBOpKEaSu5/cxUfgtGIi2eBBS4xe+GEwtlkI08c6BCiX9pUuUn8LwuUvN7NLNd7nLnZhhnawAoG75aWoMXnudqbIoX/1kGIem8XMuugWwxcr7PsnBy43Mj3yYXmtbO5IW4LC1sDywYc3O/lHmC7hner5yFJSa3kCNN9IMEieRW8/bZAlu3HncfJoORha3tZq37Po/kV8OBuYMoHwxQouCnrh0OW3QNrsmFF+tTy8z132GDjOIaNHwKZyvtXHgfmq4KXdSU5dTlDR5U4Z7jFTbOifc1+UuU1B3RHMHsrqtJgb5ihoXAjtZI8JSjQ7aI+bX9aSt3OpELymuAzoW1mV/Rf4kuNq23jmgDKBEhnR6YdQ864pFGnPL00kPhMUQ+iVX4OFQMZ2/eayYuNGz1LV1WDfFoFSsinZtr/erNnziYJHuzULfFdVg7+ZGMkmLFl7RHiRlphrylW+IN0K+hKEaTDFJ/yVYlLvr/OakR2l4kiPlxfQPXAtmh4MRe1vJdyT3RlGha9qecPddGuzWw3kG8A8bJv9H15YaplHRsu8HryMH5Zt5Tup8cnN37kMrILg=
|
16
|
+
gem: cloudflair
|
17
|
+
on:
|
18
|
+
tags: true
|
19
|
+
repo: ninech/cloudflair
|
20
|
+
condition: "$TRAVIS_RUBY_VERSION == 2.4"
|
21
|
+
skip_cleanup: true
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
|
6
6
|
A simple Ruby-wrapper around Cloudflare's v4 API.
|
7
7
|
|
8
|
-
![Animation of Homer Simpson using of a rescue flare.](https://media.giphy.com/media/n8A8omwp1mVAA/giphy.gif)
|
9
|
-
|
10
8
|
## Installation
|
11
9
|
|
12
10
|
Add this line to your application's Gemfile:
|
@@ -114,9 +112,10 @@ A good reference on how to use this wrapper are also the Rspecs.
|
|
114
112
|
* `/zones/:zone_id/available_plans` GET
|
115
113
|
* `/zones/:zone_id/available_plans/:plan_id` GET
|
116
114
|
* `/zones/:zone_id/available_rate_plans`
|
115
|
+
* `/zones/:zone_id/custom_hostnames` GET, POST, PATCH
|
117
116
|
* `/zones/:zone_id/dns_records` GET, POST
|
118
117
|
* `/zones/:zone_id/dns_records/:record_id` GET, DELETE (PUT not implemented)
|
119
|
-
* `/zones/:zone_id/purge_cache`
|
118
|
+
* `/zones/:zone_id/purge_cache` POST
|
120
119
|
* `/zones/:zone_id/railguns` GET
|
121
120
|
* `/zones/:zone_id/railguns/:railgun_id` GET
|
122
121
|
* `/zones/:zone_id/railguns/:railgun_id/diagnose` GET, PATCH
|
@@ -180,8 +179,6 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
180
179
|
|
181
180
|
## About
|
182
181
|
|
183
|
-
This gem is currently maintained and funded by [nine
|
184
|
-
|
185
|
-
[![nine.ch Logo](https://blog.nine.ch/assets/logo.png)](https://nine.ch)
|
182
|
+
This gem is currently maintained and funded by [nine](https://nine.ch).
|
186
183
|
|
187
|
-
|
184
|
+
[![logo of the company 'nine'](https://logo.apps.at-nine.ch/Dmqied_eSaoBMQwk3vVgn4UIgDo=/trim/500x0/logo_claim.png)](https://www.nine.ch)
|
data/Rakefile
CHANGED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
data/cloudflair.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'cloudflair/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'cloudflair'
|
9
|
-
spec.version =
|
9
|
+
spec.version = File.read('VERSION')
|
10
10
|
spec.authors = ['Christian Mäder']
|
11
|
-
spec.email = %w
|
11
|
+
spec.email = %w[christian.maeder@nine.ch]
|
12
12
|
|
13
13
|
spec.summary = "Wrapper to CloudFlare's v4 REST API."
|
14
14
|
spec.description = "Cloudflair aims to provide easy access to CloudFlare's public API."
|
@@ -22,15 +22,15 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = %w[lib]
|
24
24
|
|
25
|
+
spec.add_runtime_dependency "dry-configurable", "> 0.12"
|
25
26
|
spec.add_runtime_dependency 'faraday', '>= 0.10.0'
|
26
|
-
spec.add_runtime_dependency 'faraday_middleware'
|
27
|
-
spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
|
28
27
|
spec.add_runtime_dependency 'faraday-detailed_logger'
|
28
|
+
spec.add_runtime_dependency 'faraday_middleware'
|
29
29
|
|
30
|
-
spec.add_development_dependency 'bundler', '~> 1.12'
|
31
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
30
|
spec.add_development_dependency 'dotenv', '~> 2.1'
|
31
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
33
|
spec.add_development_dependency 'rubocop', '~> 0.48'
|
34
|
+
spec.add_development_dependency 'rubocop-performance'
|
35
35
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.15'
|
36
36
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cloudflair/entity'
|
4
|
+
|
5
|
+
module Cloudflair
|
6
|
+
class CustomHostname
|
7
|
+
include Cloudflair::Entity
|
8
|
+
|
9
|
+
attr_reader :zone_id, :custom_hostname_id
|
10
|
+
deletable true
|
11
|
+
patchable_fields :ssl, :custom_origin_server, :custom_metadata
|
12
|
+
path 'zones/:zone_id/custom_hostnames/:custom_hostname_id'
|
13
|
+
|
14
|
+
def initialize(zone_id, custom_hostname_id)
|
15
|
+
@zone_id = zone_id
|
16
|
+
@custom_hostname_id = custom_hostname_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/entity'
|
2
4
|
|
3
5
|
module Cloudflair
|
@@ -6,6 +8,7 @@ module Cloudflair
|
|
6
8
|
|
7
9
|
attr_reader :zone_id, :record_id
|
8
10
|
deletable true
|
11
|
+
patchable_fields :content
|
9
12
|
path 'zones/:zone_id/dns_records/:record_id'
|
10
13
|
|
11
14
|
def initialize(zone_id, record_id)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/communication'
|
2
4
|
|
3
5
|
module Cloudflair
|
@@ -13,7 +15,7 @@ module Cloudflair
|
|
13
15
|
##
|
14
16
|
# @param purge_everything must be set to true
|
15
17
|
def everything(purge_everything)
|
16
|
-
resp = connection.
|
18
|
+
resp = connection.post(path) { |req| req.body = { purge_everything: purge_everything } }
|
17
19
|
response resp
|
18
20
|
self
|
19
21
|
end
|
@@ -23,7 +25,7 @@ module Cloudflair
|
|
23
25
|
def selective(cache_identifier = {})
|
24
26
|
return self if cache_identifier.nil? || cache_identifier.empty?
|
25
27
|
|
26
|
-
resp = connection.
|
28
|
+
resp = connection.post(path) { |req| req.body = cache_identifier }
|
27
29
|
response resp
|
28
30
|
self
|
29
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/api/zone/settings/advanced_ddos'
|
2
4
|
require 'cloudflair/api/zone/settings/always_online'
|
3
5
|
require 'cloudflair/api/zone/settings/browser_cache_ttl'
|
@@ -38,36 +40,36 @@ module Cloudflair
|
|
38
40
|
end
|
39
41
|
|
40
42
|
{
|
41
|
-
advanced_ddos:
|
42
|
-
always_online:
|
43
|
-
browser_cache_ttl:
|
44
|
-
browser_check:
|
45
|
-
cache_level:
|
46
|
-
challenge_ttl:
|
47
|
-
development_mode:
|
48
|
-
email_obfuscation:
|
49
|
-
hotlink_protection:
|
50
|
-
ip_geolocation:
|
51
|
-
ipv6:
|
52
|
-
minify:
|
53
|
-
mirage:
|
54
|
-
mobile_redirect:
|
43
|
+
advanced_ddos: Cloudflair::AdvancedDdos,
|
44
|
+
always_online: Cloudflair::AlwaysOnline,
|
45
|
+
browser_cache_ttl: Cloudflair::BrowserCacheTtl,
|
46
|
+
browser_check: Cloudflair::BrowserCheck,
|
47
|
+
cache_level: Cloudflair::CacheLevel,
|
48
|
+
challenge_ttl: Cloudflair::ChallengeTtl,
|
49
|
+
development_mode: Cloudflair::DevelopmentMode,
|
50
|
+
email_obfuscation: Cloudflair::EmailObfuscation,
|
51
|
+
hotlink_protection: Cloudflair::HotlinkProtection,
|
52
|
+
ip_geolocation: Cloudflair::IpGeolocation,
|
53
|
+
ipv6: Cloudflair::Ipv6,
|
54
|
+
minify: Cloudflair::Minify,
|
55
|
+
mirage: Cloudflair::Mirage,
|
56
|
+
mobile_redirect: Cloudflair::MobileRedirect,
|
55
57
|
origin_error_page_pass_thru: Cloudflair::OriginErrorPagePassThru,
|
56
|
-
polish:
|
57
|
-
prefetch_preload:
|
58
|
-
response_buffering:
|
59
|
-
rocket_loader:
|
60
|
-
security_header:
|
61
|
-
security_level:
|
62
|
-
server_side_exclude:
|
58
|
+
polish: Cloudflair::Polish,
|
59
|
+
prefetch_preload: Cloudflair::PrefetchPreload,
|
60
|
+
response_buffering: Cloudflair::ResponseBuffering,
|
61
|
+
rocket_loader: Cloudflair::RocketLoader,
|
62
|
+
security_header: Cloudflair::SecurityHeader,
|
63
|
+
security_level: Cloudflair::SecurityLevel,
|
64
|
+
server_side_exclude: Cloudflair::ServerSideExclude,
|
63
65
|
sort_query_string_for_cache: Cloudflair::SortQueryStringForCache,
|
64
|
-
ssl:
|
65
|
-
tls_client_auth:
|
66
|
-
tls_1_2_only:
|
67
|
-
tls_1_3:
|
68
|
-
true_client_ip_header:
|
69
|
-
waf:
|
70
|
-
websockets:
|
66
|
+
ssl: Cloudflair::Ssl,
|
67
|
+
tls_client_auth: Cloudflair::TlsClientAuth,
|
68
|
+
tls_1_2_only: Cloudflair::Tls12Only,
|
69
|
+
tls_1_3: Cloudflair::Tls13,
|
70
|
+
true_client_ip_header: Cloudflair::TrueClientIpHeader,
|
71
|
+
waf: Cloudflair::Waf,
|
72
|
+
websockets: Cloudflair::Websockets
|
71
73
|
}.each do |method, klass|
|
72
74
|
define_method method do
|
73
75
|
klass.new @zone_id
|
data/lib/cloudflair/api/zone.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/api/zone/analytics'
|
2
4
|
require 'cloudflair/api/zone/available_plan'
|
3
5
|
require 'cloudflair/api/zone/available_rate_plan'
|
@@ -12,6 +14,7 @@ module Cloudflair
|
|
12
14
|
require 'cloudflair/api/zone__dns_records'
|
13
15
|
require 'cloudflair/api/zone__available_plans'
|
14
16
|
require 'cloudflair/api/zone__railguns'
|
17
|
+
require 'cloudflair/api/zone__custom_hostnames'
|
15
18
|
|
16
19
|
attr_reader :zone_id
|
17
20
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cloudflair/api/zone/custom_hostname'
|
4
|
+
|
5
|
+
module Cloudflair
|
6
|
+
class Zone
|
7
|
+
def custom_hostnames(filter = {})
|
8
|
+
raw_hostnames = response connection.get("#{path}/custom_hostnames", filter)
|
9
|
+
|
10
|
+
raw_hostnames.map { |raw_hostname| build_custom_hostname(raw_hostname) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def custom_hostname(custom_hostname_id)
|
14
|
+
Cloudflair::CustomHostname.new zone_id, custom_hostname_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def new_custom_hostname(hostname_data)
|
18
|
+
raw_hostname = response connection.post("#{path}/custom_hostnames", hostname_data)
|
19
|
+
|
20
|
+
build_custom_hostname raw_hostname
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_custom_hostname(raw_hostname)
|
26
|
+
hostname = custom_hostname raw_hostname['id']
|
27
|
+
hostname.data = raw_hostname
|
28
|
+
hostname
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/api/zone/dns_record'
|
2
4
|
|
3
5
|
module Cloudflair
|
4
6
|
class Zone
|
5
7
|
def dns_records(filter = {})
|
6
8
|
raw_records = response connection.get("#{path}/dns_records", filter)
|
7
|
-
|
8
9
|
raw_records.map { |raw_record| build_dns_record(raw_record) }
|
9
10
|
end
|
10
11
|
|
@@ -14,7 +15,6 @@ module Cloudflair
|
|
14
15
|
|
15
16
|
def new_dns_record(record_data)
|
16
17
|
raw_record = response connection.post("#{path}/dns_records", record_data)
|
17
|
-
|
18
18
|
build_dns_record raw_record
|
19
19
|
end
|
20
20
|
|
data/lib/cloudflair/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/error/cloudflare_error'
|
2
4
|
require 'cloudflair/error/cloudflair_error'
|
3
5
|
require 'cloudflair/connection'
|
@@ -35,8 +37,9 @@ module Cloudflair
|
|
35
37
|
body = response.body
|
36
38
|
|
37
39
|
unless body['success']
|
38
|
-
|
39
|
-
|
40
|
+
raise Cloudflair::CloudflairError, "Unrecognized response format: '#{body}'" unless body['errors']
|
41
|
+
|
42
|
+
raise Cloudflair::CloudflareError, body['errors']
|
40
43
|
end
|
41
44
|
|
42
45
|
body['result']
|
@@ -44,32 +47,32 @@ module Cloudflair
|
|
44
47
|
|
45
48
|
def raise_on_http_error(status)
|
46
49
|
case status
|
47
|
-
when 200..399
|
48
|
-
when 400..499
|
50
|
+
when 200..399
|
51
|
+
when 400..499
|
49
52
|
raise_on_http_client_error status
|
50
|
-
when 500..599
|
51
|
-
|
53
|
+
when 500..599
|
54
|
+
raise Cloudflair::CloudflairError, "#{status} Remote Error"
|
52
55
|
else
|
53
|
-
|
56
|
+
raise Cloudflair::CloudflairError, "#{status} Unknown Error Code"
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def raise_on_http_client_error(status)
|
58
61
|
case status
|
59
|
-
when 400
|
60
|
-
|
61
|
-
when 401
|
62
|
-
|
63
|
-
when 403
|
64
|
-
|
65
|
-
when 405
|
66
|
-
|
67
|
-
when 415
|
68
|
-
|
69
|
-
when 429
|
70
|
-
|
62
|
+
when 400
|
63
|
+
raise Cloudflair::CloudflairError, '400 Bad Request'
|
64
|
+
when 401
|
65
|
+
raise Cloudflair::CloudflairError, '401 Unauthorized'
|
66
|
+
when 403
|
67
|
+
raise Cloudflair::CloudflairError, '403 Forbidden'
|
68
|
+
when 405
|
69
|
+
raise Cloudflair::CloudflairError, '405 Method Not Allowed'
|
70
|
+
when 415
|
71
|
+
raise Cloudflair::CloudflairError, '415 Unsupported Media Type'
|
72
|
+
when 429
|
73
|
+
raise Cloudflair::CloudflairError, '429 Too Many Requests'
|
71
74
|
else
|
72
|
-
|
75
|
+
raise Cloudflair::CloudflairError, "#{status} Request Error"
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
require 'faraday/detailed_logger'
|
@@ -7,25 +9,32 @@ module Cloudflair
|
|
7
9
|
class Connection
|
8
10
|
def self.new
|
9
11
|
config = Cloudflair.config
|
10
|
-
|
11
12
|
new_faraday_from config
|
12
13
|
end
|
13
14
|
|
14
|
-
def self.headers
|
15
|
-
headers = {}
|
15
|
+
def self.headers # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
16
16
|
cloudflare_auth_config = Cloudflair.config.cloudflare.auth
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
raise CloudflairError, 'Neither email & key nor user_service_key have been defined.'
|
17
|
+
|
18
|
+
if !cloudflare_auth_config.key.nil? && !cloudflare_auth_config.email.nil?
|
19
|
+
return({
|
20
|
+
'X-Auth-Key' => cloudflare_auth_config.key,
|
21
|
+
'X-Auth-Email' => cloudflare_auth_config.email
|
22
|
+
})
|
24
23
|
end
|
25
|
-
|
24
|
+
|
25
|
+
unless cloudflare_auth_config.user_service_key.nil?
|
26
|
+
return({
|
27
|
+
'Authorization' => "Bearer #{cloudflare_auth_config.user_service_key}"
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
raise(
|
32
|
+
CloudflairError,
|
33
|
+
'Neither email & key nor user_service_key have been defined.'
|
34
|
+
)
|
26
35
|
end
|
27
36
|
|
28
|
-
private_class_method def self.new_faraday_from(config)
|
37
|
+
private_class_method def self.new_faraday_from(config) # rubocop:disable Metrics/AbcSize
|
29
38
|
Faraday.new(url: config.cloudflare.api_base_url, headers: headers) do |faraday|
|
30
39
|
faraday.request :json
|
31
40
|
faraday.response config.faraday.logger if config.faraday.logger
|
data/lib/cloudflair/entity.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/communication'
|
2
4
|
|
3
5
|
module Cloudflair
|
@@ -16,13 +18,14 @@ module Cloudflair
|
|
16
18
|
def patchable_fields(*fields)
|
17
19
|
return @patchable_fields if @patchable_fields
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
@patchable_fields =
|
22
|
+
if fields.nil?
|
23
|
+
[]
|
24
|
+
elsif fields.is_a?(Array)
|
25
|
+
fields.map(&:to_s)
|
26
|
+
else
|
27
|
+
[fields.to_s]
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def deletable(deletable = false)
|
@@ -34,7 +37,7 @@ module Cloudflair
|
|
34
37
|
def path(path = nil)
|
35
38
|
return @path if @path
|
36
39
|
|
37
|
-
|
40
|
+
raise ArgumentError, 'path is not defined' if path.nil?
|
38
41
|
|
39
42
|
@path = path
|
40
43
|
end
|
@@ -42,11 +45,12 @@ module Cloudflair
|
|
42
45
|
def object_fields(*fields)
|
43
46
|
return @object_fields if @object_fields
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
@object_fields =
|
49
|
+
if fields.nil? || fields.empty?
|
50
|
+
[]
|
51
|
+
else
|
52
|
+
fields.map(&:to_s)
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
# allowed values:
|
@@ -69,17 +73,17 @@ module Cloudflair
|
|
69
73
|
end
|
70
74
|
|
71
75
|
def turn_all_items_into_a_single_hash(fields_to_class_map)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
{}.tap do |fields_map|
|
77
|
+
fields_to_class_map.each do |field_definition|
|
78
|
+
if field_definition.is_a?(Hash)
|
79
|
+
fields_to_class_map[0].each do |field, klass_or_proc|
|
80
|
+
fields_map[field.to_s] = klass_or_proc
|
81
|
+
end
|
82
|
+
else
|
83
|
+
fields_map[field_definition.to_s] = nil
|
77
84
|
end
|
78
|
-
else
|
79
|
-
fields_map[field_definition.to_s] = nil
|
80
85
|
end
|
81
86
|
end
|
82
|
-
fields_map
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -102,7 +106,7 @@ module Cloudflair
|
|
102
106
|
end
|
103
107
|
|
104
108
|
def delete
|
105
|
-
|
109
|
+
raise Cloudflair::CloudflairError, "Can't delete unless deletable=true" unless deletable
|
106
110
|
return self if @deleted
|
107
111
|
|
108
112
|
@data = response connection.delete path
|
@@ -126,27 +130,23 @@ module Cloudflair
|
|
126
130
|
def method_missing(name_as_symbol, *args, &block)
|
127
131
|
name = normalize_accessor name_as_symbol
|
128
132
|
|
129
|
-
return data if :_raw_data!
|
133
|
+
return data if name_as_symbol == :_raw_data!
|
130
134
|
|
131
135
|
if name.end_with?('=')
|
132
136
|
if patchable_fields.include?(name[0..-2])
|
133
137
|
dirty_data[name[0..-2]] = args[0]
|
134
138
|
return
|
135
|
-
else
|
136
|
-
super
|
137
139
|
end
|
138
|
-
end
|
139
140
|
|
140
|
-
|
141
|
-
if name.end_with?('!') && data.keys.include?(name[0..-2])
|
142
|
-
return data[name[0..2]]
|
141
|
+
super
|
143
142
|
end
|
144
143
|
|
144
|
+
# allow access to the unmodified data using 'zone.always_string!' or 'zone._name!'
|
145
|
+
return data[name[0..2]] if name.end_with?('!') && data.key?(name[0..-2])
|
145
146
|
return objectify(name) if object_fields.include? name
|
146
|
-
return arrayify(name, array_object_fields[name]) if array_object_fields.
|
147
|
-
|
148
|
-
return
|
149
|
-
return data[name] if data.is_a?(Hash) && data.keys.include?(name)
|
147
|
+
return arrayify(name, array_object_fields[name]) if array_object_fields.key?(name)
|
148
|
+
return dirty_data[name] if dirty_data.key?(name)
|
149
|
+
return data[name] if data.is_a?(Hash) && data.key?(name)
|
150
150
|
|
151
151
|
super
|
152
152
|
end
|
@@ -154,16 +154,13 @@ module Cloudflair
|
|
154
154
|
def respond_to_missing?(name_as_symbol, *args)
|
155
155
|
name = normalize_accessor name_as_symbol
|
156
156
|
|
157
|
-
return true if :_raw_data!
|
158
|
-
|
157
|
+
return true if name_as_symbol == :_raw_data!
|
159
158
|
return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
|
160
|
-
return true if name.end_with?('!') && data.
|
161
|
-
|
159
|
+
return true if name.end_with?('!') && data.key?(name[0..-2])
|
162
160
|
return true if object_fields.include? name
|
163
|
-
return true if array_object_fields.
|
164
|
-
|
165
|
-
return true if
|
166
|
-
return true if data.is_a?(Hash) && data.keys.include?(name)
|
161
|
+
return true if array_object_fields.key?(name)
|
162
|
+
return true if dirty_data.key?(name)
|
163
|
+
return true if data.is_a?(Hash) && data.key?(name)
|
167
164
|
|
168
165
|
super
|
169
166
|
end
|
@@ -235,9 +232,11 @@ module Cloudflair
|
|
235
232
|
|
236
233
|
def replace_path_variables_in(path)
|
237
234
|
interpreted_path = path.clone
|
235
|
+
|
238
236
|
path.scan(/:([a-zA-Z_][a-zA-Z0-9_]+[!?=]?)/) do |match, *|
|
239
|
-
interpreted_path.gsub
|
237
|
+
interpreted_path = interpreted_path.gsub ":#{match}", send(match).to_s
|
240
238
|
end
|
239
|
+
|
241
240
|
interpreted_path
|
242
241
|
end
|
243
242
|
|
data/lib/cloudflair/version.rb
CHANGED
data/lib/cloudflair.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflair/api'
|
2
4
|
require 'cloudflair/version'
|
3
5
|
require 'dry-configurable'
|
@@ -25,7 +27,7 @@ module Cloudflair
|
|
25
27
|
extend Dry::Configurable
|
26
28
|
|
27
29
|
setting :cloudflare do
|
28
|
-
setting :api_base_url,
|
30
|
+
setting :api_base_url, default: "https://api.cloudflare.com/client/v4/"
|
29
31
|
setting :auth do
|
30
32
|
setting :key
|
31
33
|
setting :email
|
@@ -34,7 +36,7 @@ module Cloudflair
|
|
34
36
|
end
|
35
37
|
|
36
38
|
setting :faraday do
|
37
|
-
setting :adapter, :net_http
|
39
|
+
setting :adapter, default: :net_http
|
38
40
|
setting :logger
|
39
41
|
end
|
40
42
|
end
|
metadata
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Mäder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-configurable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.10.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.10.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faraday-detailed_logger
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: faraday_middleware
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,33 +67,33 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: dotenv
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1
|
75
|
+
version: '2.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1
|
82
|
+
version: '2.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '12.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '12.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,33 +109,33 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0.48'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '0.48'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop
|
126
|
+
name: rubocop-performance
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rubocop-rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,12 +159,15 @@ extra_rdoc_files: []
|
|
159
159
|
files:
|
160
160
|
- ".gitignore"
|
161
161
|
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".ruby-gemset"
|
162
164
|
- ".ruby-version"
|
163
165
|
- ".travis.yml"
|
164
166
|
- Gemfile
|
165
167
|
- LICENSE.txt
|
166
168
|
- README.md
|
167
169
|
- Rakefile
|
170
|
+
- VERSION
|
168
171
|
- bin/cloudflair
|
169
172
|
- bin/console
|
170
173
|
- bin/setup
|
@@ -176,6 +179,7 @@ files:
|
|
176
179
|
- lib/cloudflair/api/zone/analytics.rb
|
177
180
|
- lib/cloudflair/api/zone/available_plan.rb
|
178
181
|
- lib/cloudflair/api/zone/available_rate_plan.rb
|
182
|
+
- lib/cloudflair/api/zone/custom_hostname.rb
|
179
183
|
- lib/cloudflair/api/zone/dns_record.rb
|
180
184
|
- lib/cloudflair/api/zone/purge_cache.rb
|
181
185
|
- lib/cloudflair/api/zone/railgun.rb
|
@@ -211,6 +215,7 @@ files:
|
|
211
215
|
- lib/cloudflair/api/zone/settings/waf.rb
|
212
216
|
- lib/cloudflair/api/zone/settings/websockets.rb
|
213
217
|
- lib/cloudflair/api/zone__available_plans.rb
|
218
|
+
- lib/cloudflair/api/zone__custom_hostnames.rb
|
214
219
|
- lib/cloudflair/api/zone__dns_records.rb
|
215
220
|
- lib/cloudflair/api/zone__railguns.rb
|
216
221
|
- lib/cloudflair/communication.rb
|
@@ -239,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
244
|
- !ruby/object:Gem::Version
|
240
245
|
version: '0'
|
241
246
|
requirements: []
|
242
|
-
|
243
|
-
rubygems_version: 2.5.2
|
247
|
+
rubygems_version: 3.1.6
|
244
248
|
signing_key:
|
245
249
|
specification_version: 4
|
246
250
|
summary: Wrapper to CloudFlare's v4 REST API.
|