ruby-nginx 1.0.0.pre.beta.2 → 1.0.0.pre.beta.4

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: b156b35e8d3f70164e365712dc0fd152c18ea08c0f3daed48032c81487014a48
4
- data.tar.gz: 8203893515a76640d100fa0b622229d0fda10f5f22a42902417771687f5e14ac
3
+ metadata.gz: 9a6d88117211b772d96bf97915e9ab94227c23fc3b30d01e658eca6d47c9f1fc
4
+ data.tar.gz: d64a2d5beb1392bfe892bc48f34a3cd36362a8e1022360e5081c37874bedf460
5
5
  SHA512:
6
- metadata.gz: '0239941b73ea3e6eb95e7c12804c8f88e7426773a30505069352045784362b3498c0a7519f9f1f7761a490979dcbda8578aad034aebff699c4f0fc90ddc1065f'
7
- data.tar.gz: ad7e3f5e297e2482c8c49487840d66c566ca036b4dc6dd3b57428316c4a87ac0b4784f1788e211f39845df9034ec29caae0da3790b6d1f94a32d7c3899cf5bc3
6
+ metadata.gz: 3eb09a3ffffa06c21b7e0432c63fd1d1a40ae4d5234003357087ca016091801bdb33e0cfbf22f16e461bde45ec38aa38465590224e8acb2cbfca13f632fc6dc3
7
+ data.tar.gz: ec68fde1a5e5ebe27383bc6e596533b2ed968d37fab890fbfa3033684a875105ff762441c69ad68c2b1cd9d94ca0833825888c55065bb7014875c9641eaa61d2
data/README.md CHANGED
@@ -156,6 +156,7 @@ Options:
156
156
  -r, [--root-path=ROOT_PATH] # default: $PWD
157
157
  -s, [--ssl], [--no-ssl], [--skip-ssl] # default: false
158
158
  -l, [--log], [--no-log], [--skip-log] # default: false
159
+ -t, [--template-path=TEMPLATE_PATH] # default: [GEM_PATH]/nginx/templates/nginx.conf
159
160
  -cert-file, [--ssl-certificate-path=SSL_CERTIFICATE_PATH] # default: ~/.ruby-nginx/certs/_[DOMAIN].pem
160
161
  -key-file, [--ssl-certificate-key-path=SSL_CERTIFICATE_KEY_PATH] # default: ~/.ruby-nginx/certs/_[DOMAIN]-key.pem
161
162
  -access-log, [--access-log-path=ACCESS_LOG_PATH] # default: ~/.ruby-nginx/logs/[DOMAIN].access.log
@@ -25,6 +25,7 @@ module Ruby
25
25
  method_option :root_path, aliases: "-r", type: :string, desc: "default: $PWD"
26
26
  method_option :ssl, aliases: "-s", type: :boolean, desc: defaults(:ssl)
27
27
  method_option :log, aliases: "-l", type: :boolean, desc: defaults(:log)
28
+ method_option :template_path, aliases: "-t", type: :string, desc: "default: [GEM_PATH]/nginx/templates/nginx.conf"
28
29
  method_option :ssl_certificate_path, aliases: "-cert-file", type: :string, desc: default_paths(:ssl_certificate_path)
29
30
  method_option :ssl_certificate_key_path, aliases: "-key-file", type: :string, desc: default_paths(:ssl_certificate_key_path)
30
31
  method_option :access_log_path, aliases: "-access-log", type: :string, desc: default_paths(:access_log_path)
@@ -35,6 +36,7 @@ module Ruby
35
36
  port: options.port,
36
37
  host: options.host,
37
38
  root_path: options.root_path,
39
+ template_path: options.template_path,
38
40
  ssl: options.ssl,
39
41
  log: options.log,
