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

Remove Hashie and Soloist::Remote #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
rvm:
- 2.2
- 2.1
- 2.0
- rbx-19mode
- rbx-18mode
- 2.3
- 2.4
- 2.5
- 2.6
install:
- gem install bundler
- bundle
Expand Down
21 changes: 2 additions & 19 deletions lib/soloist/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "librarian/chef/cli"
require "soloist/remote_config"
require "soloist/config"
require "soloist/spotlight"
require "awesome_print"
require "thor"

module Soloist
Expand All @@ -10,16 +9,12 @@ class CLI < Thor
default_task :chef

desc "chef", "Run chef-solo"
method_option :remote, :aliases => "-r", :desc => "Run chef-solo on user@host"
method_option :identity, :aliases => "-i", :desc => "The SSH identity file"
def chef
install_cookbooks if cheffile_exists?
soloist_config.run_chef
end

desc "run_recipe [cookbook::recipe, ...]", "Run individual recipes"
method_option :remote, :aliases => "-r", :desc => "Run recipes on user@host"
method_option :identity, :aliases => "-i", :desc => "The SSH identity file"
def run_recipe(*recipes)
soloist_config.royal_crown.recipes = recipes
chef
Expand All @@ -40,11 +35,7 @@ def install_cookbooks
end

def soloist_config
@soloist_config ||= if options[:remote]
Soloist::RemoteConfig.from_file(rc_path, remote)
else
Soloist::Config.from_file(rc_path)
end.tap do |config|
@soloist_config ||= Soloist::Config.from_file(rc_path).tap do |config|
config.merge!(rc_local) if rc_local_path
end
end
Expand All @@ -55,14 +46,6 @@ def rc_local
Soloist::Config.from_file(rc_local_path)
end

def remote
@remote ||= if options[:identity]
Soloist::Remote.from_uri(options[:remote], options[:identity])
else
Soloist::Remote.from_uri(options[:remote])
end
end

def cheffile_exists?
File.exists?(File.expand_path("../Cheffile", rc_path))
end
Expand Down
10 changes: 6 additions & 4 deletions lib/soloist/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ def merge!(other)

def compiled
@compiled ||= royal_crown.dup.tap do |working_royal_crown|
while working_royal_crown["env_variable_switches"]
working_royal_crown.delete("env_variable_switches").each do |variable, switch|
switch.each do |value, inner|
working_royal_crown.merge!(inner) if ENV[variable] == value
until working_royal_crown.env_variable_switches.empty?
switches = working_royal_crown.env_variable_switches
working_royal_crown.env_variable_switches = {}
switches.each do |variable, switch|
switch.select { |value, _| ENV[variable] == value }.each do |_, inner|
working_royal_crown.merge!(RoyalCrown.new(inner))
end
end
end
Expand Down
66 changes: 0 additions & 66 deletions lib/soloist/remote.rb

This file was deleted.

62 changes: 0 additions & 62 deletions lib/soloist/remote_config.rb

This file was deleted.

92 changes: 39 additions & 53 deletions lib/soloist/royal_crown.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
require "hashie"

module Soloist
class RoyalCrown < Hashie::Trash
property :path
property :recipes, :default => []
property :cookbook_paths, :default => []
property :node_attributes, :default => Hashie::Mash.new,
:transform_with => lambda { |v| Hashie::Mash.new(v) }
property :env_variable_switches, :default => Hashie::Mash.new,
:transform_with => lambda { |v| Hashie::Mash.new(v) }

def node_attributes=(hash)
self["node_attributes"] = Hashie::Mash.new(hash)
end
class RoyalCrown
attr_accessor :path, :node_attributes, :cookbook_paths, :recipes, :env_variable_switches

def merge!(other_royal_crown)
merge_recipes(other_royal_crown["recipes"])
merge_cookbook_paths(other_royal_crown["cookbook_paths"])
self.node_attributes.deep_merge!(other_royal_crown["node_attributes"])
self.env_variable_switches = other_royal_crown["env_variable_switches"]
self
def self.from_file(file_path)
new(read_config(file_path).merge("path" => file_path).reject { |_, value| value.nil? })
end

