proxyneitor 0.0.6

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce963d1ada886f44df7d48bc3480edca051d05e0
4
+ data.tar.gz: 322c412c435071e9578bae8d6935deed0d79044c
5
+ SHA512:
6
+ metadata.gz: ef13c73f87feff719eacde461bfe724dbf904ecf6b6296cba8001259c5d151b39ea44881eac1cc4871d671aa82eb59cd27fd7f0ede23ca64afe28d508a17f67d
7
+ data.tar.gz: 2fcf74637f32b7b83f2d7220b1111398a2b3db1c9dbebc60298cb8f8c60e6c9c78c49efca0f6c53d63f87ee31a882101958b36f0ccdcb2625dbd3647106e0fe4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in proxyneitor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sergio Marin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Proxyneitor
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'proxyneitor'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install proxyneitor
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/proxyneitor/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Tags version, pushes to remote, and pushes gem'
4
+ task :release_to_github => :build do
5
+ sh "git tag v#{Proxyneitor::VERSION}"
6
+ sh "git push origin master"
7
+ sh "git push origin v#{Proxyneitor::VERSION}"
8
+ end
data/bin/proxyneitor ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "proxyneitor"
4
+
5
+ Proxyneitor::CLI.start(ARGV)
@@ -0,0 +1,50 @@
1
+ require "proxyneitor/version"
2
+ require 'proxyneitor/base'
3
+ require "thor"
4
+
5
+
6
+ module Proxyneitor
7
+
8
+ class CLI < Thor
9
+ desc "create APP_NAME PORT", "This create the new app in ~/Proxies/APP_NAME/ngnix.conf"
10
+ def create(app, port)
11
+ proxy = Proxyneitor::Base.new(app)
12
+ proxy.create(port)
13
+
14
+ say "All done!", :green
15
+
16
+ say "NOTE: you have to add #{app}.dev to your /etc/hosts file", :yellow
17
+ end
18
+
19
+ desc "delete APP_NAME", "This eliminate a app in ~/Proxies/APP_NAME/"
20
+ def delete(app)
21
+
22
+ answer = ask "Are you sure of removing app folder?", :limited_to => ['y', 'n']
23
+
24
+ if answer =~ /(y|Y)/
25
+ proxy = Proxyneitor::Base.new(app)
26
+ proxy.remove
27
+
28
+ say "All done!", :green
29
+ else
30
+ say "No deletes for today", :red
31
+ end
32
+ end
33
+
34
+ desc "install", "install proxynator from scrach"
35
+ option :reinstall, :type => :boolean
36
+ def install
37
+ proxy = Proxyneitor::Base.new
38
+ proxy.install(options[:reinstall])
39
+ say "All done!", :green
40
+ end
41
+
42
+ desc "list", "List of proxies inside proxyneitor"
43
+ def list
44
+ say "All applications: \n\n", :green
45
+ proxy = Proxyneitor::Base.new
46
+ proxy.list
47
+ say "\n\n"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ require "erb"
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'proxyneitor/builders'
5
+
6
+ module Proxyneitor
7
+
8
+ class Base
9
+ include Proxyneitor::Builders
10
+
11
+ def initialize(app = nil)
12
+ @root = File.join(ENV['HOME'],'Proxies')
13
+ @os = Gem::Platform.local.os
14
+ @app = app
15
+ end
16
+
17
+ end
18
+
19
+
20
+ end
@@ -0,0 +1,124 @@
1
+ module Proxyneitor
2
+ module Builders
3
+ def create(port)
4
+ root = @root
5
+ app = @app
6
+
7
+ ## Create ~/Proxies/APP_NAME folder if dont exist
8
+ Dir.mkdir(app_dir) unless File.directory?(app_dir)
9
+
10
+ ssl = ssl_folder
11
+ use_ssl = use_ssl?
12
+ # write app/nginx.conf
13
+ puts "Building nginx conf for #{app_dir}"
14
+
15
+ render_template('nginx.conf.erb', app_file_url('nginx.conf'), false) do |file, template|
16
+ file.write ERB.new(template).result(binding)
17
+ end
18
+
19
+ restart_nginx
20
+
21
+ end
22
+
23
+ def remove
24
+ app = @app
25
+ root = @root
26
+ directory = app_dir
27
+
28
+ remove_folder directory
29
+ restart_nginx
30
+ end
31
+
32
+ def install(force=false)
33
+ root = @root
34
+ os = @os
35
+
36
+ puts "Instaling nginx"
37
+ nginx_folder = load_nginx_folder
38
+ puts "Instalation force" if force == true
39
+
40
+ conf_file = File.join(nginx_folder, 'nginx.conf')
41
+ render_template('base_nginx.conf.erb', conf_file, !force) do |file, template|
42
+ puts "Loading new nginx.conf file"
43
+ file.write(ERB.new(template).result(binding))
44
+ end
45
+
46
+ puts "This configuration asume that you have this settings in #{nginx_folder}:"
47
+ puts " include /etc/nginx/conf.d/*.conf;"
48
+ puts " include /etc/nginx/sites-enabled/*;"
49
+
50
+ puts "Setting site-enabled folder and default"
51
+ sites_enabled = File.join(nginx_folder, 'sites-enabled')
52
+ Dir.mkdir(sites_enabled) unless File.directory?(sites_enabled)
53
+
54
+ render_template('default', File.join(sites_enabled, 'default'), !force) do |file, template|
55
+ file.write(template)
56
+ end
57
+
58
+ puts "Setting conf.d folder and proxyneitor"
59
+ conf_d = File.join(nginx_folder, 'conf.d')
60
+ Dir.mkdir(conf_d) unless File.directory?(conf_d)
61
+
62
+ render_template('proxyneitor_site', File.join(conf_d, 'proxyneitor.conf'), !force) do |file, template|
63
+ file.write ERB.new(template).result(binding)
64
+ end
65
+
66
+ restart_nginx
67
+ end
68
+
69
+ def app_dir
70
+ File.join(@root, @app)
71
+ end
72
+
73
+ def ssl_folder
74
+ @ssl ||= File.exists?(File.join(@root, @app, 'ssl')) ? File.join(@root, @app, 'ssl') : File.join(@root, @app, 'tls')
75
+ end
76
+
77
+ def use_ssl?
78
+ @user_ssl ||= File.exists?(File.join(@ssl, 'server.crt')) && File.exists?(File.join(@ssl, 'server.key'))
79
+ end
80
+
81
+ def app_file_url(file)
82
+ File.join(app_dir, file)
83
+ end
84
+
85
+ def render_template(template_url, target , optional = true, &block)
86
+ unless File.exists?(target) && optional == true
87
+
88
+ puts "Rendering #{target}"
89
+ template = File.open(File.join(Pathname.new(__FILE__).dirname, 'templates', template_url), 'rb').read
90
+
91
+ File.open(target, 'w') do |file|
92
+ block.call(file, template)
93
+ end
94
+ end
95
+ end
96
+
97
+ def restart_nginx
98
+ puts "Restarting nginx"
99
+ system('sudo nginx -s reload')
100
+ end
101
+
102
+ def remove_folder(directory)
103
+ puts "Removing app from #{app_dir}"
104
+ FileUtils.rm_rf(directory)
105
+ end
106
+
107
+ def load_nginx_folder
108
+ if @os == 'darwin'
109
+ system('brew install nginx')
110
+ nginx_folder = '/usr/local/etc/nginx/'
111
+ else
112
+ system('sudo apt-get install nginx')
113
+ nginx_folder = '/etc/nginx/'
114
+ end
115
+ end
116
+
117
+ def list
118
+ Dir.glob(File.join(@root, '*')).each { |f| puts f.split('/')[-1] }
119
+ end
120
+
121
+
122
+ # module_function :create, :install, :remove
123
+ end
124
+ end
@@ -0,0 +1,48 @@
1
+ #user nobody;
2
+ worker_processes 1;
3
+
4
+ #error_log logs/error.log;
5
+ #error_log logs/error.log notice;
6
+ #error_log logs/error.log info;
7
+
8
+ #pid logs/nginx.pid;
9
+
10
+
11
+ events {
12
+ worker_connections 1024;
13
+ }
14
+
15
+
16
+ http {
17
+ sendfile on;
18
+ tcp_nopush on;
19
+ tcp_nodelay on;
20
+ keepalive_timeout 65;
21
+ types_hash_max_size 2048;
22
+ # server_tokens off;
23
+
24
+ server_names_hash_bucket_size 64;
25
+ # server_name_in_redirect off;
26
+
27
+ include <%= File.join(nginx_folder, 'mime.types') %>;
28
+ default_type application/octet-stream;
29
+
30
+ #access_log logs/access.log;
31
+ #error_log logs/error.log;
32
+
33
+ gzip on;
34
+ gzip_disable "msie6";
35
+
36
+ # gzip_vary on;
37
+ # gzip_proxied any;
38
+ # gzip_comp_level 6;
39
+ # gzip_buffers 16 8k;
40
+ # gzip_http_version 1.1;
41
+ # gzip_types text/plain text/css application/json application/javascript text/xml applicati$
42
+
43
+ ##
44
+ # Virtual Host Configs
45
+ ##
46
+ include <%= File.join(nginx_folder, 'conf.d','*.conf') %>;
47
+ include <%= File.join(nginx_folder, 'sites-enabled','*') %>;
48
+ }
@@ -0,0 +1,70 @@
1
+ # Default server configuration
2
+ #
3
+ server {
4
+ listen 80 default_server;
5
+ listen [::]:80 default_server;
6
+
7
+ # SSL configuration
8
+ #
9
+ # listen 443 ssl default_server;
10
+ # listen [::]:443 ssl default_server;
11
+ #
12
+ # Self signed certs generated by the ssl-cert package
13
+ # Don't use them in a production server!
14
+ # include snippets/snakeoil.conf;
15
+ #
16
+ # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
17
+ # ssl_ciphers HIGH:!aNULL:!MD5;
18
+ # ssl_prefer_server_ciphers on;
19
+
20
+ root /var/www/html;
21
+
22
+ # Add index.php to the list if you are using PHP
23
+ index index.html index.htm index.nginx-debian.html;
24
+
25
+ server_name _;
26
+
27
+ location / {
28
+ # First attempt to serve request as file, then
29
+ # as directory, then fall back to displaying a 404.
30
+ try_files $uri $uri/ =404;
31
+ }
32
+
33
+ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
34
+ #
35
+ #location ~ \.php$ {
36
+ # include snippets/fastcgi-php.conf;
37
+ #
38
+ # # With php5-cgi alone:
39
+ # fastcgi_pass 127.0.0.1:9000;
40
+ # # With php5-fpm:
41
+ # fastcgi_pass unix:/var/run/php5-fpm.sock;
42
+ #}
43
+
44
+ # deny access to .htaccess files, if Apache's document root
45
+ # concurs with nginx's one
46
+ #
47
+ #location ~ /\.ht {
48
+ # deny all;
49
+ #}
50
+ }
51
+
52
+
53
+ # Virtual Host configuration for example.com
54
+ #
55
+ # You can move that to a different file under sites-available/ and symlink that
56
+ # to sites-enabled/ to enable it.
57
+ #
58
+ #server {
59
+ # listen 80;
60
+ # listen [::]:80;
61
+ #
62
+ # server_name example.com;
63
+ #
64
+ # root /var/www/example.com;
65
+ # index index.html;
66
+ #
67
+ # location / {
68
+ # try_files $uri $uri/ =404;
69
+ # }
70
+ #}
@@ -0,0 +1,43 @@
1
+ upstream <%= app %> { server 127.0.0.1:<%= port %>; }
2
+
3
+ <% if use_ssl %>
4
+ server {
5
+ listen [::]:80;
6
+ listen 80;
7
+ server_name <%= app %>.dev;
8
+ return 301 https://$host$request_uri;
9
+ }
10
+ <% end %>
11
+
12
+ server {
13
+ <% if use_ssl %>
14
+ listen [::]:443;
15
+ listen 443;
16
+ <% else %>
17
+ listen [::]:80;
18
+ listen 80;
19
+ <% end %>
20
+ server_name <%= app %>.dev;
21
+
22
+ <% if use_ssl %>
23
+ ssl on;
24
+ ssl_certificate <%= File.join(ssl, 'server.crt') %>;
25
+ ssl_certificate_key <%= File.join(ssl, 'server.key') %>;
26
+ ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!CAMELLIA;
27
+ ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
28
+ ssl_prefer_server_ciphers on;
29
+ <% end %>
30
+
31
+ location / {
32
+ proxy_pass http://<%= app %>;
33
+ proxy_http_version 1.1;
34
+ proxy_set_header Upgrade $http_upgrade;
35
+ proxy_set_header Connection "upgrade";
36
+ proxy_set_header Host $http_host;
37
+ proxy_set_header X-Forwarded-Proto $scheme;
38
+ proxy_set_header X-Forwarded-For $remote_addr;
39
+ proxy_set_header X-Forwarded-Port $server_port;
40
+ proxy_set_header X-Request-Start $msec;
41
+ }
42
+
43
+ }
@@ -0,0 +1 @@
1
+ include <%= File.join(root, '/**/nginx.conf') %>;
@@ -0,0 +1,3 @@
1
+ module Proxyneitor
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'proxyneitor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "proxyneitor"
8
+ spec.version = Proxyneitor::VERSION
9
+ spec.authors = ["Sergio Marin"]
10
+ spec.email = ["higher.vnf@gmail.com"]
11
+ spec.summary = %q{Build nginx.conf files for proxy your development environment}
12
+ spec.description = %q{Build nginx.conf files for proxy}
13
+ spec.homepage = "https://github.com/highercomve/proxyneitor"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['proxyneitor']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'thor', "~>0.19.1"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxyneitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Marin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Build nginx.conf files for proxy
56
+ email:
57
+ - higher.vnf@gmail.com
58
+ executables:
59
+ - proxyneitor
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/proxyneitor
69
+ - lib/proxyneitor.rb
70
+ - lib/proxyneitor/base.rb
71
+ - lib/proxyneitor/builders.rb
72
+ - lib/proxyneitor/templates/base_nginx.conf.erb
73
+ - lib/proxyneitor/templates/default
74
+ - lib/proxyneitor/templates/nginx.conf.erb
75
+ - lib/proxyneitor/templates/proxyneitor_site
76
+ - lib/proxyneitor/version.rb
77
+ - proxyneitor.gemspec
78
+ homepage: https://github.com/highercomve/proxyneitor
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Build nginx.conf files for proxy your development environment
102
+ test_files: []