port_map 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +4 -4
- data/bin/create_port_map +4 -0
- data/bin/remove_port_map +4 -0
- data/lib/port_map/hosts.rb +1 -1
- data/lib/port_map/utilities.rb +9 -3
- data/lib/port_map/version.rb +1 -1
- data/pkg/port_map-0.1.0.gem +0 -0
- data/spec/port_map/utilities_spec.rb +29 -49
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0a71849c6e5d17a906c31dce8eb840887d6e1ff
|
4
|
+
data.tar.gz: 62feadd3c75d9d8c9dfbc07f0b80efd4f60cf47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad87c4e5279b4481874e1e8285f2292093811a050d0927a00a76e6c5b306b9b935eae20168985b77b124dca71fc1cb026291a80ec67acc228b2c84fa530c1519
|
7
|
+
data.tar.gz: b5e971e62d173e8d4cecf3b7cf14791d30fe40a3d34a38c1f780e37bf4d33928941b981b75642d1ea7b7adcec118808f8e462de57d1cca297ea05a0cd33accb7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -95,10 +95,10 @@ Installing this gem provides four executable commands:
|
|
95
95
|
### `port_map`
|
96
96
|
- `port_map <command>`
|
97
97
|
1. Adjusts/Adds a dynamic port number on command (assuming command takes `-p <number>` or `--port <number>`).
|
98
|
-
2. Executes `create_port_map <dynamic_port_number
|
99
|
-
1. Uses a `.port_map.conf` nginx server configuration (
|
100
|
-
2. Using a name specified in the `PORT_MAP_NAME` environment variable.
|
101
|
-
|
98
|
+
2. Executes `create_port_map <dynamic_port_number>`, which goes through the following in order until a name can be determined).
|
99
|
+
1. Uses a `.port_map.conf` nginx server configuration (which has a server name and `$PORT` placeholder present), this then becomes the nginx configuration.
|
100
|
+
2. Using a name specified in the `PORT_MAP_NAME` environment variable, this name is then used to generate a nginx configuration.
|
101
|
+
3. Using a name specified from the current directory, this name is then used to generate a nginx configuration.
|
102
102
|
3. Updates `/etc/hosts` with new entry `127.0.0.1 determined_name.dev #port_map`.
|
103
103
|
4. Reloads nginx -- `sudo nginx -s reload`.
|
104
104
|
5. Executes `<command>`.
|
data/bin/create_port_map
CHANGED
@@ -7,6 +7,10 @@ unless (1..65535).cover?(port.to_i)
|
|
7
7
|
raise 'a valid port number must be provided as the first argument'
|
8
8
|
end
|
9
9
|
|
10
|
+
if PortMap::Utilities.port_taken?(port.to_i)
|
11
|
+
raise 'port number is already taken'
|
12
|
+
end
|
13
|
+
|
10
14
|
server_conf = nil
|
11
15
|
if File.exist?(PortMap::NginxConf::PORT_MAP_CONF_FILENAME)
|
12
16
|
server_conf = PortMap::NginxConf.from_file(port, File.new(PortMap::NginxConf::PORT_MAP_CONF_FILENAME))
|
data/bin/remove_port_map
CHANGED
@@ -3,6 +3,10 @@ require 'port_map'
|
|
3
3
|
|
4
4
|
name = ARGV[0] || Dir.pwd.split('/').last
|
5
5
|
|
6
|
+
if File.exist?(PortMap::NginxConf::PORT_MAP_CONF_FILENAME)
|
7
|
+
name = PortMap::NginxConf.from_file('', File.new(PortMap::NginxConf::PORT_MAP_CONF_FILENAME)).name
|
8
|
+
end
|
9
|
+
|
6
10
|
port_map = PortMap::Mappings.all.detect do |element|
|
7
11
|
element[:name] == name
|
8
12
|
end
|
data/lib/port_map/hosts.rb
CHANGED
data/lib/port_map/utilities.rb
CHANGED
@@ -7,7 +7,6 @@ module PortMap
|
|
7
7
|
ZSH_CMD_STRING = "zsh -c 'source ~/.zshrc > /dev/null; PATH=%{path}; setopt aliases; eval %{cmd}'"
|
8
8
|
|
9
9
|
STARTING_PORT_NUMBER = 20000
|
10
|
-
PORT_NUMBER_INCREMENT = 100
|
11
10
|
|
12
11
|
def self.shell_cmd_wrapper(cmd)
|
13
12
|
case ENV.fetch('SHELL')
|
@@ -35,9 +34,16 @@ module PortMap
|
|
35
34
|
def self.next_empty_port
|
36
35
|
highest_port = PortMap::Mappings.all.map do |port_map|
|
37
36
|
port_map[:locations].detect { |location| location[:name] == '/' }[:proxy_pass].split(':').last.to_i
|
38
|
-
end.sort.reverse.first
|
37
|
+
end.sort.reverse.first || STARTING_PORT_NUMBER - 1
|
39
38
|
|
40
|
-
highest_port
|
39
|
+
highest_port += 1
|
40
|
+
highest_port += 1 while port_taken?(highest_port)
|
41
|
+
|
42
|
+
highest_port
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.port_taken?(port)
|
46
|
+
system("lsof -i:#{port}", out: '/dev/null')
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
data/lib/port_map/version.rb
CHANGED
data/pkg/port_map-0.1.0.gem
CHANGED
Binary file
|
@@ -70,57 +70,36 @@ RSpec.describe PortMap::Utilities do
|
|
70
70
|
it 'returns STARTING_PORT_NUMBER' do
|
71
71
|
expect(described_class.next_empty_port).to eq(described_class::STARTING_PORT_NUMBER)
|
72
72
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'one port mapping exist' do
|
76
|
-
context 'with one location' do
|
77
|
-
let(:previous_highest_port_number) { 30000 }
|
78
|
-
let(:port_mappings) do
|
79
|
-
[
|
80
|
-
{
|
81
|
-
name: 'admin',
|
82
|
-
nginx_conf: '/usr/local/etc/nginx/servers/admin.port_map.conf',
|
83
|
-
server_name: 'admin.dev',
|
84
|
-
locations: [
|
85
|
-
{
|
86
|
-
name: '/',
|
87
|
-
proxy_pass: "http://127.0.0.1:#{previous_highest_port_number}"
|
88
|
-
}
|
89
|
-
]
|
90
|
-
}
|
91
|
-
]
|
92
|
-
end
|
93
73
|
|
94
|
-
|
95
|
-
|
74
|
+
context 'next port taken by external process' do
|
75
|
+
it 'returns 1 port higher than the STARTING_PORT_NUMBER' do
|
76
|
+
allow(described_class).to receive(:port_taken?).and_return(true, false)
|
77
|
+
expect(described_class.next_empty_port).to eq(described_class::STARTING_PORT_NUMBER + 1)
|
96
78
|
end
|
97
79
|
end
|
80
|
+
end
|
98
81
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
]
|
117
|
-
}
|
118
|
-
]
|
119
|
-
end
|
82
|
+
context 'one port mapping exist' do
|
83
|
+
let(:previous_highest_port_number) { 30000 }
|
84
|
+
let(:port_mappings) do
|
85
|
+
[
|
86
|
+
{
|
87
|
+
name: 'admin',
|
88
|
+
nginx_conf: '/usr/local/etc/nginx/servers/admin.port_map.conf',
|
89
|
+
server_name: 'admin.dev',
|
90
|
+
locations: [
|
91
|
+
{
|
92
|
+
name: '/',
|
93
|
+
proxy_pass: "http://127.0.0.1:#{previous_highest_port_number}"
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}
|
97
|
+
]
|
98
|
+
end
|
120
99
|
|
121
|
-
|
122
|
-
|
123
|
-
|
100
|
+
it 'returns 1 port higher than the highest' do
|
101
|
+
allow(described_class).to receive(:port_taken?).and_return(false)
|
102
|
+
expect(described_class.next_empty_port).to eq(previous_highest_port_number + 1)
|
124
103
|
end
|
125
104
|
end
|
126
105
|
|
@@ -135,7 +114,7 @@ RSpec.describe PortMap::Utilities do
|
|
135
114
|
locations: [
|
136
115
|
{
|
137
116
|
name: '/',
|
138
|
-
proxy_pass:
|
117
|
+
proxy_pass: "http://127.0.0.1:#{previous_highest_port_number - 1}"
|
139
118
|
}
|
140
119
|
]
|
141
120
|
},
|
@@ -153,8 +132,9 @@ RSpec.describe PortMap::Utilities do
|
|
153
132
|
]
|
154
133
|
end
|
155
134
|
|
156
|
-
it 'returns
|
157
|
-
|
135
|
+
it 'returns 1 port higher than the highest' do
|
136
|
+
allow(described_class).to receive(:port_taken?).and_return(false)
|
137
|
+
expect(described_class.next_empty_port).to eq(previous_highest_port_number + 1)
|
158
138
|
end
|
159
139
|
end
|
160
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: port_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Jalbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|