40
42
  ssl_certificate_path: options.ssl_certificate_path,
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruby
4
+ module Nginx
5
+ module Commands
6
+ module Helpers
7
+ module PromptHelper
8
+ def yes?(question)
9
+ return true if ENV["SKIP_PROMPT"]
10
+
11
+ retry_question = false
12
+
13
+ loop do
14
+ response = ask_question(question)
15
+
16
+ if !response.nil?
17
+ reset_line if retry_question
18
+ return print_confirm(question, response)
19
+ end
20
+
21
+ print_invalid_input && previous_line && reset_line
22
+ retry_question = true
23
+ end
24
+ rescue Interrupt
25
+ next_line && print_confirm(question, false)
26
+ raise Ruby::Nginx::AbortError, "Operation aborted"
27
+ end
28
+
29
+ private
30
+
31
+ def ask_question(question)
32
+ print "[Ruby::Nginx] #{question} \e[90m(Y/n)\e[0m "
33
+
34
+ case $stdin.gets.chomp.downcase
35
+ when "y", "yes"
36
+ true
37
+ when "n", "no"
38
+ false
39
+ end
40
+ end
41
+
42
+ def print_confirm(question, allowed)
43
+ previous_line && reset_line
44
+
45
+ print "[Ruby::Nginx] #{question} \e[32m#{allowed ? "yes" : "no"}\e[0m\n"
46
+ allowed
47
+ end
48
+
49
+ def reset_line
50
+ # 2K = clear line, 1G = move to first column
51
+ print "\e[2K\e[1G"
52
+ true
53
+ end
54
+
55
+ def previous_line
56
+ print "\e[1A"
57
+ true
58
+ end
59
+
60
+ def next_line
61
+ print "\n"
62
+ true
63
+ end
64
+
65
+ def print_invalid_input
66
+ print "\e[31m>>\e[0m Invalid input."
67
+ true
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty/command"
4
+ require_relative "prompt_helper"
5
+
6
+ module Ruby
7
+ module Nginx
8
+ module Commands
9
+ module Helpers
10
+ module SudoHelper
11
+ include Ruby::Nginx::Commands::Helpers::PromptHelper
12
+
13
+ def sudoify(cmd, sudo, reason)
14
+ return cmd unless sudo
15
+
16
+ if sudo_access? || yes?(reason)
17
+ "sudo #{cmd}"
18
+ else
19
+ raise Ruby::Nginx::AbortError, "Operation aborted"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def sudo_access?
26
+ TerminalCommand.new(cmd: "sudo -n true").run.success?
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -14,6 +14,8 @@ module Ruby
14
14
  def run
15
15
  return if installed?
16
16
 
17
+ puts "\e[0;33m#{cmd}\e[0m"
18
+
17
19
  if yes?("Would you like to install mkcert?")
18
20
  super
19
21
  else
@@ -14,10 +14,12 @@ module Ruby
14
14
  def run
15
15
  return if installed?
16
16
 
17
- if yes?("Would you like to install Nginx?")
17
+ puts "\e[0;33m#{cmd}\e[0m"
18
+
19
+ if yes?("Would you like to install NGINX?")
18
20
  super
19
21
  else
20
- raise Ruby::Nginx::AbortError, "Nginx is required to continue. Please install Nginx."
22
+ raise Ruby::Nginx::AbortError, "NGINX is required to continue. Please install NGINX."
21
23
  end
22
24
  end
23
25
 
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "tty/command"
4
- require "tty/prompt"
4
+ require_relative "helpers/prompt_helper"
5
+ require_relative "helpers/sudo_helper"
5
6
 
6
7
  module Ruby
7
8
  module Nginx
8
9
  module Commands
9
10
  class TerminalCommand
11
+ include Ruby::Nginx::Commands::Helpers::PromptHelper
12
+ include Ruby::Nginx::Commands::Helpers::SudoHelper
13
+
10
14
  attr_reader :cmd, :user, :error_type, :printer, :result
11
15
 
12
16
  def initialize(cmd:, user: nil, raise: nil, printer: :null)
