cloud_party 0.1.0.pre.pre.1
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 +7 -0
- data/.codeclimate.yml +11 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +33 -0
- data/.rubocop_config.yml +3199 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +144 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/cloud_party.gemspec +36 -0
- data/lib/cloud_party.rb +40 -0
- data/lib/cloud_party/config.rb +33 -0
- data/lib/cloud_party/context.rb +15 -0
- data/lib/cloud_party/exception.rb +61 -0
- data/lib/cloud_party/exceptions.rb +6 -0
- data/lib/cloud_party/exceptions/bad_request_400.rb +24 -0
- data/lib/cloud_party/nodes.rb +8 -0
- data/lib/cloud_party/nodes/ips.rb +24 -0
- data/lib/cloud_party/nodes/memberships.rb +28 -0
- data/lib/cloud_party/response.rb +11 -0
- data/lib/cloud_party/responses.rb +8 -0
- data/lib/cloud_party/responses/ips.rb +137 -0
- data/lib/cloud_party/responses/memberships.rb +147 -0
- data/lib/cloud_party/responses/nodes.rb +10 -0
- data/lib/cloud_party/responses/nodes/memberships.rb +4 -0
- data/lib/cloud_party/responses/nodes/memberships/account.rb +46 -0
- data/lib/cloud_party/responses/nodes/memberships/permissions.rb +28 -0
- data/lib/cloud_party/simple.rb +38 -0
- data/lib/cloud_party/version.rb +5 -0
- metadata +241 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cloud_party/context'
|
4
|
+
require 'cloud_party/responses'
|
5
|
+
module CloudParty
|
6
|
+
module Nodes
|
7
|
+
class IPs < CloudParty::Context
|
8
|
+
include HTTParty
|
9
|
+
base_uri 'api.cloudflare.com:443/client/v4'
|
10
|
+
headers 'X-Auth-Email' => cfg.email,
|
11
|
+
'X-Auth-Key' => cfg.api_key,
|
12
|
+
'Content-Type' => 'application/json',
|
13
|
+
'User-Agent' => "CloudParty/#{CloudParty::VERSION}"
|
14
|
+
|
15
|
+
def initialize(options = nil)
|
16
|
+
super()
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
def list
|
20
|
+
CloudParty::Responses::IPs.new(:get, '/ips', self.class.get('/ips'), @options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cloud_party/context'
|
4
|
+
require 'cloud_party/responses'
|
5
|
+
module CloudParty
|
6
|
+
module Nodes
|
7
|
+
class Memberships < CloudParty::Context
|
8
|
+
include HTTParty
|
9
|
+
base_uri 'api.cloudflare.com:443/client/v4'
|
10
|
+
headers 'X-Auth-Email' => cfg.email,
|
11
|
+
'X-Auth-Key' => cfg.api_key,
|
12
|
+
'Content-Type' => 'application/json',
|
13
|
+
'User-Agent' => "CloudParty/#{CloudParty::VERSION}"
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
super()
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def list
|
21
|
+
CloudParty::Responses::Memberships.new(:get, '/memberships', self.class.get('/memberships', @options))
|
22
|
+
rescue APIError => e
|
23
|
+
puts e.message
|
24
|
+
puts e.response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'cloud_party/responses/nodes/ips'
|
4
|
+
module CloudParty
|
5
|
+
module Responses
|
6
|
+
#
|
7
|
+
class IPs
|
8
|
+
def initialize(method_name, endpoint, response, options)
|
9
|
+
@code = response.code
|
10
|
+
@body = JSON.parse(response.body, symbolize_names: true)
|
11
|
+
@success = @body[:success]
|
12
|
+
unless successful?
|
13
|
+
message = <<~MESSAGE
|
14
|
+
Unable to #{method_name.to_s.upcase} to endpoint:
|
15
|
+
#{endpoint}. Inspect CloudParty::APIError#response
|
16
|
+
for further details
|
17
|
+
MESSAGE
|
18
|
+
raise CloudParty::APIError.new(message, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @results = []
|
22
|
+
# @body[:result].each do |res|
|
23
|
+
# @results << CloudParty::Responses::Result.new(res)
|
24
|
+
# end
|
25
|
+
@result = CloudParty::Responses::Result.new(@body[:result])
|
26
|
+
@results = [@result]
|
27
|
+
@errors = []
|
28
|
+
@body[:errors].each do |err|
|
29
|
+
@errors << CloudParty::Responses::Error.new(err)
|
30
|
+
end
|
31
|
+
@messages = []
|
32
|
+
@body[:messages].each do |msg|
|
33
|
+
@messages << CloudParty::Responses::Message.new(msg)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def code
|
38
|
+
@code
|
39
|
+
end
|
40
|
+
def successful?
|
41
|
+
@success
|
42
|
+
end
|
43
|
+
alias success successful?
|
44
|
+
attr_reader :messages
|
45
|
+
|
46
|
+
def result
|
47
|
+
@results.first
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :results
|
51
|
+
|
52
|
+
def inspect
|
53
|
+
wanted_methods = %i[errors messages success results result]
|
54
|
+
our_methods = methods.select do |m|
|
55
|
+
wanted_methods.include? m
|
56
|
+
end
|
57
|
+
outputs = []
|
58
|
+
our_methods.each do |m|
|
59
|
+
outputs << "#{m}=#{send(m)}"
|
60
|
+
end
|
61
|
+
"#<Response: #{outputs.join(', ')}>"
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
inspect
|
66
|
+
end
|
67
|
+
end
|
68
|
+
class Result
|
69
|
+
def initialize(result)
|
70
|
+
@result = result
|
71
|
+
@result.each do |k, v|
|
72
|
+
instance_variable_set(:"@#{k}", v)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def ipv4_cidrs
|
77
|
+
@ipv4_cidrs
|
78
|
+
end
|
79
|
+
def ipv6_cidrs
|
80
|
+
@ipv6_cidrs
|
81
|
+
end
|
82
|
+
|
83
|
+
def inspect
|
84
|
+
wanted = %i[ipv4_cidrs ipv6_cidrs]
|
85
|
+
outputs = []
|
86
|
+
wanted.each do |m|
|
87
|
+
outputs << "#{m.to_s}=#{send(m)}"
|
88
|
+
end
|
89
|
+
"#<Result #{outputs.join(', ')}>"
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
inspect
|
94
|
+
end
|
95
|
+
end
|
96
|
+
class Error
|
97
|
+
def initialize(error)
|
98
|
+
@error = error
|
99
|
+
@code = error.fetch(:code, nil)
|
100
|
+
@message = error.fetch(:message, nil)
|
101
|
+
end
|
102
|
+
|
103
|
+
attr_reader :code
|
104
|
+
|
105
|
+
attr_reader :message
|
106
|
+
|
107
|
+
def inspect
|
108
|
+
to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_s
|
112
|
+
wanted_methods = %i[code message]
|
113
|
+
our_methods = methods.select do |m|
|
114
|
+
wanted_methods.include? m
|
115
|
+
end
|
116
|
+
outputs = []
|
117
|
+
our_methods.each do |m|
|
118
|
+
outputs << "#{m}=#{send(m)}"
|
119
|
+
end
|
120
|
+
"#<Error: #{output.join(', ')}>"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
class Message
|
124
|
+
def initialize(message)
|
125
|
+
@message = message
|
126
|
+
end
|
127
|
+
|
128
|
+
def inspect
|
129
|
+
to_s
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_s
|
133
|
+
@messages.join(', ')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cloud_party/responses/nodes/memberships'
|
4
|
+
module CloudParty
|
5
|
+
module Responses
|
6
|
+
class Memberships
|
7
|
+
def initialize(method_name, endpoint, response)
|
8
|
+
@code = response.code
|
9
|
+
@body = JSON.parse(response.body, symbolize_names: true)
|
10
|
+
@success = @body[:success]
|
11
|
+
unless successful?
|
12
|
+
message = <<~MESSAGE
|
13
|
+
Unable to #{method_name.to_s.upcase} to endpoint:
|
14
|
+
#{endpoint}. Inspect CloudParty::APIError#response
|
15
|
+
for further details
|
16
|
+
MESSAGE
|
17
|
+
raise CloudParty::APIError.new(message, response)
|
18
|
+
end
|
19
|
+
|
20
|
+
@results = []
|
21
|
+
@body[:result].each do |res|
|
22
|
+
@results << CloudParty::Responses::Result.new(res)
|
23
|
+
end
|
24
|
+
@errors = []
|
25
|
+
@body[:errors].each do |err|
|
26
|
+
@errors << CloudParty::Responses::Error.new(err)
|
27
|
+
end
|
28
|
+
@messages = []
|
29
|
+
@body[:messages].each do |msg|
|
30
|
+
@messages << CloudParty::Responses::Message.new(msg)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def successful?
|
35
|
+
@success
|
36
|
+
end
|
37
|
+
alias success successful?
|
38
|
+
attr_reader :messages
|
39
|
+
|
40
|
+
def result
|
41
|
+
@results.first
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader :results
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
wanted_methods = %i[errors messages success results result]
|
48
|
+
our_methods = methods.select do |m|
|
49
|
+
wanted_methods.include? m
|
50
|
+
end
|
51
|
+
outputs = []
|
52
|
+
our_methods.each do |m|
|
53
|
+
outputs << "#{m}=#{send(m)}"
|
54
|
+
end
|
55
|
+
"#<Response: #{outputs.join(', ')}>"
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
inspect
|
60
|
+
end
|
61
|
+
end
|
62
|
+
class Result
|
63
|
+
def initialize(result)
|
64
|
+
@result = result
|
65
|
+
@result.each do |k, v|
|
66
|
+
next if k == :permissions
|
67
|
+
next if k == :account
|
68
|
+
|
69
|
+
instance_variable_set(:"@#{k}", v)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def account
|
74
|
+
CloudParty::Responses::Node::Account.new(@result[:account])
|
75
|
+
end
|
76
|
+
|
77
|
+
def permissions
|
78
|
+
CloudParty::Responses::Node::Permissions.new(@result[:permissions])
|
79
|
+
end
|
80
|
+
|
81
|
+
def status
|
82
|
+
@status
|
83
|
+
end
|
84
|
+
|
85
|
+
def roles
|
86
|
+
@roles
|
87
|
+
end
|
88
|
+
|
89
|
+
def id
|
90
|
+
@id
|
91
|
+
end
|
92
|
+
|
93
|
+
def inspect
|
94
|
+
wanted = %i[permissions account status roles id]
|
95
|
+
outputs = []
|
96
|
+
wanted.each do |m|
|
97
|
+
outputs << "#{m.to_s}=#{send(m)}"
|
98
|
+
end
|
99
|
+
"#<Result #{outputs.join(', ')}>"
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_s
|
103
|
+
inspect
|
104
|
+
end
|
105
|
+
end
|
106
|
+
class Error
|
107
|
+
def initialize(error)
|
108
|
+
@error = error
|
109
|
+
@code = error.fetch(:code, nil)
|
110
|
+
@message = error.fetch(:message, nil)
|
111
|
+
end
|
112
|
+
|
113
|
+
attr_reader :code
|
114
|
+
|
115
|
+
attr_reader :message
|
116
|
+
|
117
|
+
def inspect
|
118
|
+
to_s
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_s
|
122
|
+
wanted_methods = %i[code message]
|
123
|
+
our_methods = methods.select do |m|
|
124
|
+
wanted_methods.include? m
|
125
|
+
end
|
126
|
+
outputs = []
|
127
|
+
our_methods.each do |m|
|
128
|
+
outputs << "#{m}=#{send(m)}"
|
129
|
+
end
|
130
|
+
"#<Error: #{output.join(', ')}>"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
class Message
|
134
|
+
def initialize(message)
|
135
|
+
@message = message
|
136
|
+
end
|
137
|
+
|
138
|
+
def inspect
|
139
|
+
to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
def to_s
|
143
|
+
@messages.join(', ')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CloudParty
|
4
|
+
module Responses
|
5
|
+
module Node
|
6
|
+
class Account
|
7
|
+
def initialize(account_hsh)
|
8
|
+
@account = account_hsh
|
9
|
+
@name = @account[:name]
|
10
|
+
@id = @account[:id]
|
11
|
+
@settings = @account[:settings]
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
attr_reader :id
|
17
|
+
|
18
|
+
def settings
|
19
|
+
@settings.each do |k, v|
|
20
|
+
settings << { k => v }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
outputs = []
|
26
|
+
%i[id name settings].each do |var|
|
27
|
+
if var == :settings
|
28
|
+
settings = []
|
29
|
+
@settings.each do |k, v|
|
30
|
+
settings << "#{k}=#{v}"
|
31
|
+
end
|
32
|
+
outputs << "settings=[#{settings.join(', ')}]"
|
33
|
+
else
|
34
|
+
outputs << "#{var}=#{send(var)}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
"#<Account #{outputs.join(', ')}>"
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
inspect
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CloudParty
|
4
|
+
module Responses
|
5
|
+
module Node
|
6
|
+
class Permissions
|
7
|
+
def initialize(hsh)
|
8
|
+
perms = []
|
9
|
+
hsh.each do |name, values|
|
10
|
+
perm_values = values.keys.select! { |val| values[val] }
|
11
|
+
perms << "#{name} -> #{perm_values.nil? ? 'none' : perm_values.join(', ')}"
|
12
|
+
end
|
13
|
+
@list = perms
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :list
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"#<Permissions: #{list}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|