nginx_utils 0.1.1 → 0.1.2

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjU5NmIzZjlmY2YyOWU3ZTliMjE1NzVlMjY5MTY5OTAyYzNlMDNmOA==
5
- data.tar.gz: !binary |-
6
- Y2YyYTYwNmI1NTAzZjU0OTNhYTE0NWIyMjdkOWY5ODE5YWFhMTBkOQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZGJiMzBmMzY2OTY3M2IzMmRiMjliMTMxNDhmMjNlODNkMmEwZmU4MjU4ZTY3
10
- Mjc5ZDNhMTg4NWM5ODYzMmI0Y2VjMThjMTM4NTcwY2M1MjcwOGE4ZmQ2MTcw
11
- ODRmOGJlNWFiZmU2YzFmMmQyZjY4ODU3YzFjNzA3MDJkYjNiYWU=
12
- data.tar.gz: !binary |-
13
- ZTY3Mzg5N2Q4NGZlOTNiZDc0NjA1OTFkOWM4ZTRkMDI5NGNhYTEzYjA5OTFl
14
- Y2Q1ZTY5OTVhZTA4MjUxYmJiZmY2NTgwYjhkMTU2Mjg3MzkzYTE3OGRlNjBl
15
- N2RkNGJiNTZjYjQ2N2I1NGU4MDQwYWJhYzRjZGVmMmU3NzY3ZTU=
2
+ SHA1:
3
+ metadata.gz: cf5488e608925ed21642a11030049b886a369d63
4
+ data.tar.gz: ea2d9f31581ed7adedea3771e36af73058ee3225
5
+ SHA512:
6
+ metadata.gz: 4c5cab54b88e8a94344c9ec2165b7aa25e63bb0144df44c6438c0339fbb22b2d67c9925fee74104f64a3a783a686b6c38cf4ef210a33d131b22392854beea26e
7
+ data.tar.gz: 1c224216d8b3684e562e206fbd623eb3ba1aa9be65a540134ba95110dd85c96d628657fd28a9ad2ca94b5780431e1023c73dd8dfdcb9df95240166016dd010de
@@ -5,11 +5,6 @@ rvm:
5
5
  gemfile:
6
6
  - Gemfile
7
7
  script: bundle exec rake spec
8
- branches:
9
- only:
10
- - master
11
8
  notifications:
12
9
  mails:
13
- - i2bskn@gmail.com
14
- on_sucess: always
15
- on_failure: always
10
+ - i2bskn@gmail.com
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
+ path = File.expand_path("../../lib", __FILE__)
5
+ $:.unshift(path) unless $:.include?(path)
4
6
  require "nginx_utils"
5
7
 
6
8
  NginxUtils::CLI.start
@@ -8,14 +8,11 @@ module NginxUtils
8
8
  @log = File.open(log)
9
9
 
10
10
  if options[:parser]
11
- if options[:parser].is_a? Regexp
12
- @format = :custom
13
- @parser = options[:parser]
14
- else
15
- raise ArgumentError, "invalid argument"
16
- end
11
+ raise ArgumentError, "invalid argument" unless options[:parser].is_a? Regexp
12
+ @format = :custom
13
+ @parser = options[:parser]
17
14
  else
18
- @format = options[:format] || :ltsv
15
+ @format = options.fetch(:format, :ltsv)
19
16
  end
20
17
  end
21
18
 
@@ -4,9 +4,9 @@ module NginxUtils
4
4
  module Status
5
5
  class << self
6
6
  def get(options={})
7
- host = options[:host] || "localhost"
8
- port = options[:port] || 80
9
- path = options[:path] || "/nginx_status"
7
+ host = options.fetch(:host, "localhost")
8
+ port = options.fetch(:port, 80)
9
+ path = options.fetch(:path, "/nginx_status")
10
10
 
11
11
  req = Net::HTTP::Get.new(path)
12
12
  res = Net::HTTP.start(host, port){|http| http.request(req)}
@@ -1,3 +1,3 @@
1
1
  module NginxUtils
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -20,10 +20,10 @@ module NginxUtils
20
20
  case options[:vhost_type].to_sym
21
21
  when :unicorn then
22
22
  @vhost_type = :unicorn