@@ -22,28 +26,8 @@ module Ruby
22
26
  raise @error_type, @result.err if error_type && @result.failure?
23
27
 
24
28
  @result
25
- end
26
-
27
- protected
28
-
29
- def yes?(question)
30
- ENV["SKIP_PROMPT"] || TTY::Prompt.new.yes?("[Ruby::Nginx] #{question}")
31
- end
32
-
33
- def sudoify(cmd, sudo, reason)
34
- return cmd unless sudo
35
-
36
- if sudo_access? || yes?(reason)
37
- "sudo #{cmd}"
38
- else
39
- raise Ruby::Nginx::AbortError, "Operation aborted"
40
- end
41
- end
42
-
43
- private
44
-
45
- def sudo_access?
46
- TerminalCommand.new(cmd: "sudo -n true").run.success?
29
+ rescue Interrupt
30
+ raise Ruby::Nginx::AbortError, "Operation aborted"
47
31
  end
48
32
  end
49
33
  end
@@ -36,7 +36,7 @@ module Ruby
36
36
  create_ssl_certs! if options[:ssl]
37
37
  create_log_files! if options[:log]
38
38
 
39
- ERB.new(File.read(options[:template_path])).result(binding)
39
+ ERB.new(load_template).result(binding)
40
40
  end
41
41
 
42
42
  def defaults
@@ -82,6 +82,16 @@ module Ruby
82
82
  self.options = default_paths.merge(options)
83
83
  end
84
84
 
85
+ def load_template
86
+ File.read(options[:template_path])
87
+ rescue Errno::EISDIR
88
+ raise Ruby::Nginx::AbortError, "Template is a directory: #{options[:template_path]}"
89
+ rescue Errno::ENOENT
90
+ raise Ruby::Nginx::AbortError, "Template does not exist at: #{options[:template_path]}"
91
+ rescue => e
92
+ raise Ruby::Nginx::AbortError, "Failed to read template.", cause: e
93
+ end
94
+
85
95
  def create_ssl_certs!
86
96
  System::Mkcert.create!(
87
97
  options[:domain],
@@ -58,7 +58,8 @@ server {
58
58
  location @<%= name %> {
59
59
  proxy_pass http://<%= name %>;
60
60
  proxy_http_version 1.1;
61
- proxy_cache_bypass $http_upgrade;
61
+ proxy_no_cache 1;
62
+ proxy_cache_bypass 1;
62
63
 
63
64
  <% if options[:ssl] %>
64
65
  # proxy SSL
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ruby
4
4
  module Nginx
5
- VERSION = "1.0.0-beta.2"
5
+ VERSION = "1.0.0-beta.4"
6
6
 
7
7
  Version = Gem::Version
8
8
  end
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.0.pre.beta.2
4
+ version: 1.0.0.pre.beta.4
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-02-11 00:00:00.000000000 Z
11
+ date: 2025-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb
@@ -58,20 +58,6 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.10.1
61
- - !ruby/object:Gem::Dependency
62
- name: tty-prompt
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 0.3.0
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 0.3.0
75
61
  description: Utility gem with an added CLI for configuring NGINX with SSL.
76
62
  email:
77
63
  - mail@bertm.dev
@@ -89,6 +75,8 @@ files:
89
75
  - lib/ruby/nginx/commands/add_host_mapping.rb
90
76
  - lib/ruby/nginx/commands/add_nginx_config.rb
91
77
  - lib/ruby/nginx/commands/create_mkcert_certificate.rb
78
+ - lib/ruby/nginx/commands/helpers/prompt_helper.rb
79
+ - lib/ruby/nginx/commands/helpers/sudo_helper.rb
92
80
  - lib/ruby/nginx/commands/install_mkcert.rb
93
81
  - lib/ruby/nginx/commands/install_nginx.rb
94
82
  - lib/ruby/nginx/commands/nginx_options.rb