Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added env.yml for sensitive information #1

Merged
merged 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions devOn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'net-ssh' , '~> 2.6.5'
spec.add_dependency "net-sftp", '~> 2.1.2'
spec.add_dependency 'awesome_print', '~> 1.6.1'
spec.add_dependency 'env', '~> 0.3.0'
spec.required_ruby_version = '>= 2.0.0'
end
1 change: 1 addition & 0 deletions lib/devOn.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "devOn/version"
require "awesome_print"
require "devOn/env_config"
require "devOn/command"
require "devOn/config"
require "devOn/template"
Expand Down
29 changes: 29 additions & 0 deletions lib/devOn/env_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module DevOn
require 'yaml'
require 'env'

class EnvConfig
def initialize(path)
@path = path
end

def load(root)
if @yml ||= load_yml
@yml.each { |key, value| set_value(key, value) }
@yml[root].each { |key, value| set_value(key, value) } if @yml[root]
end
end

private

def load_yml
yml_path = File.expand_path(@path)
return nil unless File.exists?(yml_path)
YAML.load_file(yml_path)
end

def set_value(key, value)
ENV[key.to_s] = value.to_s unless value.is_a?(Hash)
end
end
end
56 changes: 37 additions & 19 deletions lib/devOn/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
require 'awesome_print'

include Rake::DSL
require 'devOn'
ID_SCRIPTS = "scripts"
ID_CONFIGS = "configs"
ID_CONN = "connections"
ID_NONE = "No config"

namespace :scripts do
desc "Create a new script"
task :new do
puts "What is the script name?(ex: install_41) :"
puts "What is the script name?(ex: restart_tomcat) :"
name = STDIN.gets.chomp
template=%"
module #{name.capitalize}
Expand All @@ -20,32 +25,33 @@ module #{name.capitalize}
# Command.run_shell(\"ls -la /tmp\")
# Command.run_shell(\"rm -rf /tmp/fromFile\")
# Command.run_shell(\"ls -la /tmp\")
# Command.upload_file(\"<source>/example.erb.rb\", \"/home/vagrant/test.rb\")
# Command.upload_file(\"<source>/example.rb\", \"/home/vagrant/test.rb\")
# Command.upload_file(use_file($config, \"file.rb.erb\"), \"{$config.setting_from_config}/file.rb\")
#
# and provision the machine with:
# provision_on $config
end
"
create_structure("scripts",name, template)
create_structure(ID_SCRIPTS, name, template)
end

desc "List available scripts "
task :list do
list "scripts"
list ID_SCRIPTS
end

desc "Run script"
task :run do
require 'devOn'

script = interactive "scripts"
connection = interactive "connections"


script = interactive ID_SCRIPTS
connection = interactive ID_CONN

config = interactive ID_CONFIGS
# load env.yml configuration
DevOn::EnvConfig.new(File.expand_path(ID_CONN+'/env.yml')).load(ENV[ID_CONN])

require File.expand_path(connection)

config = interactive "configs"

$connection = DevOn::Config.send(ENV['connections'])
$connection = DevOn::Config.send(ENV[ID_CONN])

exit if not_continue?(
{
Expand All @@ -58,9 +64,9 @@ module #{name.capitalize}
:connfiguration => config
})

if ENV['configs']
if ENV[ID_CONFIGS] && ENV[ID_CONFIGS]!=ID_NONE
require File.expand_path(config)
$config = DevOn::Config.send(ENV['configs'])
$config = DevOn::Config.send(ENV[ID_CONFIGS])
else
$config = DevOn::Config.on "default" do
name "default_config"
Expand Down Expand Up @@ -90,34 +96,46 @@ module #{name.capitalize}
end
end
"
create_structure("configs",name, template)
create_structure(ID_CONFIGS,name, template)
end

desc "List available configurations"
task :list do
list "configs"
list ID_CONFIGS
end
end

namespace :conn do
desc "List available connections"
task :list do
list "connections"
list ID_CONN
end
end

task :help do
`rake -T`
end

task :default => [:help]

private
require 'fileutils'

def list(folder)
_folder = Dir["#{folder}/*.rb"]
return [] if _folder.empty?
if folder.eql?ID_CONFIGS
_folder[0] = ID_NONE
else
return [] if _folder.empty?
end

DevOn::print "Available #{folder.capitalize}:"
DevOn::print _folder
_folder
end

def create_structure(on, name,template)
name = "test" if name.empty?
config = File.join(on, name + ".rb")
raise "File #{File.expand_path(config)} already exists!" if File.exist?(config)

Expand Down