ruby-nginx 1.0.0 → 1.0.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/lib/ruby/nginx/commands/add_host_mapping.rb +19 -3
- data/lib/ruby/nginx/commands/remove_host_mapping.rb +14 -3
- data/lib/ruby/nginx/commands/setup_nginx.rb +4 -2
- data/lib/ruby/nginx/commands/start_nginx.rb +1 -2
- data/lib/ruby/nginx/commands/stop_nginx.rb +1 -2
- data/lib/ruby/nginx/commands/validate_nginx_config.rb +1 -2
- data/lib/ruby/nginx/system/hosts.rb +4 -4
- data/lib/ruby/nginx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b53325ca5fc64324eaf5204d8192e9366a9564279e615d2e3797ce700c87556e
|
4
|
+
data.tar.gz: 6f29b0ed5033f6e738cef7b6b66a514be2d6aa7d1eae9c965f86dc8526e60c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4160c514cc0e5562dce1ec6c567dfaa234ecc555fc999eba2aa0739133c9df6a2af2332b688ae415f6593abe21e82c42f5c850fe54a2d00e692db31c78a95a31
|
7
|
+
data.tar.gz: 04d918dec2962326dbec3e20c02e5c62c4f8e9b5e9268d6416f69a1975895de5ff5c03c092e445b2aba14efdf420211e0d0b66e3e244f854cce9b339263f0304
|
@@ -11,19 +11,35 @@ module Ruby
|
|
11
11
|
@ip = ip
|
12
12
|
@sudo = sudo
|
13
13
|
sudo_reason = "Allow sudo elevation to add \"#{host}\" to /etc/hosts?"
|
14
|
-
cmd = "echo \"#{ip} #{host}\" | #{sudoify("tee -a /etc/hosts", sudo, sudo_reason)}"
|
15
14
|
|
16
|
-
super(
|
15
|
+
super(
|
16
|
+
cmd: "echo \"#{host_config}\" | #{sudoify("tee -a /etc/hosts", sudo, sudo_reason)}",
|
17
|
+
raise: Ruby::Nginx::ConfigError
|
18
|
+
)
|
17
19
|
end
|
18
20
|
|
19
21
|
def run
|
20
|
-
super
|
22
|
+
super unless added?
|
21
23
|
rescue Ruby::Nginx::ConfigError
|
22
24
|
raise if @sudo
|
23
25
|
|
24
26
|
# Elevate to sudo and try again.
|
25
27
|
self.class.new(@host, @ip, sudo: true).run
|
26
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def added?
|
33
|
+
hosts.include?(host_config)
|
34
|
+
end
|
35
|
+
|
36
|
+
def hosts
|
37
|
+
@hosts ||= Ruby::Nginx::System::SafeFile.read("/etc/hosts")
|
38
|
+
end
|
39
|
+
|
40
|
+
def host_config
|
41
|
+
"#{@ip} #{@host}"
|
42
|
+
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
end
|
@@ -7,8 +7,9 @@ module Ruby
|
|
7
7
|
module Nginx
|
8
8
|
module Commands
|
9
9
|
class RemoveHostMapping < TerminalCommand
|
10
|
-
def initialize(host, sudo: false)
|
10
|
+
def initialize(host, ignore_ip: nil, sudo: false)
|
11
11
|
@host = host
|
12
|
+
@ignore_ip = ignore_ip
|
12
13
|
@sudo = sudo
|
13
14
|
@sudo_reason = "Allow sudo elevation to remove \"#{host}\" from /etc/hosts?"
|
14
15
|
|
@@ -16,16 +17,26 @@ module Ruby
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def run
|
19
|
-
super
|
20
|
+
super unless removed?
|
20
21
|
rescue Ruby::Nginx::ConfigError
|
21
22
|
raise if @sudo
|
22
23
|
|
23
24
|
# Elevate to sudo and try again.
|
24
|
-
self.class.new(@host, sudo: true).run
|
25
|
+
self.class.new(@host, ignore_ip: @ignore_ip, sudo: true).run
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
def removed?
|
31
|
+
hosts.each_line.none? do |host_config|
|
32
|
+
host_config.include?(@host) && (@ignore_ip.nil? || !host_config.include?(@ignore_ip))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def hosts
|
37
|
+
@hosts ||= Ruby::Nginx::System::SafeFile.read("/etc/hosts")
|
38
|
+
end
|
39
|
+
|
29
40
|
def darwin_command
|
30
41
|
sudoify("sed -i '' '/#{@host}/d' /etc/hosts", @sudo, @sudo_reason)
|
31
42
|
end
|
@@ -20,9 +20,11 @@ module Ruby
|
|
20
20
|
def initialize(sudo: false)
|
21
21
|
@sudo = sudo
|
22
22
|
sudo_reason = "Allow sudo elevation to add \"#{INCLUDE_STATEMENT}\" to NGINX configuration file?"
|
23
|
-
cmd = "echo \"#{new_config}\" | #{sudoify("tee #{config_file_path}", sudo, sudo_reason)}"
|
24
23
|
|
25
|
-
super(
|
24
|
+
super(
|
25
|
+
cmd: "echo \"#{new_config}\" | #{sudoify("tee #{config_file_path}", sudo, sudo_reason)}",
|
26
|
+
raise: Ruby::Nginx::SetupError
|
27
|
+
)
|
26
28
|
end
|
27
29
|
|
28
30
|
def run
|
@@ -9,9 +9,8 @@ module Ruby
|
|
9
9
|
def initialize(sudo: false)
|
10
10
|
@sudo = sudo
|
11
11
|
sudo_reason = "Allow sudo elevation to start NGINX?"
|
12
|
-
cmd = sudoify("nginx", sudo, sudo_reason)
|
13
12
|
|
14
|
-
super(cmd
|
13
|
+
super(cmd: sudoify("nginx", sudo, sudo_reason), raise: Ruby::Nginx::StartError)
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
@@ -9,9 +9,8 @@ module Ruby
|
|
9
9
|
def initialize(sudo: false)
|
10
10
|
@sudo = sudo
|
11
11
|
sudo_reason = "Allow sudo elevation to stop NGINX?"
|
12
|
-
cmd = sudoify("nginx -s stop", sudo, sudo_reason)
|
13
12
|
|
14
|
-
super(cmd
|
13
|
+
super(cmd: sudoify("nginx -s stop", sudo, sudo_reason), raise: Ruby::Nginx::StopError)
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
@@ -9,9 +9,8 @@ module Ruby
|
|
9
9
|
def initialize(sudo: false)
|
10
10
|
@sudo = sudo
|
11
11
|
sudo_reason = "Allow sudo elevation to validate NGINX config?"
|
12
|
-
cmd = sudoify("nginx -t", sudo, sudo_reason)
|
13
12
|
|
14
|
-
super(cmd
|
13
|
+
super(cmd: sudoify("nginx -t", sudo, sudo_reason), raise: Ruby::Nginx::ConfigError)
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
@@ -9,12 +9,12 @@ module Ruby
|
|
9
9
|
class Hosts
|
10
10
|
class << self
|
11
11
|
def add(host, ip)
|
12
|
-
remove(host)
|
13
|
-
Commands::AddHostMapping.new(host, ip).run
|
12
|
+
remove(host, ignore_ip: ip)
|
13
|
+
Commands::AddHostMapping.new(host, ip).run&.success?
|
14
14
|
end
|
15
15
|
|
16
|
-
def remove(host)
|
17
|
-
Commands::RemoveHostMapping.new(host).run
|
16
|
+
def remove(host, ignore_ip: nil)
|
17
|
+
Commands::RemoveHostMapping.new(host, ignore_ip:).run&.success?
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/ruby/nginx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert McCutchen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|