23
- @destination = options[:destination] || "127.0.0.1:8080"
23
+ @destination = options.fetch(:destination, "127.0.0.1:8080")
24
24
  when :proxy then
25
25
  @vhost_type = :proxy
26
- @destination = options[:destination] || "127.0.0.1:8080"
26
+ @destination = options.fetch(:destination, "127.0.0.1:8080")
27
27
  when :passenger then
28
28
  @vhost_type = :passenger
29
29
  else
@@ -38,13 +38,13 @@ module NginxUtils
38
38
 
39
39
  def set_common_params(options)
40
40
  # Arguments: prefix, server_name, root, index, auth_basic, auth_basic_user_file in options
41
- @prefix = options[:prefix] || "/usr/local/nginx"
42
- @server_name = options[:server_name] || "example.com"
43
- @root = options[:root] || File.join(@prefix, "vhosts", @server_name, "html")
44
- @index = options[:index] || ["index.html", "index.htm"].join(" ")
41
+ @prefix = options.fetch(:prefix, "/usr/local/nginx")
42
+ @server_name = options.fetch(:server_name, "example.com")
43
+ @root = options.fetch(:root, File.join(@prefix, "vhosts", @server_name, "html"))
44
+ @index = options.fetch(:index, ["index.html", "index.htm"].join(" "))
45
45
  @auth_basic = options[:auth_basic]
46
46
  if @auth_basic
47
- @auth_basic_user_file = options[:auth_basic_user_file] || File.join(@prefix, "vhosts", @server_name, "etc", "users")
47
+ @auth_basic_user_file = options.fetch(:auth_basic_user_file, File.join(@prefix, "vhosts", @server_name, "etc", "users"))
48
48
  end
49
49
  end
50
50
 
@@ -55,16 +55,16 @@ module NginxUtils
55
55
  @http = false if options[:only_https]
56
56
  @https = false if options[:only_http]
57
57
  if @https
58
- @ssl_certificate = options[:ssl_certificate] || File.join(@prefix, "vhosts", @server_name, "ssl.crt", "server.crt")
59
- @ssl_certificate_key = options[:ssl_certificate_key] || File.join(@prefix, "vhosts", @server_name, "ssl.key", "server.key")
58
+ @ssl_certificate = options.fetch(:ssl_certificate, File.join(@prefix, "vhosts", @server_name, "ssl.crt", "server.crt"))
59
+ @ssl_certificate_key = options.fetch(:ssl_certificate_key, File.join(@prefix, "vhosts", @server_name, "ssl.key", "server.key"))
60
60
  end
61
61
  end
62
62
 
63
63
  def set_log_params(options)
64
64
  # Arguments: log_dir, access_log_format, error_log_level in options
65
- @log_dir = options[:log_dir] || File.join(@prefix, "vhosts", @server_name, "logs")
66
- @access_log_format = options[:access_log_format] || :ltsv
67
- @error_log_level = options[:error_log_level] || :info
65
+ @log_dir = options.fetch(:log_dir, File.join(@prefix, "vhosts", @server_name, "logs"))
66
+ @access_log_format = options.fetch(:access_log_format, :ltsv)
67
+ @error_log_level = options.fetch(:error_log_level, :info)
68
68
  end
69
69
 
70
70
  def config
@@ -1,21 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "spec_helper"
4
- require "stringio"
5
4
 
6
5
  describe NginxUtils::CLI do
7
- def capture(stream)
8
- begin
9
- stream = stream.to_s
10
- eval "$#{stream} = StringIO.new"
11
- yield
12
- result = eval("$#{stream}").string
13
- ensure
14
- eval("$#{stream} = #{stream.upcase}")
15
- end
16
- result
17
- end
18
-
19
6
  describe "#status" do
