netbox-client-ruby 0.13.0 → 0.13.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 +4 -4
- data/VERSION +1 -0
- data/lib/netbox_client_ruby/api/circuits/circuit.rb +2 -2
- data/lib/netbox_client_ruby/api/circuits/circuit_termination.rb +1 -1
- data/lib/netbox_client_ruby/api/circuits.rb +4 -6
- data/lib/netbox_client_ruby/api/dcim/device_type.rb +1 -1
- data/lib/netbox_client_ruby/api/dcim/platform.rb +1 -1
- data/lib/netbox_client_ruby/api/dcim/site.rb +2 -2
- data/lib/netbox_client_ruby/api/dcim.rb +4 -6
- data/lib/netbox_client_ruby/api/extras/config_context.rb +1 -1
- data/lib/netbox_client_ruby/api/extras.rb +4 -6
- data/lib/netbox_client_ruby/api/ipam/ip_address.rb +5 -4
- data/lib/netbox_client_ruby/api/ipam/ip_range.rb +1 -1
- data/lib/netbox_client_ruby/api/ipam/prefix.rb +1 -1
- data/lib/netbox_client_ruby/api/ipam/service.rb +1 -1
- data/lib/netbox_client_ruby/api/ipam.rb +4 -6
- data/lib/netbox_client_ruby/api/secrets/rsa_key_pair.rb +1 -1
- data/lib/netbox_client_ruby/api/secrets/session_key.rb +6 -1
- data/lib/netbox_client_ruby/api/secrets.rb +4 -6
- data/lib/netbox_client_ruby/api/tenancy.rb +4 -6
- data/lib/netbox_client_ruby/api/virtualization.rb +2 -4
- data/lib/netbox_client_ruby/communication.rb +13 -28
- data/lib/netbox_client_ruby/connection.rb +3 -3
- data/lib/netbox_client_ruby/entities.rb +8 -10
- data/lib/netbox_client_ruby/entity.rb +49 -24
- data/lib/netbox_client_ruby/version.rb +11 -0
- data/lib/netbox_client_ruby.rb +10 -0
- metadata +10 -28
- data/.dockerignore +0 -17
- data/.github/workflows/codeql-analysis.yml +0 -42
- data/.github/workflows/gem-push.yml +0 -26
- data/.github/workflows/rspec.yml +0 -45
- data/.gitignore +0 -21
- data/.rspec +0 -1
- data/Appraisals +0 -17
- data/Dockerfile +0 -14
- data/Gemfile +0 -19
- data/Rakefile +0 -8
- data/bin/console +0 -36
- data/bin/setup +0 -7
- data/docker/start.sh +0 -3
- data/docker/start.test.sh +0 -3
- data/docker-compose.test.yml +0 -16
- data/docker-compose.yml +0 -31
- data/dump.sql +0 -9895
- data/gemfiles/faraday0.gemfile +0 -16
- data/gemfiles/faraday1.gemfile +0 -16
- data/gemfiles/faraday2.gemfile +0 -16
- data/netbox-client-ruby.gemspec +0 -30
- data/netbox-client-ruby_rsa +0 -51
- data/netbox-client-ruby_rsa.pub +0 -1
- data/netbox.env +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3c13d93a4b630b6cbf0132bd3be08c5ce516eb5dd41796663decda4ecbaf3c5
|
|
4
|
+
data.tar.gz: da860034ae235b12b07fe39a2ed55d349df9805763312030eccdda9080184db3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0de307eed7348946cc8d93c9e31fad29ad7931a01ab7fb9c3c29f00cb7218829e00e8b0033b7730add002c9552d2880cace8acb7eb915bbb4ca03e9579255685
|
|
7
|
+
data.tar.gz: 2bc8a49a8cb146f84ac9fcce228f1325c7925120afb0598fee6a6b4b560d28964de9ade481e60ac5971a78561b511ad48dc4987e0f51f470671a3cf2e8517155
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.13.1
|
|
@@ -11,7 +11,7 @@ module NetboxClientRuby
|
|
|
11
11
|
planned: 2,
|
|
12
12
|
provisioning: 3,
|
|
13
13
|
offline: 4,
|
|
14
|
-
decommissioned: 5
|
|
14
|
+
decommissioned: 5,
|
|
15
15
|
}.freeze
|
|
16
16
|
|
|
17
17
|
id id: :id
|
|
@@ -27,7 +27,7 @@ module NetboxClientRuby
|
|
|
27
27
|
STATUS_VALUES.key(raw_status['value']) || raw_status['value']
|
|
28
28
|
end,
|
|
29
29
|
type: proc { |raw_data| CircuitType.new raw_data['id'] },
|
|
30
|
-
tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] }
|
|
30
|
+
tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] },
|
|
31
31
|
)
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -13,7 +13,7 @@ module NetboxClientRuby
|
|
|
13
13
|
object_fields(
|
|
14
14
|
circuit: proc { |raw_data| Circuit::Circuit.new raw_data['id'] },
|
|
15
15
|
site: proc { |raw_data| DCIM::Site.new raw_data['id'] },
|
|
16
|
-
interface: proc { |raw_data| DCIM::Interface.new raw_data['id'] }
|
|
16
|
+
interface: proc { |raw_data| DCIM::Interface.new raw_data['id'] },
|
|
17
17
|
)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -6,20 +6,18 @@ module NetboxClientRuby
|
|
|
6
6
|
providers: Providers,
|
|
7
7
|
circuits: Circuits,
|
|
8
8
|
circuit_types: CircuitTypes,
|
|
9
|
-
circuit_terminations: CircuitTerminations
|
|
9
|
+
circuit_terminations: CircuitTerminations,
|
|
10
10
|
}.each_pair do |method_name, class_name|
|
|
11
|
-
|
|
12
|
-
module_function(method_name)
|
|
11
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
{
|
|
16
15
|
provider: Provider,
|
|
17
16
|
circuit: Circuit,
|
|
18
17
|
circuit_type: CircuitType,
|
|
19
|
-
circuit_termination: CircuitTermination
|
|
18
|
+
circuit_termination: CircuitTermination,
|
|
20
19
|
}.each_pair do |method_name, class_name|
|
|
21
|
-
|
|
22
|
-
module_function(method_name)
|
|
20
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
23
21
|
end
|
|
24
22
|
end
|
|
25
23
|
end
|
|
@@ -8,7 +8,7 @@ module NetboxClientRuby
|
|
|
8
8
|
STATUS_VALUES = {
|
|
9
9
|
active: 1,
|
|
10
10
|
planned: 2,
|
|
11
|
-
retired: 4
|
|
11
|
+
retired: 4,
|
|
12
12
|
}.freeze
|
|
13
13
|
|
|
14
14
|
id id: :id
|
|
@@ -23,7 +23,7 @@ module NetboxClientRuby
|
|
|
23
23
|
region: proc { |raw_region| DCIM::Region.new raw_region['id'] },
|
|
24
24
|
status: proc do |raw_status|
|
|
25
25
|
STATUS_VALUES.key(raw_status['value']) || raw_status['value']
|
|
26
|
-
end
|
|
26
|
+
end,
|
|
27
27
|
)
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -24,10 +24,9 @@ module NetboxClientRuby
|
|
|
24
24
|
rack_roles: RackRoles,
|
|
25
25
|
regions: Regions,
|
|
26
26
|
sites: Sites,
|
|
27
|
-
virtual_chassis_list: VirtualChassisList
|
|
27
|
+
virtual_chassis_list: VirtualChassisList,
|
|
28
28
|
}.each_pair do |method_name, class_name|
|
|
29
|
-
|
|
30
|
-
module_function(method_name)
|
|
29
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
{
|
|
@@ -52,10 +51,9 @@ module NetboxClientRuby
|
|
|
52
51
|
rack_role: RackRole,
|
|
53
52
|
region: Region,
|
|
54
53
|
site: Site,
|
|
55
|
-
virtual_chassis: VirtualChassis
|
|
54
|
+
virtual_chassis: VirtualChassis,
|
|
56
55
|
}.each_pair do |method_name, class_name|
|
|
57
|
-
|
|
58
|
-
module_function(method_name)
|
|
56
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
59
57
|
end
|
|
60
58
|
end
|
|
61
59
|
end
|
|
@@ -18,7 +18,7 @@ module NetboxClientRuby
|
|
|
18
18
|
clusters: proc { |raw_data| Virtualization::Cluster.new raw_data['id'] },
|
|
19
19
|
tenant_groups: proc { |raw_data| Tenancy::TenantGroup.new raw_data['id'] },
|
|
20
20
|
tenants: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] },
|
|
21
|
-
tags: proc { |raw_data| Tag.new raw_data['id'] }
|
|
21
|
+
tags: proc { |raw_data| Tag.new raw_data['id'] },
|
|
22
22
|
)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -5,19 +5,17 @@ module NetboxClientRuby
|
|
|
5
5
|
{
|
|
6
6
|
config_contexts: ConfigContexts,
|
|
7
7
|
journal_entries: JournalEntries,
|
|
8
|
-
tags: Tags
|
|
8
|
+
tags: Tags,
|
|
9
9
|
}.each_pair do |method_name, class_name|
|
|
10
|
-
|
|
11
|
-
module_function(method_name)
|
|
10
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
{
|
|
15
14
|
config_context: ConfigContext,
|
|
16
15
|
journal_entry: JournalEntry,
|
|
17
|
-
tag: Tag
|
|
16
|
+
tag: Tag,
|
|
18
17
|
}.each_pair do |method_name, class_name|
|
|
19
|
-
|
|
20
|
-
module_function(method_name)
|
|
18
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
21
19
|
end
|
|
22
20
|
end
|
|
23
21
|
end
|
|
@@ -9,7 +9,7 @@ module NetboxClientRuby
|
|
|
9
9
|
active: 1,
|
|
10
10
|
reserved: 2,
|
|
11
11
|
deprecated: 3,
|
|
12
|
-
dhcp: 5
|
|
12
|
+
dhcp: 5,
|
|
13
13
|
}.freeze
|
|
14
14
|
|
|
15
15
|
id id: :id
|
|
@@ -20,7 +20,7 @@ module NetboxClientRuby
|
|
|
20
20
|
vrf: proc { |raw_data| Vrf.new raw_data['id'] },
|
|
21
21
|
tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] },
|
|
22
22
|
status: proc { |raw_data| STATUS_VALUES.key(raw_data['value']) || raw_data['value'] },
|
|
23
|
-
address: proc { |raw_ip| IPAddress.parse(raw_ip) }
|
|
23
|
+
address: proc { |raw_ip| IPAddress.parse(raw_ip) },
|
|
24
24
|
)
|
|
25
25
|
readonly_fields :display_name
|
|
26
26
|
|
|
@@ -33,8 +33,9 @@ module NetboxClientRuby
|
|
|
33
33
|
interface_data = data['interface']
|
|
34
34
|
|
|
35
35
|
return nil unless interface_data
|
|
36
|
-
return Virtualization::Interface.new interface_data['id'] unless interface_data
|
|
37
|
-
|
|
36
|
+
return Virtualization::Interface.new interface_data['id'] unless interface_data['virtual_machine'].nil?
|
|
37
|
+
|
|
38
|
+
DCIM::Interface.new interface_data['id']
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
end
|
|
@@ -15,7 +15,7 @@ module NetboxClientRuby
|
|
|
15
15
|
role: proc { |raw_data| Role.new raw_data['id'] },
|
|
16
16
|
status: proc { |raw_data| IpRangeStatus.new raw_data },
|
|
17
17
|
start_address: proc { |raw_data| IPAddress.parse raw_data },
|
|
18
|
-
end_address: proc { |raw_data| IPAddress.parse raw_data }
|
|
18
|
+
end_address: proc { |raw_data| IPAddress.parse raw_data },
|
|
19
19
|
)
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -16,7 +16,7 @@ module NetboxClientRuby
|
|
|
16
16
|
vlan: proc { |raw_data| Vlan.new raw_data['id'] },
|
|
17
17
|
status: proc { |raw_data| PrefixStatus.new raw_data },
|
|
18
18
|
role: proc { |raw_data| Role.new raw_data['id'] },
|
|
19
|
-
prefix: proc { |raw_data| IPAddress.parse raw_data }
|
|
19
|
+
prefix: proc { |raw_data| IPAddress.parse raw_data },
|
|
20
20
|
)
|
|
21
21
|
readonly_fields :display_name
|
|
22
22
|
end
|
|
@@ -13,7 +13,7 @@ module NetboxClientRuby
|
|
|
13
13
|
device: proc { |raw_data| Device.new raw_data['id'] },
|
|
14
14
|
virtual_machine: proc { |raw_data| VirtualMachine.new raw_data['id'] },
|
|
15
15
|
protocol: proc { |raw_data| ServiceProtocol.new raw_data },
|
|
16
|
-
ipaddresses: proc { |raw_data| IpAddress.new raw_data['id'] }
|
|
16
|
+
ipaddresses: proc { |raw_data| IpAddress.new raw_data['id'] },
|
|
17
17
|
)
|
|
18
18
|
readonly_fields :display_name
|
|
19
19
|
end
|
|
@@ -12,10 +12,9 @@ module NetboxClientRuby
|
|
|
12
12
|
services: Services,
|
|
13
13
|
vlans: Vlans,
|
|
14
14
|
vlan_groups: VlanGroups,
|
|
15
|
-
vrfs: Vrfs
|
|
15
|
+
vrfs: Vrfs,
|
|
16
16
|
}.each_pair do |method_name, class_name|
|
|
17
|
-
|
|
18
|
-
module_function(method_name)
|
|
17
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
{
|
|
@@ -28,10 +27,9 @@ module NetboxClientRuby
|
|
|
28
27
|
service: Service,
|
|
29
28
|
vlan: Vlan,
|
|
30
29
|
vlan_group: VlanGroup,
|
|
31
|
-
vrf: Vrf
|
|
30
|
+
vrf: Vrf,
|
|
32
31
|
}.each_pair do |method_name, class_name|
|
|
33
|
-
|
|
34
|
-
module_function(method_name)
|
|
32
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
end
|
|
@@ -5,7 +5,7 @@ module NetboxClientRuby
|
|
|
5
5
|
class SessionKey
|
|
6
6
|
include Communication
|
|
7
7
|
|
|
8
|
-
PATH = '/api/secrets/get-session-key/'
|
|
8
|
+
PATH = '/api/secrets/get-session-key/'
|
|
9
9
|
|
|
10
10
|
def initialize
|
|
11
11
|
session_key
|
|
@@ -49,6 +49,7 @@ module NetboxClientRuby
|
|
|
49
49
|
private_key.to_pem
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
# rubocop:disable Layout/LineLength,Metrics/MethodLength
|
|
52
53
|
def decode_private_key(encoded_private_key)
|
|
53
54
|
begin
|
|
54
55
|
private_key = OpenSSL::PKey::RSA.new encoded_private_key, rsa_private_key_password
|
|
@@ -67,15 +68,18 @@ module NetboxClientRuby
|
|
|
67
68
|
raise LocalError,
|
|
68
69
|
"The file at '#{rsa_private_key_path}' is not a private key, but a private key is required for get-session-key. (The corresponding configuration is 'netbox.auth.rsa_private_key.path'.)"
|
|
69
70
|
end
|
|
71
|
+
# rubocop:enable Layout/LineLength,Metrics/MethodLength
|
|
70
72
|
|
|
71
73
|
def rsa_private_key_password
|
|
72
74
|
pwd = rsa_private_key_config.password
|
|
73
75
|
# If nil is not converted to '', then OpenSSL will block and ask on console for the password.
|
|
74
76
|
# We really don't want that.
|
|
75
77
|
return '' if pwd.nil?
|
|
78
|
+
|
|
76
79
|
pwd
|
|
77
80
|
end
|
|
78
81
|
|
|
82
|
+
# rubocop:disable Layout/LineLength
|
|
79
83
|
def read_private_key_file(key_file)
|
|
80
84
|
encoded_private_key = key_file.read
|
|
81
85
|
return encoded_private_key unless encoded_private_key.nil? || encoded_private_key.empty?
|
|
@@ -90,6 +94,7 @@ module NetboxClientRuby
|
|
|
90
94
|
raise LocalError,
|
|
91
95
|
"No file exists at the given path '#{rsa_private_key_path}', but it's required for get-session-key. (The corresponding configuration is 'netbox.auth.rsa_private_key.path'.)"
|
|
92
96
|
end
|
|
97
|
+
# rubocop:enable Layout/LineLength
|
|
93
98
|
|
|
94
99
|
def rsa_private_key_path
|
|
95
100
|
@rsa_private_key_path ||= File.expand_path(rsa_private_key_config.path)
|
|
@@ -6,18 +6,16 @@ module NetboxClientRuby
|
|
|
6
6
|
secret_roles: SecretRoles,
|
|
7
7
|
secrets: Secrets,
|
|
8
8
|
generate_rsa_key_pair: RSAKeyPair,
|
|
9
|
-
get_session_key: SessionKey
|
|
9
|
+
get_session_key: SessionKey,
|
|
10
10
|
}.each_pair do |method_name, class_name|
|
|
11
|
-
|
|
12
|
-
module_function(method_name)
|
|
11
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
{
|
|
16
15
|
secret_role: SecretRole,
|
|
17
|
-
secret: Secret
|
|
16
|
+
secret: Secret,
|
|
18
17
|
}.each_pair do |method_name, class_name|
|
|
19
|
-
|
|
20
|
-
module_function(method_name)
|
|
18
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
21
19
|
end
|
|
22
20
|
|
|
23
21
|
def session_key=(session_key)
|
|
@@ -6,20 +6,18 @@ module NetboxClientRuby
|
|
|
6
6
|
tenants: Tenants,
|
|
7
7
|
tenant_groups: TenantGroups,
|
|
8
8
|
contacts: Contacts,
|
|
9
|
-
contact_groups: ContactGroups
|
|
9
|
+
contact_groups: ContactGroups,
|
|
10
10
|
}.each_pair do |method_name, class_name|
|
|
11
|
-
|
|
12
|
-
module_function(method_name)
|
|
11
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
{
|
|
16
15
|
tenant: Tenant,
|
|
17
16
|
tenant_group: TenantGroup,
|
|
18
17
|
contact: Contact,
|
|
19
|
-
contact_group: ContactGroup
|
|
18
|
+
contact_group: ContactGroup,
|
|
20
19
|
}.each_pair do |method_name, class_name|
|
|
21
|
-
|
|
22
|
-
module_function(method_name)
|
|
20
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
23
21
|
end
|
|
24
22
|
end
|
|
25
23
|
end
|
|
@@ -9,8 +9,7 @@ module NetboxClientRuby
|
|
|
9
9
|
virtual_machines: VirtualMachines,
|
|
10
10
|
interfaces: Interfaces,
|
|
11
11
|
}.each_pair do |method_name, class_name|
|
|
12
|
-
|
|
13
|
-
module_function(method_name)
|
|
12
|
+
NetboxClientRuby.load_collection(self, method_name, class_name)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
{
|
|
@@ -20,8 +19,7 @@ module NetboxClientRuby
|
|
|
20
19
|
virtual_machine: VirtualMachine,
|
|
21
20
|
interface: Interface,
|
|
22
21
|
}.each_pair do |method_name, class_name|
|
|
23
|
-
|
|
24
|
-
module_function(method_name)
|
|
22
|
+
NetboxClientRuby.load_entity(self, method_name, class_name)
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
end
|
|
@@ -15,60 +15,44 @@ module NetboxClientRuby
|
|
|
15
15
|
NetboxClientRuby::Connection.new
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def hash_to_object(hash)
|
|
19
|
-
objectified_class = Class.new
|
|
20
|
-
objectified_instance = objectified_class.new
|
|
21
|
-
hash.each do |k, v|
|
|
22
|
-
variable_name = sanitize_variable_name(k)
|
|
23
|
-
variable_name = "_#{variable_name}" if objectified_instance.methods.map(&:to_s).include?(variable_name)
|
|
24
|
-
|
|
25
|
-
objectified_instance.instance_variable_set(:"@#{variable_name}", v)
|
|
26
|
-
objectified_class.send(:define_method, variable_name, proc { instance_variable_get(:"@#{variable_name}") })
|
|
27
|
-
end
|
|
28
|
-
objectified_instance
|
|
29
|
-
end
|
|
30
|
-
|
|
31
18
|
private
|
|
32
19
|
|
|
33
|
-
def sanitize_variable_name(raw_name)
|
|
34
|
-
raw_name.gsub(/[^a-zA-Z0-9_]/, '_')
|
|
35
|
-
end
|
|
36
|
-
|
|
37
20
|
def read(response)
|
|
38
21
|
response.body
|
|
39
22
|
end
|
|
40
23
|
|
|
41
|
-
def raise_on_http_error(response)
|
|
24
|
+
def raise_on_http_error(response) # rubocop:disable Metrics/MethodLength
|
|
42
25
|
status = response.status
|
|
43
26
|
body = response.body
|
|
44
27
|
|
|
45
28
|
case status
|
|
46
|
-
when 200..299
|
|
47
|
-
|
|
29
|
+
when 200..299
|
|
30
|
+
# do nothing
|
|
31
|
+
when 300..499
|
|
48
32
|
raise_on_http_client_error response
|
|
49
|
-
when 500..599
|
|
33
|
+
when 500..599
|
|
50
34
|
raise NetboxClientRuby::RemoteError, "#{status} Remote Error#{formatted_body(body)}"
|
|
51
35
|
else
|
|
52
36
|
raise NetboxClientRuby::RemoteError, "#{status} Unknown Error Code#{formatted_body(body)}"
|
|
53
37
|
end
|
|
54
38
|
end
|
|
55
39
|
|
|
56
|
-
def raise_on_http_client_error(response)
|
|
40
|
+
def raise_on_http_client_error(response) # rubocop:disable Metrics/MethodLength
|
|
57
41
|
status = response.status
|
|
58
42
|
body = response.body
|
|
59
43
|
|
|
60
44
|
case status
|
|
61
|
-
when 400
|
|
45
|
+
when 400
|
|
62
46
|
raise_client_error '400 Bad Request', body
|
|
63
|
-
when 401
|
|
47
|
+
when 401
|
|
64
48
|
raise_client_error '401 Unauthorized', body
|
|
65
|
-
when 403
|
|
49
|
+
when 403
|
|
66
50
|
raise_client_error '403 Forbidden', body
|
|
67
|
-
when 405
|
|
51
|
+
when 405
|
|
68
52
|
raise_client_error '405 Method Not Allowed', body
|
|
69
|
-
when 415
|
|
53
|
+
when 415
|
|
70
54
|
raise_client_error '415 Unsupported Media Type', body
|
|
71
|
-
when 429
|
|
55
|
+
when 429
|
|
72
56
|
raise_client_error '429 Too Many Requests', body
|
|
73
57
|
else
|
|
74
58
|
raise_client_error "#{status} Request Error", body
|
|
@@ -81,6 +65,7 @@ module NetboxClientRuby
|
|
|
81
65
|
|
|
82
66
|
def formatted_body(body)
|
|
83
67
|
return '' if body.nil? || body.empty?
|
|
68
|
+
|
|
84
69
|
shortened = body.to_s
|
|
85
70
|
one_line = shortened.gsub(/\n/, '\n')
|
|
86
71
|
" (#{one_line})"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module NetboxClientRuby
|
|
4
4
|
class Connection
|
|
5
5
|
DEFAULT_OPTIONS = {
|
|
6
|
-
request_encoding: :json
|
|
6
|
+
request_encoding: :json,
|
|
7
7
|
}.freeze
|
|
8
8
|
|
|
9
9
|
def self.new(options = {})
|
|
@@ -13,7 +13,7 @@ module NetboxClientRuby
|
|
|
13
13
|
def self.headers
|
|
14
14
|
headers = {}
|
|
15
15
|
auth_token = auth_config.token
|
|
16
|
-
headers['Authorization'] = "Token #{auth_token}"
|
|
16
|
+
headers['Authorization'] = "Token #{auth_token}" if auth_token
|
|
17
17
|
headers['X-Session-Key'] = NetboxClientRuby::Secrets.session_key if NetboxClientRuby::Secrets.session_key
|
|
18
18
|
headers
|
|
19
19
|
end
|
|
@@ -26,7 +26,7 @@ module NetboxClientRuby
|
|
|
26
26
|
NetboxClientRuby.config.netbox
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
private_class_method def self.build_faraday(request_encoding: :json)
|
|
29
|
+
private_class_method def self.build_faraday(request_encoding: :json) # rubocop:disable Metrics/AbcSize
|
|
30
30
|
config = NetboxClientRuby.config
|
|
31
31
|
Faraday.new(url: config.netbox.api_base_url, headers: headers, ssl: config.faraday.ssl_options) do |faraday|
|
|
32
32
|
faraday.request request_encoding
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NetboxClientRuby
|
|
4
|
-
module Entities
|
|
4
|
+
module Entities # rubocop:disable Metrics/ModuleLength
|
|
5
5
|
include NetboxClientRuby::Communication
|
|
6
6
|
include Enumerable
|
|
7
7
|
|
|
@@ -37,7 +37,7 @@ module NetboxClientRuby
|
|
|
37
37
|
@limit
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def check_limit(limit)
|
|
40
|
+
def check_limit(limit) # rubocop:disable Metrics/MethodLength
|
|
41
41
|
max_limit = NetboxClientRuby.config.netbox.pagination.max_limit
|
|
42
42
|
if limit.nil?
|
|
43
43
|
raise ArgumentError,
|
|
@@ -74,8 +74,8 @@ module NetboxClientRuby
|
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
def find_by(attributes)
|
|
78
|
-
|
|
77
|
+
def find_by(attributes) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
78
|
+
raise ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash
|
|
79
79
|
|
|
80
80
|
filter(attributes).find do |netbox_object|
|
|
81
81
|
attributes.all? do |filter_key, filter_value|
|
|
@@ -83,19 +83,17 @@ module NetboxClientRuby
|
|
|
83
83
|
custom_field = filter_key.to_s.sub('cf_', '')
|
|
84
84
|
|
|
85
85
|
netbox_object.custom_fields[custom_field].to_s == filter_value.to_s
|
|
86
|
+
elsif netbox_object.respond_to?(filter_key)
|
|
87
|
+
netbox_object.public_send(filter_key).to_s == filter_value.to_s
|
|
86
88
|
else
|
|
87
|
-
|
|
88
|
-
netbox_object.public_send(filter_key).to_s == filter_value.to_s
|
|
89
|
-
else
|
|
90
|
-
false
|
|
91
|
-
end
|
|
89
|
+
false
|
|
92
90
|
end
|
|
93
91
|
end
|
|
94
92
|
end
|
|
95
93
|
end
|
|
96
94
|
|
|
97
95
|
def filter(filter)
|
|
98
|
-
|
|
96
|
+
raise ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash
|
|
99
97
|
|
|
100
98
|
@filter = filter
|
|
101
99
|
reset
|