redirus 0.1.2 → 0.2.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/.ruby-version +1 -1
- data/CHANGELOG +11 -0
- data/Gemfile.lock +67 -58
- data/Guardfile +1 -1
- data/README.md +102 -38
- data/bin/redirus +2 -2
- data/bin/redirus-client +2 -2
- data/bin/redirus-init +7 -0
- data/lib/redirus/cli/client.rb +183 -0
- data/lib/redirus/cli/init.rb +173 -0
- data/lib/redirus/cli/server.rb +101 -0
- data/lib/redirus/cli.rb +4 -141
- data/lib/redirus/config.rb +2 -21
- data/lib/redirus/proxy.rb +16 -25
- data/lib/redirus/utils.rb +15 -0
- data/lib/redirus/version.rb +1 -1
- data/lib/redirus/worker/add_proxy.rb +46 -35
- data/lib/redirus/worker/rm_proxy.rb +1 -0
- data/lib/redirus.rb +10 -5
- data/redirus.gemspec +7 -7
- data/spec/redirus/config_spec.rb +8 -8
- data/spec/redirus/proxy_spec.rb +1 -1
- data/spec/redirus/worker/add_proxy_spec.rb +41 -25
- data/spec/resources/config.yml +3 -19
- data/spec/resources/http.erb.conf +19 -0
- data/spec/resources/https.erb.conf +21 -0
- data/spec/support/resources.rb +3 -0
- data/templates/config.yml +16 -0
- data/templates/http.conf.erb +17 -0
- data/templates/https.conf.erb +21 -0
- data/templates/nginx.conf +24 -0
- metadata +52 -38
- data/config.yml.example +0 -33
- data/lib/redirus/server_cli.rb +0 -86
data/spec/redirus/config_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Redirus::Config do
|
4
4
|
|
5
5
|
context 'loading default values' do
|
6
|
-
let(:config) { Redirus::Config.new
|
6
|
+
let(:config) { Redirus::Config.new('nonexisting_config_file') }
|
7
7
|
|
8
8
|
it 'returns redis config' do
|
9
9
|
expect(config.queues).to eq ['default']
|
@@ -14,15 +14,16 @@ describe Redirus::Config do
|
|
14
14
|
it 'returns nginx files location' do
|
15
15
|
expect(config.nginx_pid_file).to eq 'nginx.pid'
|
16
16
|
expect(config.configs_path).to eq 'sites-enabled'
|
17
|
-
expect(config.http_template).to eq '
|
18
|
-
expect(config.https_template).to start_with '
|
19
|
-
expect(config.config_template).to start_with '#{upstream}'
|
17
|
+
expect(config.http_template).to eq 'http.conf.erb'
|
18
|
+
expect(config.https_template).to start_with 'https.conf.erb'
|
20
19
|
expect(config.allowed_properties).to eq []
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
context 'loading config from file' do
|
25
|
-
let(:config)
|
24
|
+
let(:config) do
|
25
|
+
Redirus::Config.new(File.join(SPEC_DIR, 'resources', 'config.yml'))
|
26
|
+
end
|
26
27
|
|
27
28
|
it 'returns redis config' do
|
28
29
|
expect(config.queues).to eq ['first', 'second']
|
@@ -33,9 +34,8 @@ describe Redirus::Config do
|
|
33
34
|
it 'returns nginx files location' do
|
34
35
|
expect(config.nginx_pid_file).to eq 'configfile-nginx.pid'
|
35
36
|
expect(config.configs_path).to eq 'configfile-sites-enabled'
|
36
|
-
expect(config.http_template).to eq '
|
37
|
-
expect(config.https_template).to start_with '
|
38
|
-
expect(config.config_template).to start_with '## configfile'
|
37
|
+
expect(config.http_template).to eq '/path/to/http/tmpl'
|
38
|
+
expect(config.https_template).to start_with '/path/to/https/tmpl'
|
39
39
|
expect(config.allowed_properties).to eq ['proxy_send_timeout \d', 'proxy_read_timeout \d']
|
40
40
|
end
|
41
41
|
end
|
data/spec/redirus/proxy_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Redirus::Proxy do
|
|
9
9
|
}
|
10
10
|
|
11
11
|
before do
|
12
|
-
Redirus.
|
12
|
+
allow(Redirus).to receive(:config).and_return(config)
|
13
13
|
allow(File).to receive(:open).with('nginx_pid_file').and_yield(nginx_pid_file)
|
14
14
|
allow(nginx_pid_file).to receive(:read).and_return('123')
|
15
15
|
end
|
@@ -6,19 +6,8 @@ describe Redirus::Worker::AddProxy do
|
|
6
6
|
let(:config) {
|
7
7
|
double('worker configuration',
|
8
8
|
configs_path: 'configs_base_path',
|
9
|
-
http_template: '
|
10
|
-
https_template: '
|
11
|
-
base_server_name: 'localhost',
|
12
|
-
config_template: %q[#{upstream}
|
13
|
-
server {
|
14
|
-
#{listen}
|
15
|
-
server_name #{name}.my.server.pl;
|
16
|
-
location / {
|
17
|
-
proxy_pass http://#{upstream_name};
|
18
|
-
#{properties}
|
19
|
-
}
|
20
|
-
}
|
21
|
-
],
|
9
|
+
http_template: File.join(resources_dir, 'http.erb.conf'),
|
10
|
+
https_template: File.join(resources_dir, 'https.erb.conf'),
|
22
11
|
allowed_properties: ['proxy_send_timeout \d', 'proxy_read_timeout \d'],
|
23
12
|
nginx_pid_file: 'nginx_pid_file'
|
24
13
|
)
|
@@ -39,19 +28,23 @@ describe Redirus::Worker::AddProxy do
|
|
39
28
|
end
|
40
29
|
|
41
30
|
it 'sets http listen section' do
|
42
|
-
expect(proxy_file).to have_received(:write).
|
31
|
+
expect(proxy_file).to have_received(:write).
|
32
|
+
with(/.*listen 123.123.123.135:80.*/)
|
43
33
|
end
|
44
34
|
|
45
35
|
it 'sets http upstream name in proxy pass section' do
|
46
|
-
expect(proxy_file).to have_received(:write).
|
36
|
+
expect(proxy_file).to have_received(:write).
|
37
|
+
with(/.*proxy_pass http:\/\/subdomain_http;.*/)
|
47
38
|
end
|
48
39
|
|
49
40
|
it 'has http upstream section with 2 upstream servers' do
|
50
|
-
expect(proxy_file).to have_received(:write).
|
41
|
+
expect(proxy_file).to have_received(:write).
|
42
|
+
with(/.*upstream subdomain_http {\n\s*server 10.100.10.112:80;\n\s*server 10.100.10.113:80;\n\s*}.*/)
|
51
43
|
end
|
52
44
|
|
53
45
|
it 'sets subdomain.my.server.pl server name' do
|
54
|
-
expect(proxy_file).to have_received(:write).
|
46
|
+
expect(proxy_file).to have_received(:write).
|
47
|
+
with(/.*subdomain\.my\.server\.pl;.*/)
|
55
48
|
end
|
56
49
|
|
57
50
|
it 'restarts nginx' do
|
@@ -61,40 +54,63 @@ describe Redirus::Worker::AddProxy do
|
|
61
54
|
|
62
55
|
context 'when https redirection is required' do
|
63
56
|
before do
|
64
|
-
allow(File).to receive(:open).
|
57
|
+
allow(File).to receive(:open).
|
58
|
+
with('configs_base_path/subdomain_https', 'w').
|
59
|
+
and_yield(proxy_file)
|
65
60
|
allow(proxy_file).to receive(:write)
|
61
|
+
|
66
62
|
subject.perform('subdomain', ['10.100.10.112:80'], :https)
|
67
63
|
end
|
68
64
|
|
69
65
|
it 'sets https listen section' do
|
70
|
-
expect(proxy_file).to have_received(:write).
|
66
|
+
expect(proxy_file).to have_received(:write).
|
67
|
+
with(/.*listen 123.123.123.135:443 ssl;.*/)
|
71
68
|
end
|
72
69
|
|
73
70
|
it 'sets https upstream name in proxy pass section' do
|
74
|
-
expect(proxy_file).to have_received(:write).
|
71
|
+
expect(proxy_file).to have_received(:write).
|
72
|
+
with(/.*proxy_pass http:\/\/subdomain_https;.*/)
|
75
73
|
end
|
76
74
|
|
77
75
|
it 'has https upstream section with upstream server' do
|
78
|
-
expect(proxy_file).to have_received(:write).
|
76
|
+
expect(proxy_file).to have_received(:write).
|
77
|
+
with(/.*upstream subdomain_https {\n\s*server 10.100.10.112:80;\n\s*}.*/)
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
context 'when redirection with properties is required' do
|
83
82
|
before do
|
84
|
-
allow(File).to receive(:open).
|
83
|
+
allow(File).to receive(:open).
|
84
|
+
with('configs_base_path/subdomain_http', 'w').
|
85
|
+
and_yield(proxy_file)
|
85
86
|
allow(proxy_file).to receive(:write)
|
86
87
|
end
|
87
88
|
|
88
89
|
it 'writes static properties into location section' do
|
89
|
-
expect(proxy_file).to receive(:write).
|
90
|
+
expect(proxy_file).to receive(:write).
|
91
|
+
with(/location \/ {\s*.*\s*proxy_send_timeout 600;\s*proxy_read_timeout 600;\s*}/)
|
90
92
|
|
91
|
-
subject.perform('subdomain', ['10.100.10.112:80'], :http,
|
93
|
+
subject.perform('subdomain', ['10.100.10.112:80'], :http,
|
94
|
+
['proxy_send_timeout 600', 'proxy_read_timeout 600'])
|
92
95
|
end
|
93
96
|
|
94
97
|
it 'discard not allowed properties' do
|
95
98
|
expect(proxy_file).to_not receive(:write).with(/not allowed property/)
|
96
99
|
|
97
|
-
subject.perform('subdomain', ['10.100.10.112:80'], :http,
|
100
|
+
subject.perform('subdomain', ['10.100.10.112:80'], :http,
|
101
|
+
['not allowed property'])
|
98
102
|
end
|
99
103
|
end
|
104
|
+
|
105
|
+
it 'parse specific options' do
|
106
|
+
allow(File).to receive(:open).
|
107
|
+
with('configs_base_path/options_http', 'w').
|
108
|
+
and_yield(proxy_file)
|
109
|
+
|
110
|
+
expect(proxy_file).to receive(:write).
|
111
|
+
with(/upstream options_http {\n\s*ip_hash;/)
|
112
|
+
|
113
|
+
subject.perform('options', ['10.100.10.112:80'], :http, [],
|
114
|
+
load_balancing: :ip_hash)
|
115
|
+
end
|
100
116
|
end
|
data/spec/resources/config.yml
CHANGED
@@ -6,24 +6,8 @@ namespace: configfile-redirus
|
|
6
6
|
nginx:
|
7
7
|
pid: configfile-nginx.pid
|
8
8
|
configs_path: configfile-sites-enabled
|
9
|
-
http_template:
|
10
|
-
https_template:
|
11
|
-
listen *:8443 ssl;
|
12
|
-
ssl_certificate /usr/share/ssl/certs/localhost/host.cert;
|
13
|
-
ssl_certificate_key /usr/share/ssl/certs/localhost/host.key;
|
14
|
-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
15
|
-
config_template: |
|
16
|
-
## configfile
|
17
|
-
#{upstream}
|
18
|
-
server {
|
19
|
-
#{listen}
|
20
|
-
server_name #{name}.localhost;
|
21
|
-
server_tokens off;
|
22
|
-
location / {
|
23
|
-
proxy_pass http://#{upstream_name};
|
24
|
-
#{properties}
|
25
|
-
}
|
26
|
-
}
|
9
|
+
http_template: /path/to/http/tmpl
|
10
|
+
https_template: /path/to/https/tmpl
|
27
11
|
allowed_properties:
|
28
12
|
- proxy_send_timeout \d
|
29
|
-
- proxy_read_timeout \d
|
13
|
+
- proxy_read_timeout \d
|
@@ -0,0 +1,19 @@
|
|
1
|
+
upstream <%= @name %>_http {
|
2
|
+
<% if @options[:load_balancing] == :ip_hash -%>
|
3
|
+
ip_hash;
|
4
|
+
<% end -%>
|
5
|
+
<% for worker in @workers -%>
|
6
|
+
server <%= worker %>;
|
7
|
+
<% end -%>
|
8
|
+
}
|
9
|
+
|
10
|
+
server {
|
11
|
+
listen 123.123.123.135:80;
|
12
|
+
server_name <%= @name %>.my.server.pl;
|
13
|
+
location / {
|
14
|
+
proxy_pass http://<%= @name %>_http;
|
15
|
+
<% for property in @location_properties -%>
|
16
|
+
<%= property %>;
|
17
|
+
<% end -%>
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
upstream <%= @name %>_https {
|
2
|
+
<% for worker in @workers -%>
|
3
|
+
server <%= worker %>;
|
4
|
+
<% end -%>
|
5
|
+
}
|
6
|
+
|
7
|
+
server {
|
8
|
+
listen 123.123.123.135:443 ssl;
|
9
|
+
server_name <%= @name %>.my.server.pl;
|
10
|
+
|
11
|
+
ssl_certificate /path/to/cert/dir/server.crt;
|
12
|
+
ssl_certificate_key /path/to/cert/dir/server.key;
|
13
|
+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
14
|
+
|
15
|
+
location / {
|
16
|
+
proxy_pass http://<%= @name %>_https;
|
17
|
+
<% for property in @location_properties -%>
|
18
|
+
<%= property %>;
|
19
|
+
<% end -%>
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
queues:
|
2
|
+
<% for queue in @options[:queues] -%>
|
3
|
+
- <%= queue %>
|
4
|
+
<% end -%>
|
5
|
+
|
6
|
+
redis_url: <%= @options[:redis] %>
|
7
|
+
namespace: redirus
|
8
|
+
|
9
|
+
nginx:
|
10
|
+
configs_path: <%= @options[:configs_dir] %>
|
11
|
+
pid: <%= @options[:pid] %>
|
12
|
+
http_template: <%= @options[:http_template] %>
|
13
|
+
https_template: <%= @options[:https_template] %>
|
14
|
+
allowed_properties:
|
15
|
+
- proxy_sent_timeout \d
|
16
|
+
- proxy_read_timeout \d
|
@@ -0,0 +1,17 @@
|
|
1
|
+
upstream <%%= @name %>_http {
|
2
|
+
<%% for worker in @workers -%>
|
3
|
+
server <%%= worker %>;
|
4
|
+
<%% end -%>
|
5
|
+
}
|
6
|
+
|
7
|
+
server {
|
8
|
+
listen <%= @options[:ip] %>:80;
|
9
|
+
server_name <%%= @name %>.<%= @options[:server_name] %>;
|
10
|
+
|
11
|
+
location / {
|
12
|
+
proxy_pass http://<%%= @name %>_http;
|
13
|
+
<%% for property in @location_properties -%>
|
14
|
+
<%%= property %>;
|
15
|
+
<%% end -%>
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
upstream <%%= @name %>_https {
|
2
|
+
<%% for worker in @workers -%>
|
3
|
+
server <%%= worker %>;
|
4
|
+
<%% end -%>
|
5
|
+
}
|
6
|
+
|
7
|
+
server {
|
8
|
+
listen <%= @options[:ip] %>:443 ssl;
|
9
|
+
server_name <%%= @name %>.<%= @options[:server_name] %>;
|
10
|
+
|
11
|
+
ssl_certificate <%= @options[:ssl_cert] %>;
|
12
|
+
ssl_certificate_key <%= @options[:ssl_cert_key] %>;
|
13
|
+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
14
|
+
|
15
|
+
location / {
|
16
|
+
proxy_pass http://<%%= @name %>_https;
|
17
|
+
<%% for property in @location_properties -%>
|
18
|
+
<%%= property %>;
|
19
|
+
<%% end -%>
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
worker_processes 1;
|
2
|
+
|
3
|
+
pid <%= @options[:pid] %>;
|
4
|
+
|
5
|
+
events {
|
6
|
+
worker_connections 1024;
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
http {
|
11
|
+
include /etc/nginx/mime.types;
|
12
|
+
default_type application/octet-stream;
|
13
|
+
|
14
|
+
sendfile on;
|
15
|
+
keepalive_timeout 65;
|
16
|
+
|
17
|
+
types_hash_max_size 2048;
|
18
|
+
server_names_hash_bucket_size 128;
|
19
|
+
|
20
|
+
access_log <%= @options[:configs_dir] %>/access.log;
|
21
|
+
error_log <%= @options[:configs_dir] %>/error.log;
|
22
|
+
|
23
|
+
include <%= @options[:configs_dir] %>/*;
|
24
|
+
}
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Kasztelnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.2'
|
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: '
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10'
|
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
|
-
version: '
|
54
|
+
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.3'
|
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
|
-
version: '
|
68
|
+
version: '4.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda-matchers
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec-sidekiq
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '2.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '2.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: coveralls
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Redirus
|
@@ -114,14 +114,15 @@ email:
|
|
114
114
|
executables:
|
115
115
|
- redirus
|
116
116
|
- redirus-client
|
117
|
+
- redirus-init
|
117
118
|
extensions: []
|
118
119
|
extra_rdoc_files: []
|
119
120
|
files:
|
120
|
-
- .gitignore
|
121
|
-
- .hound.yml
|
122
|
-
- .rspec
|
123
|
-
- .ruby-version
|
124
|
-
- .travis.yml
|
121
|
+
- ".gitignore"
|
122
|
+
- ".hound.yml"
|
123
|
+
- ".rspec"
|
124
|
+
- ".ruby-version"
|
125
|
+
- ".travis.yml"
|
125
126
|
- CHANGELOG
|
126
127
|
- Gemfile
|
127
128
|
- Gemfile.lock
|
@@ -131,12 +132,15 @@ files:
|
|
131
132
|
- Rakefile
|
132
133
|
- bin/redirus
|
133
134
|
- bin/redirus-client
|
134
|
-
-
|
135
|
+
- bin/redirus-init
|
135
136
|
- lib/redirus.rb
|
136
137
|
- lib/redirus/cli.rb
|
138
|
+
- lib/redirus/cli/client.rb
|
139
|
+
- lib/redirus/cli/init.rb
|
140
|
+
- lib/redirus/cli/server.rb
|
137
141
|
- lib/redirus/config.rb
|
138
142
|
- lib/redirus/proxy.rb
|
139
|
-
- lib/redirus/
|
143
|
+
- lib/redirus/utils.rb
|
140
144
|
- lib/redirus/version.rb
|
141
145
|
- lib/redirus/worker.rb
|
142
146
|
- lib/redirus/worker/add_proxy.rb
|
@@ -147,11 +151,18 @@ files:
|
|
147
151
|
- spec/redirus/worker/add_proxy_spec.rb
|
148
152
|
- spec/redirus/worker/rm_proxy_spec.rb
|
149
153
|
- spec/resources/config.yml
|
154
|
+
- spec/resources/http.erb.conf
|
155
|
+
- spec/resources/https.erb.conf
|
150
156
|
- spec/spec_helper.rb
|
151
157
|
- spec/support/matchers.rb
|
158
|
+
- spec/support/resources.rb
|
152
159
|
- support/upstart/redirus-nginx.conf
|
153
160
|
- support/upstart/redirus-sidekiq.conf
|
154
161
|
- support/upstart/redirus.conf
|
162
|
+
- templates/config.yml
|
163
|
+
- templates/http.conf.erb
|
164
|
+
- templates/https.conf.erb
|
165
|
+
- templates/nginx.conf
|
155
166
|
homepage: https://github.com/dice-cyfronet/redirus
|
156
167
|
licenses:
|
157
168
|
- MIT
|
@@ -162,17 +173,17 @@ require_paths:
|
|
162
173
|
- lib
|
163
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
164
175
|
requirements:
|
165
|
-
- -
|
176
|
+
- - ">="
|
166
177
|
- !ruby/object:Gem::Version
|
167
178
|
version: '0'
|
168
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
180
|
requirements:
|
170
|
-
- -
|
181
|
+
- - ">="
|
171
182
|
- !ruby/object:Gem::Version
|
172
183
|
version: '0'
|
173
184
|
requirements: []
|
174
185
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.2.2
|
176
187
|
signing_key:
|
177
188
|
specification_version: 4
|
178
189
|
summary: Redirus is responsible for managing http/https redirections
|
@@ -182,5 +193,8 @@ test_files:
|
|
182
193
|
- spec/redirus/worker/add_proxy_spec.rb
|
183
194
|
- spec/redirus/worker/rm_proxy_spec.rb
|
184
195
|
- spec/resources/config.yml
|
196
|
+
- spec/resources/http.erb.conf
|
197
|
+
- spec/resources/https.erb.conf
|
185
198
|
- spec/spec_helper.rb
|
186
199
|
- spec/support/matchers.rb
|
200
|
+
- spec/support/resources.rb
|
data/config.yml.example
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
queues:
|
2
|
-
- site_prefix
|
3
|
-
- second_site_prefix
|
4
|
-
|
5
|
-
redis_url: redis://localhost:6379
|
6
|
-
namespace: redirus
|
7
|
-
|
8
|
-
nginx:
|
9
|
-
configs_path: /path/to/dir/with/nginx/configs/
|
10
|
-
pid: /path/to/nginx.pid
|
11
|
-
http_template: |
|
12
|
-
listen *:80;
|
13
|
-
https_template: |
|
14
|
-
listen *:443 ssl;
|
15
|
-
ssl_certificate /path/to/cert/dir/server.crt;
|
16
|
-
ssl_certificate_key /path/to/cert/dir/server.key;
|
17
|
-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
18
|
-
config_template: |
|
19
|
-
#{upstream}
|
20
|
-
server {
|
21
|
-
#{listen}
|
22
|
-
server_name #{name}.my-domain.pl;
|
23
|
-
server_tokens off;
|
24
|
-
proxy_set_header X-Server-Address $scheme://#{name}.my-domain.pl;
|
25
|
-
proxy_set_header Host $http_host;
|
26
|
-
location / {
|
27
|
-
proxy_pass http://#{upstream_name};
|
28
|
-
#{properties}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
allowed_properties:
|
32
|
-
- proxy_sent_timeout \d
|
33
|
-
- proxy_read_timeout \d
|
data/lib/redirus/server_cli.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'singleton'
|
3
|
-
require 'sidekiq/cli'
|
4
|
-
|
5
|
-
Sidekiq.configure_server do |config|
|
6
|
-
config.redis = {
|
7
|
-
namespace: Redirus.config.namespace,
|
8
|
-
url: Redirus.config.redis_url
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
module Redirus
|
13
|
-
class ServerCLI
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
attr_reader :options
|
17
|
-
|
18
|
-
def parse(args = ARGV)
|
19
|
-
init_options(args)
|
20
|
-
validate!
|
21
|
-
end
|
22
|
-
|
23
|
-
def run
|
24
|
-
sidekiq_cli = Sidekiq::CLI.instance
|
25
|
-
args = queues + [
|
26
|
-
'-c', '1',
|
27
|
-
'-r', runner_path,
|
28
|
-
options[:config_path]
|
29
|
-
]
|
30
|
-
|
31
|
-
sidekiq_cli.parse(args)
|
32
|
-
sidekiq_cli.run
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def queues
|
38
|
-
Redirus.config.queues.inject([]) do |arr, q|
|
39
|
-
arr << '-q'
|
40
|
-
arr << q
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def runner_path
|
45
|
-
module_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
46
|
-
File.join(module_path, 'redirus.rb')
|
47
|
-
end
|
48
|
-
|
49
|
-
def init_options(args)
|
50
|
-
opts = parse_options(args)
|
51
|
-
opts[:config_path] ||= 'config.yml'
|
52
|
-
|
53
|
-
Redirus.config_path = opts[:config_path]
|
54
|
-
|
55
|
-
@options = opts
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse_options(args)
|
59
|
-
opts = {}
|
60
|
-
|
61
|
-
OptionParser.new do |o|
|
62
|
-
o.banner = 'Usage: redirus [options]'
|
63
|
-
|
64
|
-
o.on('-c',
|
65
|
-
'--configuration PATH',
|
66
|
-
'Yaml redirus configuration path') do |arg|
|
67
|
-
opts[:config_path] = arg
|
68
|
-
end
|
69
|
-
|
70
|
-
o.on_tail('-h', '--help', 'Show this message') do
|
71
|
-
puts opts
|
72
|
-
exit
|
73
|
-
end
|
74
|
-
end.parse!
|
75
|
-
|
76
|
-
opts
|
77
|
-
end
|
78
|
-
|
79
|
-
def validate!
|
80
|
-
unless File.exist?(options[:config_path])
|
81
|
-
puts "ERROR: Configuration file #{options[:config_path]} does not exist"
|
82
|
-
exit(1)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|