def merge_recipes(new_recipes = [])
merge_array_property("recipes", new_recipes)
def self.read_config(yaml_file)
content = File.read(yaml_file)
parsed_content = ERB.new(content).result
YAML.load(parsed_content) || {}
end

def merge_cookbook_paths(new_cookbook_paths = [])
merge_array_property("cookbook_paths", new_cookbook_paths)
def initialize(attributes = {})
@path = attributes.fetch(:path, attributes.fetch('path', nil))
@recipes = attributes.fetch(:recipes, attributes.fetch('recipes', []))
@cookbook_paths = attributes.fetch(:cookbook_paths, attributes.fetch('cookbook_paths', []))
@node_attributes = attributes.fetch(:node_attributes, attributes.fetch('node_attributes', {}))
@env_variable_switches = attributes.fetch(:env_variable_switches, attributes.fetch('env_variable_switches', {}))
end

def env_variable_switches=(hash)
self["env_variable_switches"] ||= Hashie::Mash.new
self["env_variable_switches"].merge!(Hashie::Mash.new(hash))
def to_yaml
{
'recipes' => recipes.empty? ? nil : recipes,
'cookbook_paths' => cookbook_paths.empty? ? nil : cookbook_paths,
'node_attributes' => node_attributes.empty? ? nil : node_attributes,
'env_variable_switches' => env_variable_switches.empty? ? nil : env_variable_switches
}
end

def to_yaml
to_hash.tap do |hash|
hash.delete("path")
self.class.nilable_properties.each { |k| hash[k] = nil if hash[k].empty? }
end
def merge!(other_royal_crown)
@recipes = recipes.concat(other_royal_crown.recipes).uniq
@cookbook_paths = cookbook_paths.concat(other_royal_crown.cookbook_paths).uniq
@node_attributes = deep_merge(node_attributes, other_royal_crown.node_attributes)
@env_variable_switches = deep_merge(env_variable_switches, other_royal_crown.env_variable_switches)
end

def save
Expand All @@ -52,28 +46,20 @@ def reload
self.class.from_file(path)
end

def self.from_file(file_path)
new(read_config(file_path).merge("path" => file_path))
end

def self.read_config(yaml_file)
content = File.read(yaml_file)
YAML.load(ERB.new(content).result).tap do |hash|
nilable_properties.each do |key|
hash.delete(key) if hash[key].nil?
end if hash
end || {}
end

private
def self.nilable_properties
(properties - [:path]).map(&:to_s)
end

def merge_array_property(property_name, values)
self[property_name] ||= []
self[property_name] += values
self[property_name].uniq!
def deep_merge(first_hash, second_hash)
deep_merger = Proc.new do |key, first, second|
if first.is_a?(Hash) && second.is_a?(Hash)
first.merge(second, &deep_merger)
elsif first.is_a?(Array) && second.is_a?(Array)
first.concat(second)
elsif v2.nil?
v1
else
v2
end
end
first_hash.merge(second_hash, &deep_merger)
end
end
end
2 changes: 1 addition & 1 deletion lib/soloist/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Soloist
VERSION = "1.0.4"
VERSION = "2.0.0alpha"
end
7 changes: 2 additions & 5 deletions soloist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ Gem::Specification.new do |s|
# chef 12.9.x and chef-zero 4.6.x dropped support for Ruby 2.0.x, which is
# El Capitan's system ruby. Gem versions are being locked to allow soloist
# to run with system Ruby.
s.add_dependency "chef", "~> 12.8.1"
s.add_dependency "chef-zero", "~> 4.5.0"
s.add_dependency "chef", "~> 13.1"
s.add_dependency "chef-zero", "~> 13.1"

s.add_dependency "librarian-chef"
s.add_dependency "thor"
s.add_dependency "hashie", "~> 2.0"
s.add_dependency "net-ssh"
s.add_dependency "awesome_print"

s.add_development_dependency "rspec"
s.add_development_dependency "guard-rspec"
Expand Down
38 changes: 0 additions & 38 deletions spec/helpers/net_ssh_test_patch.rb

This file was deleted.

Loading