From 68487459ffd50fab73460cbeac460afb9f8a590e Mon Sep 17 00:00:00 2001 From: Costa Shapiro Date: Thu, 5 Aug 2021 17:48:51 +0300 Subject: [PATCH 1/5] origin certificates setup and back-end CIDRs list; NO SPECS --- lib/cloudflare/certificates.rb | 49 ++++++++++++++++++++++++++++++++++ lib/cloudflare/connection.rb | 10 +++++++ lib/cloudflare/i_ps.rb | 13 +++++++++ 3 files changed, 72 insertions(+) create mode 100644 lib/cloudflare/certificates.rb create mode 100644 lib/cloudflare/i_ps.rb diff --git a/lib/cloudflare/certificates.rb b/lib/cloudflare/certificates.rb new file mode 100644 index 0000000..5f44819 --- /dev/null +++ b/lib/cloudflare/certificates.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +# Copyright, 2012, by Marcin Prokop. +# Copyright, 2017, by Samuel G. D. Williams. +# Copyright, 2017, by David Rosenbloom. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +require_relative 'representation' +require_relative 'paginate' + +module Cloudflare + + class Certificate < Representation + def certificate + value[:certificate] + end + end + + class Certificates < Representation + include Paginate + + def representation + Certificate + end + + def create(csr_pem, hostnames, request_type = 'origin-rsa', requested_validity = 5475) + attrs = + {csr: csr_pem, request_type: request_type, hostnames: hostnames, requested_validity: requested_validity} + represent_message(self.post(attrs)) + end + end +end diff --git a/lib/cloudflare/connection.rb b/lib/cloudflare/connection.rb index 86e9ad2..6f1cf2a 100644 --- a/lib/cloudflare/connection.rb +++ b/lib/cloudflare/connection.rb @@ -22,9 +22,11 @@ require_relative 'representation' +require_relative 'i_ps' require_relative 'zones' require_relative 'accounts' require_relative 'user' +require_relative 'certificates' module Cloudflare class Connection < Representation @@ -44,6 +46,10 @@ def authenticated(token: nil, key: nil, email: nil) self.with(headers: headers) end + + def cidrs(ipv: nil) + with(IPs, path: 'ips').cidrs(ipv: ipv) + end def zones self.with(Zones, path: 'zones') @@ -56,5 +62,9 @@ def accounts def user self.with(User, path: 'user') end + + def certificates + with(Certificates, path: 'certificates') + end end end diff --git a/lib/cloudflare/i_ps.rb b/lib/cloudflare/i_ps.rb new file mode 100644 index 0000000..4587c47 --- /dev/null +++ b/lib/cloudflare/i_ps.rb @@ -0,0 +1,13 @@ +require_relative 'representation' + +module Cloudflare + class IPs < Representation + def cidrs(ipv: nil) + if ipv + value[:"ipv#{ipv}_cidrs"] + else + value[:ipv4_cidrs].to_a + value[:ipv6_cidrs].to_a + end + end + end +end From a0d9522890f75c6aac8a2979e525e06733f92cd4 Mon Sep 17 00:00:00 2001 From: Costa Shapiro Date: Sun, 3 Oct 2021 23:33:28 +0300 Subject: [PATCH 2/5] oops (cleanup) --- lib/cloudflare/certificates.rb | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/cloudflare/certificates.rb b/lib/cloudflare/certificates.rb index 5f44819..7096ebd 100644 --- a/lib/cloudflare/certificates.rb +++ b/lib/cloudflare/certificates.rb @@ -1,27 +1,3 @@ -# frozen_string_literal: true - -# Copyright, 2012, by Marcin Prokop. -# Copyright, 2017, by Samuel G. D. Williams. -# Copyright, 2017, by David Rosenbloom. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - require_relative 'representation' require_relative 'paginate' From f41c21f7a6bbdc0eaaa42946c295e65a9d8513bf Mon Sep 17 00:00:00 2001 From: Costa Shapiro Date: Sat, 5 Jul 2025 17:08:12 +0300 Subject: [PATCH 3/5] oops upgrade --- lib/cloudflare/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloudflare/connection.rb b/lib/cloudflare/connection.rb index 6c38207..9fdf573 100644 --- a/lib/cloudflare/connection.rb +++ b/lib/cloudflare/connection.rb @@ -40,7 +40,7 @@ def authenticated(token: nil, key: nil, email: nil) end def cidrs(ipv: nil) - with(IPs, path: 'ips').cidrs(ipv: ipv) + IPs.new(self.with(path: 'ips').cidrs(ipv: ipv)) end def zones From 69e280738bd3b9d483c1627d3e3029cfeb7a9d3c Mon Sep 17 00:00:00 2001 From: Costa Shapiro Date: Sat, 5 Jul 2025 17:15:49 +0300 Subject: [PATCH 4/5] oooops typo --- lib/cloudflare/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloudflare/connection.rb b/lib/cloudflare/connection.rb index 9fdf573..b3e42f8 100644 --- a/lib/cloudflare/connection.rb +++ b/lib/cloudflare/connection.rb @@ -40,7 +40,7 @@ def authenticated(token: nil, key: nil, email: nil) end def cidrs(ipv: nil) - IPs.new(self.with(path: 'ips').cidrs(ipv: ipv)) + IPs.new(self.with(path: 'ips')).cidrs(ipv: ipv) end def zones From 1f7514cd296b6498a717390d980e565bacf21b64 Mon Sep 17 00:00:00 2001 From: Costa Shapiro Date: Sun, 6 Jul 2025 22:46:07 +0300 Subject: [PATCH 5/5] yeah, so, basically, testing in production, sorry about thaat --- lib/cloudflare/certificates.rb | 2 +- lib/cloudflare/i_ps.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cloudflare/certificates.rb b/lib/cloudflare/certificates.rb index 7096ebd..228c24a 100644 --- a/lib/cloudflare/certificates.rb +++ b/lib/cloudflare/certificates.rb @@ -5,7 +5,7 @@ module Cloudflare class Certificate < Representation def certificate - value[:certificate] + result[:certificate] end end diff --git a/lib/cloudflare/i_ps.rb b/lib/cloudflare/i_ps.rb index 4587c47..0de35e8 100644 --- a/lib/cloudflare/i_ps.rb +++ b/lib/cloudflare/i_ps.rb @@ -4,9 +4,9 @@ module Cloudflare class IPs < Representation def cidrs(ipv: nil) if ipv - value[:"ipv#{ipv}_cidrs"] + result[:"ipv#{ipv}_cidrs"] else - value[:ipv4_cidrs].to_a + value[:ipv6_cidrs].to_a + result[:ipv4_cidrs].to_a + result[:ipv6_cidrs].to_a end end end