potluck-nginx 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5dc3bb7d62e4244f719abe5110cdb80a972b10f56f13d35844918a3eaa875df
4
- data.tar.gz: b971afa507788f9bf2261df078e7df83df963928dba62dcca2e1cbf80a10cd6a
3
+ metadata.gz: 4fc8a1ec53a80c8a2914316ea35e955a79851fde0c32b59c2d26b22c573e4d3f
4
+ data.tar.gz: 1f5beb340d4e719f11f98806a7d96844e9c71b11aef0de8441de516d170c0a24
5
5
  SHA512:
6
- metadata.gz: d6b3f68bf12bce2e2035689d9c07bd76af04d0f5c8ad596c1dfafb2c5faca4551e9a9d8c64e51fd6fb614f2b7e5dc4746a8f36137b5f416ecd78dffab961c6db
7
- data.tar.gz: 3885228d15374b68b7af5d86050aea5bab688e4de24fa4cb18a54599bdece7baa0e6495487b707547be70646eefe4099184b69c60128370151b069153f5b2136
6
+ metadata.gz: 2852025b7fa30b945c8450b23d9efbd725b5abf3dcc41875dff7a860e85a182074c7e47ea3bf8cf7442e7ebab0a715d56296cea541b5a1c9ad9906369aeaa3fc
7
+ data.tar.gz: 99cef178c6195136c566f55948b5b64068a56ffaa918f4bdea05c7f193d9161ad05796a7a33a3c4dfc0637d1ecb491a818dac35c36516c6a241b581a119f999e
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 Nate Pickens
1
+ Copyright 2021-2022 Nate Pickens
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
4
  documentation files (the "Software"), to deal in the Software without restriction, including without
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.7
@@ -49,8 +49,7 @@ module Potluck
49
49
  @auto_generated = !crt_file && !key_file && !dhparam_file
50
50
 
51
51
  if !@auto_generated && (!crt_file || !key_file || !dhparam_file)
52
- raise(ArgumentError.new('Must supply values for all three or none: crt_file, key_file, '\
53
- 'dhparam_file'))
52
+ raise(ArgumentError, 'Must supply values for all three or none: crt_file, key_file, dhparam_file')
54
53
  end
55
54
 
56
55
  @csr_file = File.join(@dir, "#{@host}.csr").freeze
@@ -74,10 +73,10 @@ module Potluck
74
73
  #
75
74
  def ensure_files
76
75
  return if !@auto_generated || (
77
- File.exists?(@csr_file) &&
78
- File.exists?(@key_file) &&
79
- File.exists?(@crt_file) &&
80
- File.exists?(@dhparam_file) &&
76
+ File.exist?(@csr_file) &&
77
+ File.exist?(@key_file) &&
78
+ File.exist?(@crt_file) &&
79
+ File.exist?(@dhparam_file) &&
81
80
  (Time.parse(
82
81
  @nginx.run("openssl x509 -enddate -noout -in #{@crt_file}").sub('notAfter=', '')
83
82
  ) - Time.now) >= CERT_RENEW_DAYS * 24 * 60 * 60
@@ -85,13 +84,13 @@ module Potluck
85
84
 
86
85
  @nginx.log('Generating SSL files...')
87
86
 
88
- @nginx.run("openssl genrsa -out #{@key_file} 4096", redirect_stderr: false)
87
+ @nginx.run("openssl genrsa -out #{@key_file} 4096", capture_stderr: false)
89
88
  @nginx.run("openssl req -out #{@csr_file} -key #{@key_file} -new -sha256 -config /dev/stdin <<< "\
90
- "'#{openssl_config}'", redirect_stderr: false)
89
+ "'#{openssl_config}'", capture_stderr: false)
91
90
  @nginx.run("openssl x509 -in #{@csr_file} -out #{@crt_file} -signkey #{@key_file} -days "\
92
91
  "#{CERT_DAYS} -req -sha256 -extensions req_ext -extfile /dev/stdin <<< '#{openssl_config}'",
93
- redirect_stderr: false)
94
- @nginx.run("openssl dhparam -out #{@dhparam_file} 2048", redirect_stderr: false)
92
+ capture_stderr: false)
93
+ @nginx.run("openssl dhparam -out #{@dhparam_file} 2048", capture_stderr: false)
95
94
 
96
95
  if IS_MACOS
97
96
  @nginx.log('Adding cert to keychain...')
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Potluck
4
+ class Nginx < Service
5
+ VERSION = '0.0.7'
6
+ end
7
+ end
data/lib/potluck/nginx.rb CHANGED
@@ -4,6 +4,7 @@ require('fileutils')
4
4
  require('potluck')
5
5
  require_relative('nginx/ssl')
6
6
  require_relative('nginx/util')
7
+ require_relative('nginx/version')
7
8
 
8
9
  module Potluck
9
10
  ##
