linux_admin 2.0.2 → 4.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ddedcd6ceb14d076ced3bfb96af9c8f29ad37abd2971dacf4f53259e908e86f
4
- data.tar.gz: 999756b223217fcff6fc317a256e8ee2dfaaa7fc18bb97bbfb4c7216be824079
3
+ metadata.gz: 5a68c70db030c6c422243f781a3500324a224ae653c7e04e6ebac3f5ad902d08
4
+ data.tar.gz: 2d1d363cd64e3c2ebf64616a0376752f2e04aa7b74c143856d89c1aa2bcd0a7e
5
5
  SHA512:
6
- metadata.gz: 686d0e331bacae73eed707a30d21fcbf188d14aaa61651a9f606202a62b295e4a0d4c45c73f6a62fa7d3946cd062c2fc49cd791013559b6b057fbed50012be5b
7
- data.tar.gz: 1eabbe2ea7f4bd9ce0deb9f590d50a90e03ac880cf3bd3360025a828be206fa9705145bf73fa92f1cb60c27e2175382760db48cc8504d0e136c689580fe88aab
6
+ metadata.gz: 24c97db1e87afbbb873c963eb0e5c45f54dd1de468b46e301ec44563bcc459ecc2a97c9219a4c221ec8703258328c0c2f476b6e27f91da4c6bb811945ea3cfe7
7
+ data.tar.gz: 9b1a31fbf403c5b0873dced35a8308870a382c907ae8ef3919a285151c878bebf9297d71179435c09bc4c4a182fffee053e3e1ee8b76b2a50f2e8e8bd2e3d1ee
data/README.md CHANGED
@@ -1,12 +1,9 @@
1
1
  # LinuxAdmin
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/linux_admin.svg)](http://badge.fury.io/rb/linux_admin)
4
- [![Build Status](https://travis-ci.com/ManageIQ/linux_admin.svg)](https://travis-ci.com/ManageIQ/linux_admin)
5
- [![Code Climate](http://img.shields.io/codeclimate/github/ManageIQ/linux_admin.svg)](https://codeclimate.com/github/ManageIQ/linux_admin)
6
- [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/linux_admin.svg)](https://coveralls.io/r/ManageIQ/linux_admin)
7
- [![Dependency Status](https://gemnasium.com/ManageIQ/linux_admin.svg)](https://gemnasium.com/ManageIQ/linux_admin)
8
- [![Security](https://hakiri.io/github/ManageIQ/linux_admin/master.svg)](https://hakiri.io/github/ManageIQ/linux_admin/master)
9
-
4
+ [![CI](https://github.com/ManageIQ/linux_admin/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/linux_admin/actions/workflows/ci.yaml)
5
+ [![Code Climate](https://codeclimate.com/github/ManageIQ/linux_admin.svg)](https://codeclimate.com/github/ManageIQ/linux_admin)
6
+ [![Test Coverage](https://codeclimate.com/github/ManageIQ/linux_admin/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/linux_admin/coverage)
10
7
 
11
8
  LinuxAdmin is a module to simplify management of linux systems.
12
9
  It should be a single place to manage various system level configurations,
@@ -4,7 +4,7 @@ module LinuxAdmin
4
4
  module Common
5
5
  include Logging
6
6
 
7
- BIN_DIRS = %w(/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin)
7
+ BIN_DIRS = ENV["PATH"].split(File::PATH_SEPARATOR).freeze
8
8
 
9
9
  def self.cmd(name)
10
10
  BIN_DIRS.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exist?(cmd) }
@@ -12,7 +12,15 @@ module LinuxAdmin
12
12
  def initialize(interface)
13
13
  @interface_file = self.class.path_to_interface_config_file(interface)
14
14
  super
15
+ end
16
+
17
+ # Gathers current network information for this interface
18
+ #
19
+ # @return [Boolean] true if network information was gathered successfully
20
+ def reload
21
+ super
15
22
  parse_conf
23
+ true
16
24
  end
17
25
 
18
26
  # Parses the interface configuration file into the @interface_config hash
@@ -1,7 +1,8 @@
1
- require 'ipaddr'
2
-
3
1
  module LinuxAdmin
4
2
  class NetworkInterface
3
+ require "ipaddr"
4
+ require "json"
5
+
5
6
  # Cached class instance variable for what distro we are running on
6
7
  @dist_class = nil
7
8
 
@@ -20,13 +21,28 @@ module LinuxAdmin
20
21
  end
21
22
  end
22
23
 
24
+ def self.list
25
+ ip_link.pluck("ifname").map { |iface| new(iface) }
26
+ rescue AwesomeSpawn::CommandResultError => e
27
+ raise NetworkInterfaceError.new(e.message, e.result)
28
+ end
29
+
30
+ private_class_method def self.ip_link
31
+ require "json"
32
+
33
+ result = Common.run!(Common.cmd("ip"), :params => ["--json", "link"])
34
+ JSON.parse(result.output)
35
+ rescue AwesomeSpawn::CommandResultError, JSON::ParserError => e
36
+ raise NetworkInterfaceError.new(e.message, e.result)
37
+ end
38
+
23
39
  # Creates an instance of the correct NetworkInterface subclass for the local distro
24
40
  def self.new(*args)
25
41
  self == LinuxAdmin::NetworkInterface ? dist_class.new(*args) : super
26
42
  end
27
43
 
28
44
  # @return [String] the interface for networking operations
29
- attr_reader :interface
45
+ attr_reader :interface, :link_type
30
46
 
31
47
  # @param interface [String] Name of the network interface to manage
32
48
  def initialize(interface)
@@ -45,18 +61,25 @@ module LinuxAdmin
45
61
  return false
46
62
  end
47
63
 
48
- parse_ip4(ip_output)
49
- parse_ip6(ip_output, :global)
50
- parse_ip6(ip_output, :link)
64
+ @link_type = ip_output["link_type"]
65
+ addr_info = ip_output["addr_info"]
66
+
67
+ parse_ip4(addr_info)
68
+ parse_ip6(addr_info, "global")
69
+ parse_ip6(addr_info, "link")
51
70
 
52
- @network_conf[:mac] = parse_ip_output(ip_output, %r{link/ether}, 1)
71
+ @network_conf[:mac] = ip_output["address"]
53
72
 
54
73
  [4, 6].each do |version|
55
- @network_conf["gateway#{version}".to_sym] = parse_ip_output(ip_route(version), /^default/, 2)
74
+ @network_conf["gateway#{version}".to_sym] = ip_route(version, "default")&.dig("gateway")
56
75
  end
57
76
  true
58
77
  end
59
78
 
79
+ def loopback?
80
+ @link_type == "loopback"
81
+ end
82
+
60
83
  # Retrieve the IPv4 address assigned to the interface
61
84
  #
62
85
  # @return [String] IPv4 address for the managed interface
@@ -153,23 +176,15 @@ module LinuxAdmin
153
176
 
154
177
  private
155
178
 
156
- # Parses the output of `ip addr show`
157
- #
158
- # @param output [String] The command output
159
- # @param regex [Regexp] Regular expression to match the desired output line
160
- # @param col [Fixnum] The whitespace delimited column to be returned
161
- # @return [String] The parsed data
162
- def parse_ip_output(output, regex, col)
163
- the_line = output.split("\n").detect { |l| l =~ regex }
164
- the_line.nil? ? nil : the_line.strip.split(' ')[col]
165
- end
166
-
167
179
  # Runs the command `ip addr show <interface>`
168
180
  #
169
181
  # @return [String] The command output
170
182
  # @raise [NetworkInterfaceError] if the command fails
171
183
  def ip_show
172
- Common.run!(Common.cmd("ip"), :params => ["addr", "show", @interface]).output
184
+ output = Common.run!(Common.cmd("ip"), :params => ["--json", "addr", "show", @interface]).output
185
+ return {} if output.blank?
186
+
187
+ JSON.parse(output).first
173
188
  rescue AwesomeSpawn::CommandResultError => e
174
189
  raise NetworkInterfaceError.new(e.message, e.result)
175
190
  end
@@ -179,8 +194,11 @@ module LinuxAdmin
179
194
  # @param version [Fixnum] Version of IP protocol (4 or 6)
180
195
  # @return [String] The command output
181
196
  # @raise [NetworkInterfaceError] if the command fails
182
- def ip_route(version)
183
- Common.run!(Common.cmd("ip"), :params => ["-#{version}", 'route']).output
197
+ def ip_route(version, route = "default")
198
+ output = Common.run!(Common.cmd("ip"), :params => ["--json", "-#{version}", "route", "show", route]).output
199
+ return {} if output.blank?
200
+
201
+ JSON.parse(output).first
184
202
  rescue AwesomeSpawn::CommandResultError => e
185
203
  raise NetworkInterfaceError.new(e.message, e.result)
186
204
  end
@@ -188,26 +206,24 @@ module LinuxAdmin
188
206
  # Parses the IPv4 information from the output of `ip addr show <device>`
189
207
  #
190
208
  # @param ip_output [String] The command output
191
- def parse_ip4(ip_output)
192
- cidr_ip = parse_ip_output(ip_output, /inet /, 1)
193
- return unless cidr_ip
209
+ def parse_ip4(addr_info)
210
+ inet = addr_info&.detect { |addr| addr["family"] == "inet" }
211
+ return if inet.nil?
194
212
 
195
- parts = cidr_ip.split('/')
196
- @network_conf[:address] = parts[0]
197
- @network_conf[:prefix] = parts[1].to_i
213
+ @network_conf[:address] = inet["local"]
214
+ @network_conf[:prefix] = inet["prefixlen"]
198
215
  end
199
216
 
200
217
  # Parses the IPv6 information from the output of `ip addr show <device>`
201
218
  #
202
219
  # @param ip_output [String] The command output
203
220
  # @param scope [Symbol] The IPv6 scope (either `:global` or `:local`)
204
- def parse_ip6(ip_output, scope)
205
- cidr_ip = parse_ip_output(ip_output, /inet6 .* scope #{scope}/, 1)
206
- return unless cidr_ip
221
+ def parse_ip6(addr_info, scope)
222
+ inet6 = addr_info&.detect { |addr| addr["family"] == "inet6" && addr["scope"] == scope }
223
+ return if inet6.nil?
207
224
 
208
- parts = cidr_ip.split('/')
209
- @network_conf["address6_#{scope}".to_sym] = parts[0]
210
- @network_conf["prefix6_#{scope}".to_sym] = parts[1].to_i
225
+ @network_conf["address6_#{scope}".to_sym] = inet6["local"]
226
+ @network_conf["prefix6_#{scope}".to_sym] = inet6["prefixlen"]
211
227
  end
212
228
  end
213
229
  end
@@ -47,7 +47,8 @@ module LinuxAdmin
47
47
  private_class_method :white_list_methods
48
48
 
49
49
  def install_server_certificate(server, cert_path)
50
- host = server.start_with?("http") ? URI.parse(server).host : server
50
+ require 'uri'
51
+ host = server.start_with?("http") ? ::URI.parse(server).host : server
51
52
 
52
53
  LinuxAdmin::Rpm.upgrade("http://#{host}/#{cert_path}")
53
54
  end
@@ -1,3 +1,5 @@
1
+ require "time"
2
+
1
3
  module LinuxAdmin
2
4
  class SystemdService < Service
3
5
  def running?
@@ -32,7 +32,7 @@ module LinuxAdmin
32
32
  end
33
33
 
34
34
  def stop
35
- system({'SSH_AGENT_PID' => @pid}, '(ssh-agent -k) &> /dev/null') if process_exists?(@pid)
35
+ system({'SSH_AGENT_PID' => @pid}, '(ssh-agent -k) >/dev/null 2>&1') if process_exists?(@pid)
36
36
  File.delete(@socket) if File.exist?(@socket)
37
37
  @socket = nil
38
38
  @pid = nil
@@ -1,3 +1,3 @@
1
1
  module LinuxAdmin
2
- VERSION = "2.0.2".freeze
2
+ VERSION = "4.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -24,11 +24,28 @@ authors:
24
24
  - Daniel Berger
25
25
  - Satoe Imaishi
26
26
  - d-m-u
27
- autorequire:
27
+ - whitesource-bolt-for-github[bot]
28
+ - Adam Grare
29
+ - renovate[bot]
30
+ autorequire:
28
31
  bindir: bin
29
32
  cert_chain: []
30
- date: 2020-07-09 00:00:00.000000000 Z
33
+ date: 2024-08-13 00:00:00.000000000 Z
31
34
  dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: manageiq-style
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
32
49
  - !ruby/object:Gem::Dependency
33
50
  name: rake
34
51
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +75,7 @@ dependencies:
58
75
  - !ruby/object:Gem::Version
59
76
  version: '3.0'
60
77
  - !ruby/object:Gem::Dependency
61
- name: coveralls
78
+ name: rubocop
62
79
  requirement: !ruby/object:Gem::Requirement
63
80
  requirements:
64
81
  - - ">="
@@ -72,33 +89,59 @@ dependencies:
72
89
  - !ruby/object:Gem::Version
73
90
  version: '0'
74
91
  - !ruby/object:Gem::Dependency
75
- name: rubocop
92
+ name: awesome_spawn
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.6'
98
+ type: :runtime
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.6'
105
+ - !ruby/object:Gem::Dependency
106
+ name: bcrypt_pbkdf
76
107
  requirement: !ruby/object:Gem::Requirement
77
108
  requirements:
78
109
  - - ">="
79
110
  - !ruby/object:Gem::Version
80
- version: '0'
81
- type: :development
111
+ version: '1.0'
112
+ - - "<"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.0'
115
+ type: :runtime
82
116
  prerelease: false
83
117
  version_requirements: !ruby/object:Gem::Requirement
84
118
  requirements:
85
119
  - - ">="
86
120
  - !ruby/object:Gem::Version
87
- version: '0'
121
+ version: '1.0'
122
+ - - "<"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
88
125
  - !ruby/object:Gem::Dependency
89
- name: awesome_spawn
126
+ name: ed25519
90
127
  requirement: !ruby/object:Gem::Requirement
91
128
  requirements:
92
- - - "~>"
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ - - "<"
93
133
  - !ruby/object:Gem::Version
94
- version: '1.3'
134
+ version: '2.0'
95
135
  type: :runtime
96
136
  prerelease: false
97
137
  version_requirements: !ruby/object:Gem::Requirement
98
138
  requirements:
99
- - - "~>"
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '1.2'
142
+ - - "<"
100
143
  - !ruby/object:Gem::Version
101
- version: '1.3'
144
+ version: '2.0'
102
145
  - !ruby/object:Gem::Dependency
103
146
  name: inifile
104
147
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +170,20 @@ dependencies:
127
170
  - - "~>"
128
171
  - !ruby/object:Gem::Version
129
172
  version: '4.0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: net-ssh
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: 7.2.3
180
+ type: :runtime
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: 7.2.3
130
187
  - !ruby/object:Gem::Dependency
131
188
  name: nokogiri
132
189
  requirement: !ruby/object:Gem::Requirement
@@ -180,19 +237,19 @@ dependencies:
180
237
  - !ruby/object:Gem::Version
181
238
  version: '0'
182
239
  - !ruby/object:Gem::Dependency
183
- name: net-ssh
240
+ name: simplecov
184
241
  requirement: !ruby/object:Gem::Requirement
185
242
  requirements:
186
- - - "~>"
243
+ - - ">="
187
244
  - !ruby/object:Gem::Version
188
- version: 4.2.0
189
- type: :runtime
245
+ version: 0.21.2
246
+ type: :development
190
247
  prerelease: false
191
248
  version_requirements: !ruby/object:Gem::Requirement
192
249
  requirements:
193
- - - "~>"
250
+ - - ">="
194
251
  - !ruby/object:Gem::Version
195
- version: 4.2.0
252
+ version: 0.21.2
196
253
  description: |2
197
254
 
198
255
  LinuxAdmin is a module to simplify management of linux systems.
@@ -202,7 +259,7 @@ email:
202
259
  - brandondunne@hotmail.com
203
260
  - fryguy9@gmail.com
204
261
  - mmorsi@redhat.com
205
- - jrafanie@redhat.com
262
+ - jrafanie@gmail.com
206
263
  - keenan@thebrocks.net
207
264
  - twiest@redhat.com
208
265
  - ncarboni@redhat.com
@@ -218,7 +275,10 @@ email:
218
275
  - nicklamuro@gmail.com
219
276
  - djberg96@gmail.com
220
277
  - simaishi@redhat.com
221
- - drewuhlmann@gmail.com
278
+ - 16326669+d-m-u@users.noreply.github.com
279
+ - 42819689+whitesource-bolt-for-github[bot]@users.noreply.github.com
280
+ - adam@grare.com
281
+ - 29139614+renovate[bot]@users.noreply.github.com
222
282
  executables: []
223
283
  extensions: []
224
284
  extra_rdoc_files: []
@@ -268,7 +328,7 @@ homepage: http://github.com/ManageIQ/linux_admin
268
328
  licenses:
269
329
  - MIT
270
330
  metadata: {}
271
- post_install_message:
331
+ post_install_message:
272
332
  rdoc_options: []
273
333
  require_paths:
274
334
  - lib
@@ -276,15 +336,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
336
  requirements:
277
337
  - - ">="
278
338
  - !ruby/object:Gem::Version
279
- version: 2.0.0
339
+ version: '2.6'
280
340
  required_rubygems_version: !ruby/object:Gem::Requirement
281
341
  requirements:
282
342
  - - ">="
283
343
  - !ruby/object:Gem::Version
284
344
  version: '0'
285
345
  requirements: []
286
- rubygems_version: 3.0.6
287
- signing_key:
346
+ rubygems_version: 3.3.27
347
+ signing_key:
288
348
  specification_version: 4
289
349
  summary: LinuxAdmin is a module to simplify management of linux systems.
290
350
  test_files: []