20
7
  let(:result) {
21
8
  {
@@ -179,67 +179,146 @@ describe NginxUtils::VirtualHost do
179
179
  end
180
180
 
181
181
  describe "#config" do
182
- subject {
183
- virtual_host = NginxUtils::VirtualHost.new(
184
- vhost_type: :unicorn,
185
- destination: "/usr/local/rails/app/tmp/unicorn.sock",
186
- prefix: "/opt/nginx",
187
- server_name: "nginx_utils.example.com",
188
- index: "index.rb",
189
- log_dir: "/var/log",
190
- access_log_format: "combined",
191
- error_log_level: "error",
192
- auth_basic: "Auth"
193
- )
194
- virtual_host.config
195
- }
196
-
197
- it "upstream block should be defined" do
198
- should match(/upstream backend-unicorn/)
199
- end
182
+ context "for unicron" do
183
+ subject {
184
+ virtual_host = NginxUtils::VirtualHost.new(
185
+ vhost_type: :unicorn,
186
+ destination: "/usr/local/rails/app/tmp/unicorn.sock",
187
+ prefix: "/opt/nginx",
188
+ server_name: "nginx_utils.example.com",
189
+ index: "index.rb",
190
+ log_dir: "/var/log",
191
+ access_log_format: "combined",
192
+ error_log_level: "error",
193
+ auth_basic: "Auth"
194
+ )
195
+ virtual_host.config
196
+ }
197
+
198
+ it "upstream block should be defined" do
199
+ should match(/upstream backend-unicorn/)
200
+ end
200
201
 
201
- it "http block should be defined" do
202
- should match(/listen 80;/)
203
- end
202
+ it "http block should be defined" do
203
+ should match(/listen 80;/)
204
+ end
204
205
 
205
- it "https block should be defined" do
206
- should match(/listen 443 ssl;/)
207
- end
206
+ it "https block should be defined" do
207
+ should match(/listen 443 ssl;/)
208
+ end
208
209
 
209
- it "unix domain socket should be defined" do
210
- should match(/server unix:\/usr\/local\/rails\/app\/tmp\/unicorn\.sock;/)
211
- end
210
+ it "unix domain socket should be defined" do
211
+ should match(/server unix:\/usr\/local\/rails\/app\/tmp\/unicorn\.sock;/)
212
+ end
212
213
 
213
- it "server_name should be defined" do
214
- should match(/server_name nginx_utils.example.com;/)
215
- end
214
+ it "server_name should be defined" do
215
+ should match(/server_name nginx_utils.example.com;/)
216
+ end
216
217
 
217
- it "index should be defined" do
218
- should match(/index index.rb;/)
219
- end
218
+ it "index should be defined" do
219
+ should match(/index index.rb;/)
220
+ end
220
221
 
221
- it "access_log should be defined" do
222
- should match(/access_log \/var\/log\/access.log combined;/)
223
- end
222
+ it "access_log should be defined" do
223
+ should match(/access_log \/var\/log\/access.log combined;/)
224
+ end
224
225
 
225
- it "error_log should be defined" do
226
- should match(/error_log \/var\/log\/error.log error;/)
227
- end
226
+ it "error_log should be defined" do
227
+ should match(/error_log \/var\/log\/error.log error;/)
228
+ end
228
229
 
229
- it "auth_basic should be defined" do
230
- should match(/auth_basic "Auth";/)
231
- end
230
+ it "auth_basic should be defined" do
231
+ should match(/auth_basic "Auth";/)
232
+ end
233
+
234
+ it "auth_basic_user_file should be defined" do
235
+ should match(/auth_basic_user_file \/opt\/nginx\/vhosts\/nginx_utils\.example\.com\/etc\/users;/)
236
+ end
237
+
238
+ it "try_files should be defined" do
239
+ should match(/try_files/)
240
+ end
232
241
 
233
- it "auth_basic_user_file should be defined" do
234
- should match(/auth_basic_user_file \/opt\/nginx\/vhosts\/nginx_utils\.example\.com\/etc\/users;/)
242
+ it "proxy_pass should be defined" do
243
+ should match(/proxy_pass http:\/\/backend-unicorn;/)
244
+ end
235
245
  end
236
246
 
237
- it "try_files should be defined" do
238
- should match(/try_files/)
247
+ context "for passenger" do
248
+ subject {
249
+ virtual_host = NginxUtils::VirtualHost.new(
250
+ vhost_type: :passenger,
251
+ only_https: true
252
+ )
253
+ virtual_host.config
254
+ }
255
+
256
+ it "upstream block should not defined" do
257
+ should_not match(/upstream backend-unicorn/)
258
+ end
259
+
260
+ it "http block should not defined" do
261
+ should_not match(/listen 80/)
262
+ end
263
+
264
+ it "auth_basic should not defined" do
265
+ should_not match(/auth_basic/)
266
+ end
267
+
268
+ it "proxy_pass should not defined" do
269
+ should_not match(/proxy_pass/)
270
+ end
271
+
272
+ it "https block should be defined" do
273
+ should match(/listen 443 ssl/)
274
+ end
275
+
276
+ it "server_name should be default" do
277
+ should match(/server_name example.com;/)
278
+ end
279
+
280
+ it "index should be default" do
281
+ should match(/index index.html index.htm;/)
282
+ end
283
+
284
+ it "passenger_enabled should be defined" do
285
+ should match(/passenger_enabled on/)
286
+ end
239
287
  end
240
288
 
241
- it "proxy_pass should be defined" do
242
- should match(/proxy_pass http:\/\/backend-unicorn;/)
289
+ context "for proxy" do
290
+ subject {
291
+ virtual_host = NginxUtils::VirtualHost.new(
292
+ vhost_type: :proxy,
293
+ destination: "192.168.10.241:8080",
294
+ only_http: true
295
+ )
296
+ virtual_host.config
297
+ }
298
+
299
+ it "upstream block should not defined" do
300
+ should_not match(/upstream backend-unicorn/)
301
+ end
302
+
303
+ it "http block should defined" do
304
+ should match(/listen 80/)
305
+ end
306
+
307
+ it "https block should not defined" do
308
+ should_not match(/listen 443 ssl/)
309
+ end
310
+
311
+ it "proxy_pass should defined" do
312
+ should match(/proxy_pass http:\/\/192\.168\.10\.241:8080/)
313
+ end
314
+
315
+ it "proxy_redirect should defined" do
316
+ should match(/proxy_redirect default/)
317
+ end
318
+
319
+ it "passenger_enabled should be defined" do
320
+ should_not match(/passenger_enabled on/)
321
+ end
243
322
  end
244
323
  end
245
324
  end
@@ -2,8 +2,22 @@ require "simplecov"
2
2
  require "coveralls"
3
3
  Coveralls.wear!
4
4
 
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+
5
10
  SimpleCov.start do
6
11
  add_filter "spec"
12
+ add_filter ".bundle"
7
13
  end
8
14
 
9
15
  require "nginx_utils"
16
+
17
+ support_files = File.join(File.expand_path("..", __FILE__), "support/*.rb")
18
+ Dir[support_files].each {|f| require f}
19
+
20
+ RSpec.configure do |config|
21
+ config.order = "random"
22
+ config.include(SpecUtils)
23
+ end
@@ -0,0 +1,15 @@
1
+ require "stringio"
2
+
3
+ module SpecUtils
4
+ def capture(stream)
5
+ begin
6
+ stream = stream.to_s
7
+ eval "$#{stream} = StringIO.new"
8
+ yield
9
+ result = eval("$#{stream}").string
10
+ ensure
11
+ eval("$#{stream} = #{stream.upcase}")
12
+ end
13
+ result
14
+ end
15
+ end
@@ -38,7 +38,6 @@ server {
38
38
  location @proxy {
39
39
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
40
40
  proxy_set_header Host $http_host;
41
- proxy_set_header X-Forwarded-Proto https;
42
41
  proxy_redirect off;
43
42
 
44
43
  <% if @vhost_type == :passenger %>
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginx_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2bskn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
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
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: The various utilities on nginx
@@ -96,6 +96,7 @@ files:
96
96
  - spec/nginx_utils/status_spec.rb
97
97
  - spec/nginx_utils/virtual_host_spec.rb
98
98
  - spec/spec_helper.rb
99
+ - spec/support/spec_utils.rb
99
100
  - template/virtual_host.erb
100
101
  homepage: https://github.com/i2bskn/nginx_utils
101
102
  licenses:
@@ -107,17 +108,17 @@ require_paths:
107
108
  - lib
108
109
  required_ruby_version: !ruby/object:Gem::Requirement
109
110
  requirements:
110
- - - ! '>='
111
+ - - '>='
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - ! '>='
116
+ - - '>='
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.0.3
121
+ rubygems_version: 2.1.6
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Nginx utilities
@@ -128,3 +129,4 @@ test_files:
128
129
  - spec/nginx_utils/status_spec.rb
129
130
  - spec/nginx_utils/virtual_host_spec.rb
130
131
  - spec/spec_helper.rb
132
+ - spec/support/spec_utils.rb