@@ -56,7 +57,7 @@ module Potluck
56
57
  def initialize(hosts, port, subdomains: nil, ssl: nil, one_host: false, www: nil, multiple_slashes: nil,
57
58
  multiple_question_marks: nil, trailing_slash: nil, trailing_question_mark: nil, config: {},
58
59
  ensure_host_entries: false, **args)
59
- if args[:manage] && !args[:manage].kind_of?(Hash) && !launchctl?
60
+ if args[:manage] && !args[:manage].kind_of?(Hash) && !self.class.launchctl?
60
61
  args[:manage] = NON_LAUNCHCTL_COMMANDS
61
62
  end
62
63
 
@@ -138,6 +139,98 @@ module Potluck
138
139
  self.class.to_nginx_config(config)
139
140
  end
140
141
 
142
+ ##
143
+ # Content of the launchctl plist file.
144
+ #
145
+ def self.plist
146
+ super(
147
+ <<~EOS
148
+ <key>ProgramArguments</key>
149
+ <array>
150
+ <string>#{HOMEBREW_PREFIX}/opt/nginx/bin/nginx</string>
151
+ <string>-g</string>
152
+ <string>daemon off;</string>
153
+ </array>
154
+ <key>StandardOutPath</key>
155
+ <string>#{HOMEBREW_PREFIX}/var/log/nginx/access.log</string>
156
+ <key>StandardErrorPath</key>
157
+ <string>#{HOMEBREW_PREFIX}/var/log/nginx/error.log</string>
158
+ EOS
159
+ )
160
+ end
161
+
162
+ ##
163
+ # Converts a hash to an Nginx configuration file content string. Keys should be strings and values
164
+ # either strings or hashes. A +nil+ value in a hash will result in that key-value pair being omitted.
165
+ #
166
+ # * +hash+ - Hash to convert to the string content of an Nginx configuration file.
167
+ # * +indent+ - Number of spaces to indent; used when the method is called recursively and should not be
168
+ # set explicitly (optional, default: 0).
169
+ # * +repeat+ - Value to prepend to each entry of the hash; used when the method is called recursively
170
+ # and should not be set explicitly (optional).
171
+ #
172
+ # Symbol keys in hashes are used as special directives. Including <tt>repeat: true</tt> will cause the
173
+ # parent hash's key for the child hash to be prefixed to each line of the output. Example:
174
+ #
175
+ # {
176
+ # # ...
177
+ #
178
+ # 'add_header' => {
179
+ # repeat: true,
180
+ # 'X-Frame-Options' => 'DENY',
181
+ # 'X-Content-Type-Options' => 'nosniff',
182
+ # }
183
+ # }
184
+ #
185
+ # Result:
186
+ #
187
+ # # ...
188
+ #
189
+ # add_header X-Frame-Options DENY;
190
+ # add_header X-Content-Type-Options nosniff;
191
+ #
192
+ # A hash containing <tt>raw: '...'</tt> can be used to include a raw chunk of text rather than key-value
193
+ # pairs. Example:
194
+ #
195
+ # {
196
+ # # ...
197
+ #
198
+ # 'location /' => {
199
+ # raw: """
200
+ # if ($scheme = https) { ... }
201
+ # if ($host ~ ^www.) { ... }
202
+ # """,
203
+ # }
204
+ # }
205
+ #
206
+ # Result:
207
+ #
208
+ # location / {
209
+ # if ($scheme = https) { ... }
210
+ # if ($host ~ ^www.) { ... }
211
+ # }
212
+ #
213
+ def self.to_nginx_config(hash, indent: 0, repeat: nil)
214
+ hash.each_with_object(+'') do |(k, v), config|
215
+ next if v.nil?
216
+ next if k == :repeat
217
+
218
+ config << (
219
+ if v.kind_of?(Hash)
220
+ if v[:repeat]
221
+ to_nginx_config(v, indent: indent, repeat: k)
222
+ else
223
+ "#{' ' * indent}#{k} {\n#{to_nginx_config(v, indent: indent + 2)}#{' ' * indent}}\n"
224
+ end
225
+ elsif k == :raw
226
+ "#{v.gsub(/^(?=.)/, ' ' * indent)}\n\n"
227
+ else
228
+ "#{' ' * indent}#{"#{repeat} " if repeat}#{k}#{" #{v}" unless v == true};\n"
229
+ end
230
+ )
231
+ end
232
+ end
233
+
141
234
  private
142
235
 
143
236
  ##
@@ -259,9 +352,7 @@ module Potluck
259
352
  # Writes the Nginx configuration to the (inactive) configuration file.
260
353
  #
261
354
  def write_config
262
- File.open(@config_file_inactive, 'w') do |file|
263
- file.write(config_file_content)
264
- end
355
+ File.write(@config_file_inactive, config_file_content)
265
356
  end
266
357
 
267
358
  ##
