rails_enterprise_setup 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38a7f8f7c050f535d8b8604f76f233ac584456e5
4
+ data.tar.gz: 50525de9b2522488d082066520b87f49e4f3996b
5
+ SHA512:
6
+ metadata.gz: 5bccebec5e7813e37b3e943391ea9df8a140cc0b8eaf0d4180036f317c2278c839d614ec4268c5d83488616aa113eb8e23f2a6d3570d222060e403cd0fd6b522
7
+ data.tar.gz: 901f3bb5b6d7a4c740d3b4838d997b1169b04a794e76f9e3592f0516274203f00c0d113b19572be477afdea9861628dc820c51b462bffe3ddb2e7f25c8bc58d6
data/.gitignore ADDED
@@ -0,0 +1,16 @@
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
15
+ *.swp
16
+ *.swo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_setup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mikhli, Uri
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,37 @@
1
+ # RailsSetup
2
+
3
+ This is a collection of generators to help setup rails development in an enterprise environment.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rails_setup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails_setup
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ rails generate setup_rails
25
+ ```
26
+ Follow directions.
27
+
28
+ Note: You can enter more then 1 letter.
29
+
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/rails_setup/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ Description:
2
+ generates an abstract Database connection class that acts as the interface to the given database
3
+
4
+ Example:
5
+ $ rails generate db_coonect <Name of Database>
6
+
7
+ This will create:
8
+ create app/models/<name_of_database>_db.rb
9
+ -----
10
+ class NameofdatabaseDb < ActiveRecord::Base
11
+ self.abstract_class = true
12
+ ...
13
+ -----
14
+
15
+ Inside of which will be the appropriate configuration for that database's ActiveRecord connection.
16
+ All rails models representing tables in that database must inherit from this abstract class.
17
+
18
+ -----
19
+ rails model: app/models/some_table.rb
20
+ -----
21
+ class SomeTable < NameofdatabaseDb
22
+ ...
23
+ -----
@@ -0,0 +1,63 @@
1
+ class DbConnectGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+
5
+ def add_to_database_to_yml
6
+ #insert #EOF so inject will work.
7
+ unless File.open('config/database.yml').read().include? "#EOF"
8
+ File.open('config/database.yml', 'a') do |f1|
9
+ f1 << "\n#EOF"
10
+ end
11
+ end
12
+ #if entry doesnt exist inject it. Force:false means that it doesnt repeat
13
+ unless File.open('config/database.yml').read().include? "#{file_name}:"
14
+ say("Please enter some details about the (#{file_name}) database in the development environment:")
15
+
16
+ adapter = ask("adapter?[mysql2]:")
17
+ adapter = "mysql2" if adapter.blank?
18
+
19
+ host = ask("host?[localhost]:")
20
+ host = "localhost" if host.blank?
21
+
22
+ port = ask("port?[3307]:")
23
+ port = 3307 if port.blank?
24
+
25
+ sslca = ask("path to database ssl certificate if any[]")
26
+ unless sslca.blank?
27
+ sslca = "sslca: #{sslca}"
28
+ end
29
+
30
+ inject_into_file 'config/database.yml',"
31
+ #{file_name}_default: &#{file_name}_default
32
+ adapter: #{adapter}
33
+ encoding: utf8
34
+ reconnect: false
35
+ pool: 5
36
+ #{sslca}
37
+
38
+ #{Rails.env}_#{file_name}:
39
+ <<: *#{file_name}_default
40
+ host: #{host}
41
+ port: #{port}
42
+ database: #{file_name}
43
+
44
+ " , before: /^\#EOF/, verbose: true, force: false
45
+ end
46
+
47
+ end
48
+
49
+ def create_abstract_db_model
50
+ create_file "app/models/#{file_name}_db.rb", <<-FILE
51
+ class #{class_name}Db < ActiveRecord::Base
52
+ self.abstract_class = true
53
+
54
+ config = ActiveRecord::Base.configurations["\#{Rails.env}_#{file_name}"]
55
+
56
+ establish_connection( config )
57
+
58
+ end
59
+ FILE
60
+ end
61
+
62
+
63
+ end
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Create a database credentials yml file that holds the path to the username and password files.
3
+ Create an initializer that adds the credentilas to ActiveRecord.
4
+ Example:
5
+ rails generate db_credentials database_name
6
+
7
+ This will create:
8
+ If they dont exist:
9
+ config/initializers/database_credentials.rb
10
+ config/database_credentials.yml
11
+
12
+ Otherwise for:
13
+ config/database_credentials.yml
14
+ It will insert the entry for the named database, if one doesnt already exist.
@@ -0,0 +1,47 @@
1
+ class DbCredentialsGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ def create_database_credentials
4
+ unless File.exists?('config/database_credentials.yml')
5
+ #file doesnt exist... create it
6
+ create_file "config/database_credentials.yml", <<-FILE
7
+ #Manage DB credentials
8
+ #The section below is appropriate for the #{file_name} database.
9
+ #Any additions made by hand to this file should be in the following format:
10
+ #environment:
11
+ # db_name:
12
+ # home_path: <path to home dir>
13
+ # username: <path to username file>/environment_dbname_username.txt
14
+ # password: <path to password file>/environment_dbname_password.txt
15
+ # other_db_name:
16
+ # home_path: ...
17
+ # username: ...
18
+ # password: ...
19
+ #
20
+ #{Rails.env}:
21
+ #{file_name}:
22
+ home_path: "#{Dir.home}"
23
+ username: "config/passwords/#{Rails.env}_#{file_name}_username.txt"
24
+ password: "config/passwords/#{Rails.env}_#{file_name}_password.txt"
25
+
26
+ FILE
27
+ else
28
+ unless File.open('config/database_credentials.yml').read().include? "#{file_name}:"
29
+ inject_into_file 'config/database_credentials.yml',"
30
+ #{file_name}:
31
+ home_path: \"#{Dir.home}\"
32
+ username: \"config/passwords/#{Rails.env}_#{file_name}_username.txt\"
33
+ password: \"config/passwords/#{Rails.env}_#{file_name}_password.txt\"
34
+
35
+ ", after: /#{Rails.env}:/, verbose: true, force: false
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ def load_credentials
42
+ unless File.exists?('config/initializers/database_credentials.rb')
43
+ copy_file("database_credentials.rb",'config/initializers/database_credentials.rb')
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ Rails.application.config.after_initialize do
3
+ ActiveSupport.on_load(:active_record) do
4
+ database_credentials = YAML::load(File.open('config/database_credentials.yml'))
5
+ database_credentials[Rails.env].each do |db, credentials|
6
+
7
+ #read credentials file for the location of the password files and then insert their contents
8
+ #into credentials hash
9
+ if ActiveRecord::Base.configurations["#{Rails.env}_#{db}"].present?
10
+ user_path = credentials["home_path"] + credentials["username"]
11
+ pswd_path = credentials["home_path"] + credentials["password"]
12
+
13
+ credentials["username"] = File.read(user_path).strip if File.exists?(user_path)
14
+ credentials["password"] = File.read(pswd_path).strip if File.exists?(pswd_path)
15
+
16
+ #Finally, add credentials to ActiveRecord
17
+ #if password file doesnt exist, keep the path to it as the password. This will aid debugging
18
+ ActiveRecord::Base.configurations["#{Rails.env}_#{db}"].merge!(credentials)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ Description:
2
+ This generator will do a full rails setup.
3
+ Generators invoked:
4
+ * db_connect
5
+ * db_credentials
6
+ * ssl_mode generators
7
+
8
+ You will have the option of choosing all or any of the setups.
9
+
10
+ Example:
11
+ rails generate setup_rails
12
+
13
+ you will be asked if you want all generators to run or specific generators to run.
14
+
@@ -0,0 +1,40 @@
1
+ class SetupRailsGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def call_generators
5
+
6
+ say("
7
+ All Generators[Aa]:
8
+ * db_connect
9
+ * db_credentials
10
+ * ssl_mode
11
+
12
+ db_connect[Cc]:
13
+ db_credentials[Rr]:
14
+ ssl_mode[Ss]:
15
+
16
+ Hitting enter without an entry will NOT run any generators
17
+ ")
18
+ choice = ask("What setup would you like to run. (Default: none)[AaCcRsSs]:")
19
+
20
+ if choice =~ /[Aa]/ || choice =~ /[Cc]/
21
+ db_name = ask("db_connect -- What is the database name?:")
22
+ unless db_name.blank?
23
+ generate "db_connect", db_name
24
+ end
25
+ end
26
+
27
+ if choice =~ /[Aa]/ || choice =~ /[Rr]/
28
+ db_name = ask("db_credentials -- What is the database name?:")
29
+ unless db_name.blank?
30
+ generate "db_credentials", db_name
31
+ end
32
+ end
33
+
34
+ if choice =~ /[Aa]/ || choice =~ /[Ss]/
35
+ generate "ssl_mode"
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Setup Rails to run SSL mode in development. This will use port 3001 when running in ssl mode.
3
+
4
+ Example:
5
+ rails generate ssl_setup
6
+
7
+ This will:
8
+ * insert the config.force_ssl = true line into applicaton.rb
9
+ * insert code for starting rails development in SSL mode into bin/rails.
10
+ * create a certs/ directory that holds the self signed certs needed to run in ssl mode. You will need to create your own self signed certifications. Google "self signed certificate in rails".
11
+
12
+ Run Time Invokation:
13
+ * None SSL mode: $> rails s #note: this is the standard invokation.
14
+ * SSL mode: $> SSL=true rails s
15
+
@@ -0,0 +1,29 @@
1
+ class SslModeGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def ssl_config
5
+ # set application.rb config.
6
+ environment 'config.force_ssl = true if ENV[\'SSL\'] == true'
7
+ end
8
+
9
+ def create_local_certs
10
+ unless File.exists?('certs/server.key')
11
+ say("\nYou need to have a 'certs/' directory where your self signed certificates will be stored. It will be populated with the correct file names, but these files will be empty. You will still need to generate your own:")
12
+ create_certs_dir = ask("Would you like to create certs/ directory?[y/N]:")
13
+ if create_certs_dir =~ /[Yy]/
14
+ run "cp -rf #{Gem.loaded_specs['rails_setup'].full_gem_path}/lib/generators/ssl_mode/templates/certs certs"
15
+ end
16
+ end
17
+ end
18
+
19
+ def set_ssl_rails
20
+ #add the contents of sslrails.rb file into bin/rails
21
+
22
+ sentinal = /require\s\'rails\/commands\'/i
23
+
24
+ data = File.read(Gem.loaded_specs['rails_setup'].full_gem_path + "/lib/generators/ssl_mode/templates/sslrails.rb")
25
+
26
+ inject_into_file 'bin/rails', "\n#{data}\n",before: sentinal, verbose: true, force: false
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ Create your OWN Certificate
3
+ -----END CERTIFICATE-----
@@ -0,0 +1,3 @@
1
+ -----BEGIN CERTIFICATE REQUEST-----
2
+ Create your OWN Certificate
3
+ -----END CERTIFICATE REQUEST-----
@@ -0,0 +1,3 @@
1
+ -----BEGIN PRIVATE KEY-----
2
+ Create your own Certificate
3
+ -----END PRIVATE KEY-----
@@ -0,0 +1,3 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ Create your own Certificate
3
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,29 @@
1
+ if ENV['RAILS_ENV'] == "development" || ENV['RAILS_ENV'].class == NilClass
2
+ require 'rails/commands/server'
3
+ require 'rack'
4
+ require 'webrick'
5
+ require 'webrick/https'
6
+ if ENV['SSL'] == "true"
7
+ module Rails
8
+ class Server < ::Rack::Server
9
+ def default_options
10
+ super.merge({
11
+ :Port => 3001,
12
+ :environment => (ENV['RAILS_ENV'] || "development").dup,
13
+ :daemonize => false,
14
+ :debugger => false,
15
+ :pid => File.expand_path("tmp/pids/server.pid"),
16
+ :config => File.expand_path("config.ru"),
17
+ :SSLEnable => true,
18
+ :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
19
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(
20
+ File.open("certs/server.key").read),
21
+ :SSLCertificate => OpenSSL::X509::Certificate.new(
22
+ File.open("certs/server.crt").read),
23
+ :SSLCertName => [["CN", "localhost.ssl"]],
24
+ })
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module RailsSetup
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "rails_setup/version"
2
+
3
+ module RailsSetup
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_setup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_enterprise_setup"
8
+ spec.version = RailsSetup::VERSION
9
+ spec.authors = ["Mikhli, Uri"]
10
+ spec.email = ["urimikhli@gmail.com"]
11
+ spec.summary = %q{Generators for setting up common enterprise development needs for rails}
12
+ spec.description = %q{Topics covered: \n Multiple DBs \n Database credential managment \n SSL in development \n Session Managment Via 3rd Party authentication service.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib","lib/generators"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_enterprise_setup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Mikhli, Uri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: 'Topics covered: \n Multiple DBs \n Database credential managment \n
42
+ SSL in development \n Session Managment Via 3rd Party authentication service.'
43
+ email:
44
+ - urimikhli@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/generators/db_connect/USAGE
55
+ - lib/generators/db_connect/db_connect_generator.rb
56
+ - lib/generators/db_credentials/USAGE
57
+ - lib/generators/db_credentials/db_credentials_generator.rb
58
+ - lib/generators/db_credentials/templates/database_credentials.rb
59
+ - lib/generators/setup_rails/USAGE
60
+ - lib/generators/setup_rails/setup_rails_generator.rb
61
+ - lib/generators/ssl_mode/USAGE
62
+ - lib/generators/ssl_mode/ssl_mode_generator.rb
63
+ - lib/generators/ssl_mode/templates/certs/server.crt
64
+ - lib/generators/ssl_mode/templates/certs/server.csr
65
+ - lib/generators/ssl_mode/templates/certs/server.key
66
+ - lib/generators/ssl_mode/templates/certs/server.orig.key
67
+ - lib/generators/ssl_mode/templates/sslrails.rb
68
+ - lib/rails_setup.rb
69
+ - lib/rails_setup/version.rb
70
+ - rails_setup.gemspec
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ - lib/generators
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.14
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Generators for setting up common enterprise development needs for rails
96
+ test_files: []