@@ -275,7 +366,7 @@ module Potluck
275
366
  # Renames the active Nginx configuration file to its inactive name.
276
367
  #
277
368
  def deactivate_config
278
- FileUtils.mv(@config_file_active, @config_file_inactive) if File.exists?(@config_file_active)
369
+ FileUtils.mv(@config_file_active, @config_file_inactive) if File.exist?(@config_file_active)
279
370
  end
280
371
 
281
372
  ##
@@ -315,97 +406,5 @@ module Potluck
315
406
  "\\1\\2\\3include #{ACTIVE_CONFIG_PATTERN};\n\n\\3"))
316
407
  end
317
408
  end
318
-
319
- ##
320
- # Converts a hash to an Nginx configuration file content string. Keys should be strings and values
321
- # either strings or hashes. A +nil+ value in a hash will result in that key-value pair being omitted.
322
- #
323
- # * +hash+ - Hash to convert to the string content of an Nginx configuration file.
324
- # * +indent+ - Number of spaces to indent; used when the method is called recursively and should not be
325
- # set explicitly (optional, default: 0).
326
- # * +repeat+ - Value to prepend to each entry of the hash; used when the method is called recursively
327
- # and should not be set explicitly (optional).
328
- #
329
- # Symbol keys in hashes are used as special directives. Including <tt>repeat: true</tt> will cause the
330
- # parent hash's key for the child hash to be prefixed to each line of the output. Example:
331
- #
332
- # {
333
- # # ...
334
- #
335
- # 'add_header' => {
336
- # repeat: true,
337
- # 'X-Frame-Options' => 'DENY',
338
- # 'X-Content-Type-Options' => 'nosniff',
339
- # }
340
- # }
341
- #
342
- # Result:
343
- #
344
- # # ...
345
- #
346
- # add_header X-Frame-Options DENY;
347
- # add_header X-Content-Type-Options nosniff;
348
- #
349
- # A hash containing <tt>raw: '...'</tt> can be used to include a raw chunk of text rather than key-value
350
- # pairs. Example:
351
- #
352
- # {
353
- # # ...
354
- #
355
- # 'location /' => {
356
- # raw: """
357
- # if ($scheme = https) { ... }
358
- # if ($host ~ ^www.) { ... }
359
- # """,
360
- # }
361
- # }
362
- #
363
- # Result:
364
- #
365
- # location / {
366
- # if ($scheme = https) { ... }
367
- # if ($host ~ ^www.) { ... }
368
- # }
369
- #
370
- def self.to_nginx_config(hash, indent: 0, repeat: nil)
371
- hash.each_with_object(+'') do |(k, v), config|
372
- next if v.nil?
373
- next if k == :repeat
374
-
375
- config << (
376
- if v.kind_of?(Hash)
377
- if v[:repeat]
378
- to_nginx_config(v, indent: indent, repeat: k)
379
- else
380
- "#{' ' * indent}#{k} {\n#{to_nginx_config(v, indent: indent + 2)}#{' ' * indent}}\n"
381
- end
382
- elsif k == :raw
383
- "#{v.gsub(/^(?=.)/, ' ' * indent)}\n\n"
384
- else
385
- "#{' ' * indent}#{"#{repeat} " if repeat}#{k}#{" #{v}" unless v == true};\n"
386
- end
387
- )
388
- end
389
- end
390
-
391
- ##
392
- # Content of the launchctl plist file.
393
- #
394
- def self.plist
395
- super(
396
- <<~EOS
397
- <key>ProgramArguments</key>
398
- <array>
399
- <string>/usr/local/opt/nginx/bin/nginx</string>
400
- <string>-g</string>
401
- <string>daemon off;</string>
402
- </array>
403
- <key>StandardOutPath</key>
404
- <string>/usr/local/var/log/nginx/access.log</string>
405
- <key>StandardErrorPath</key>
406
- <string>/usr/local/var/log/nginx/error.log</string>
407
- EOS
408
- )
409
- end
410
409
  end
411
410
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potluck-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Pickens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-31 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: potluck
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.5
19
+ version: 0.0.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.5
26
+ version: 0.0.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,9 +67,11 @@ extra_rdoc_files: []
67
67
  files:
68
68
  - LICENSE
69
69
  - README.md
70
+ - VERSION
70
71
  - lib/potluck/nginx.rb
71
72
  - lib/potluck/nginx/ssl.rb
72
73
  - lib/potluck/nginx/util.rb
74
+ - lib/potluck/nginx/version.rb
73
75
  homepage: https://github.com/npickens/potluck/tree/master/potluck-nginx
74
76
  licenses:
75
77
  - MIT
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  - !ruby/object:Gem::Version
93
95
  version: '0'
94
96
  requirements: []
95
- rubygems_version: 3.2.32
97
+ rubygems_version: 3.3.7
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: A Ruby manager for Nginx.