lambom 0.1.1
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 +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/bin/lambom +52 -0
- data/lambom.gemspec +20 -0
- data/lib/lambom/api.rb +121 -0
- data/lib/lambom/attribute_mixin.rb +24 -0
- data/lib/lambom/config.rb +75 -0
- data/lib/lambom/config_static.rb +62 -0
- data/lib/lambom/converger.rb +95 -0
- data/lib/lambom/shell_mixin.rb +14 -0
- data/lib/lambom.rb +47 -0
- data/spec/api_client_spec.rb +27 -0
- data/spec/config_spec.rb +60 -0
- data/spec/converger_spec.rb +30 -0
- data/spec/private_key.pem +27 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/test_config.yml +4 -0
- data/spec/test_config_bad_options.yml +4 -0
- data/spec/test_config_bad_yaml.yml +4 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 144162d3f7b3636e039a8d09381ee380d484972f
|
4
|
+
data.tar.gz: 1d8b1ee42de69116792b4cc96c874c5ed8451e3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc7a6b4ab57fd0821abc439336e2015e7a709035d82bf3e08785888866da28a549e169cd675536896580232ddf7c773150edd2d81f51cc4ab91cb74523465bd8
|
7
|
+
data.tar.gz: b6fbfe89b8e83257f24fd2c39323a06594d940cee1351b62c07b97bf66280a2d5982b121da4e3b03db01715b8425da5a55c95a846cf484abcf99ef764e81700f
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.swp
|
data/.rspec
ADDED
data/bin/lambom
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'lambom'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
# -e environment
|
7
|
+
# -j json_file
|
8
|
+
# -s server
|
9
|
+
# -l loglevel
|
10
|
+
# -k private_key_file
|
11
|
+
options = {}
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: lambom [options]"
|
15
|
+
|
16
|
+
opts.on("-j", "--json [JSON FILE]",
|
17
|
+
"Run server configuration with json attributes file") do |j|
|
18
|
+
options[:json_file] = j
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-e", "--env [ENVIRONMENT]",
|
22
|
+
"Select environment") do |e|
|
23
|
+
options[:environment] = e
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-s", "--server [SERVER_UUID]",
|
27
|
+
"Set server to which get configuration from riyic api") do |s|
|
28
|
+
options[:server] = s
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-k", "--keyfile [PRIVATE KEYFILE]",
|
32
|
+
"PEM Private keyfile to sign api requests") do |k|
|
33
|
+
options[:private_key_file] = k
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-l","--loglevel [LOG_LEVEL]",
|
37
|
+
"Set loglevel") do |l|
|
38
|
+
options[:loglevel] = l
|
39
|
+
end
|
40
|
+
|
41
|
+
end.parse!
|
42
|
+
|
43
|
+
out = ''
|
44
|
+
begin
|
45
|
+
out = Lambom.run(options)
|
46
|
+
rescue Exception => e
|
47
|
+
puts "Error: #{e.message}"
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "Command executed successfully"
|
52
|
+
|
data/lambom.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'lambom'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.date = '2013-12-16'
|
5
|
+
s.summary = "Tool to apply riyic configurations"
|
6
|
+
s.description = "Riyic is a server configuration service based on chef (http://riyic.com). The lambom gem is a tool to apply, through chef-solo, your riyic configurations in your server"
|
7
|
+
s.authors = ["J. Gomez"]
|
8
|
+
s.email = 'alambike@gmail.com'
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.executables << 'lambom'
|
11
|
+
s.files = `git ls-files`.split($/)
|
12
|
+
s.license = 'Apache-2.0'
|
13
|
+
|
14
|
+
s.add_runtime_dependency "oj","~> 2.0"
|
15
|
+
s.add_runtime_dependency "mixlib-authentication","~> 1.3"
|
16
|
+
s.add_runtime_dependency "mixlib-shellout","~> 1.3"
|
17
|
+
|
18
|
+
s.homepage =
|
19
|
+
'https://github.com/RIYIC/lambom'
|
20
|
+
end
|
data/lib/lambom/api.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'time'
|
2
|
+
require "mixlib/authentication"
|
3
|
+
require "mixlib/authentication/signedheaderauth"
|
4
|
+
require 'digest/sha1'
|
5
|
+
require 'openssl'
|
6
|
+
require 'net/http'
|
7
|
+
|
8
|
+
module Lambom
|
9
|
+
class ApiClient
|
10
|
+
API_URL = {
|
11
|
+
:production => "http://riyic.com/api/v1",
|
12
|
+
:development => "http://10.0.3.1:3000/api/v1"
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(conf)
|
16
|
+
@server_id = conf.server or raise "Required parameter \"server\" not found"
|
17
|
+
@private_key_file = conf.private_key_file or raise "Required parameter \"private_key_file\" not found"
|
18
|
+
@env = conf.environment
|
19
|
+
|
20
|
+
@api_url = (@env == "production")?
|
21
|
+
API_URL[:production]:
|
22
|
+
API_URL[:development]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_server_config
|
26
|
+
get('servers',"#{@server_id}/generate_config");
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def get(controller, action='',params={})
|
33
|
+
uri = build_uri(controller,action)
|
34
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
35
|
+
req.body=generate_body_string(params)
|
36
|
+
send(uri,req)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def post(controller, action='',params={})
|
41
|
+
uri = build_uri(controller,action)
|
42
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
43
|
+
#req.set_form_data(params)
|
44
|
+
req.body=generate_body_string(params)
|
45
|
+
send(uri,req)
|
46
|
+
end
|
47
|
+
|
48
|
+
def send(uri,req)
|
49
|
+
|
50
|
+
## agregamos os headers da signature
|
51
|
+
headers = generate_headers(@server_id, @private_key_file, req)
|
52
|
+
puts headers.inspect if $debug
|
53
|
+
|
54
|
+
headers.each do |header,value|
|
55
|
+
req[header] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
#http.use_ssl = true
|
60
|
+
|
61
|
+
response = http.request(req)
|
62
|
+
puts response.body if $debug
|
63
|
+
|
64
|
+
if response.is_a?(Net::HTTPSuccess)
|
65
|
+
return response.body
|
66
|
+
else
|
67
|
+
puts "code:#{response.code}, message:#{response.message}" if $debug
|
68
|
+
raise "api error: #{response.body}"
|
69
|
+
end
|
70
|
+
|
71
|
+
#puts resp.inspect if @debug
|
72
|
+
#response = Oj.load(response.body)
|
73
|
+
|
74
|
+
#if response["status"] == "OK"
|
75
|
+
# return response
|
76
|
+
#else
|
77
|
+
# raise response.body
|
78
|
+
#end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def build_uri(controller, action='')
|
86
|
+
URI("#{@api_url}/#{controller}/#{action}")
|
87
|
+
end
|
88
|
+
|
89
|
+
def generate_body_string(h={})
|
90
|
+
r = ""
|
91
|
+
|
92
|
+
h.each do |k,v|
|
93
|
+
r << "&#{k}=#{v}"
|
94
|
+
end
|
95
|
+
|
96
|
+
r
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def generate_headers(server_id, private_key_file, request)
|
101
|
+
|
102
|
+
args = {
|
103
|
+
:body => request.body.to_s,
|
104
|
+
:user_id => server_id.to_s,
|
105
|
+
:http_method => request.method.to_s,
|
106
|
+
:timestamp => Time.now.iso8601,
|
107
|
+
#:file => MockFile.new,
|
108
|
+
:path => request.path.to_s,
|
109
|
+
:proto_version => 1.1
|
110
|
+
}
|
111
|
+
|
112
|
+
# cargamos a private key do ficheiro
|
113
|
+
key = IO::read(private_key_file)
|
114
|
+
private_key = OpenSSL::PKey::RSA.new(key)
|
115
|
+
|
116
|
+
Mixlib::Authentication::SignedHeaderAuth.signing_object(args).sign(private_key)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Riyic
|
2
|
+
module AttributeMixin
|
3
|
+
# si extendemos unha clase con este modulo os metodos fanse de clase
|
4
|
+
# si incluimos esta clase os metodos fanse de instancia
|
5
|
+
|
6
|
+
def attr_setter(*method_names)
|
7
|
+
method_names.each do |name|
|
8
|
+
send :define_method, name do |data|
|
9
|
+
instance_variable_set "@#{name}".to_sym, data
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def varargs_setter(*method_names)
|
15
|
+
|
16
|
+
method_names.each do |name|
|
17
|
+
send :define_method, name do |*data|
|
18
|
+
instance_variable_set "@#{name}".to_sym, data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Lambom
|
4
|
+
class Config
|
5
|
+
FILE = '/etc/riyic/lambom.conf'
|
6
|
+
|
7
|
+
|
8
|
+
attr_accessor :server, :private_key_file, :environment, :loglevel
|
9
|
+
attr_reader :logdir, :logfile
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@server = nil
|
13
|
+
@private_key_file = nil
|
14
|
+
@environment = 'production'
|
15
|
+
@loglevel = 'debug'
|
16
|
+
@logdir = '/var/log/riyic'
|
17
|
+
@logfile = "solo_#{Time.now.strftime("%F_%T")}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def load
|
21
|
+
# evitamos cascar si o ficheiro de configuracion non existe
|
22
|
+
return self unless File.exists?(FILE)
|
23
|
+
|
24
|
+
h = {}
|
25
|
+
begin
|
26
|
+
h = YAML.load(IO::read(FILE))
|
27
|
+
rescue Exception => e
|
28
|
+
e.to_s =~ /line (\d+) column/
|
29
|
+
raise "Error loading yaml config file #{FILE}, syntax error in line #{$1}"
|
30
|
+
end
|
31
|
+
|
32
|
+
puts h.inspect if $debug
|
33
|
+
|
34
|
+
h.each do |k,v|
|
35
|
+
if validate(k,v)
|
36
|
+
instance_variable_set "@#{k}".to_sym, v
|
37
|
+
else
|
38
|
+
raise "Invalid value '#{v}' to parameter '#{k}'"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
self
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def merge(options)
|
47
|
+
options.each do |k,v|
|
48
|
+
puts "mergeando #{k} con valor #{v} en config" if $debug
|
49
|
+
self.send("#{k}=",v) if validate(k,v)
|
50
|
+
#instance_variable_set "@#{k}".to_sym, v if validate(k,v)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate(parametro,valor)
|
55
|
+
case parametro.to_sym
|
56
|
+
when :server
|
57
|
+
# uuid
|
58
|
+
valor =~ /^[\d\w\-]{36}$/
|
59
|
+
when :private_key_file
|
60
|
+
#unix path
|
61
|
+
valor =~ /^[\w\s.\/\-_+%]+$/i
|
62
|
+
when :environment
|
63
|
+
#env de rails
|
64
|
+
["production","development","test"].include?(valor)
|
65
|
+
when :loglevel
|
66
|
+
#loglevel de chef
|
67
|
+
%w{debug info}.include?(valor)
|
68
|
+
else
|
69
|
+
false
|
70
|
+
#raise "Invalid parameter #{parametro}"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Lambom
|
5
|
+
class Config
|
6
|
+
FILE = '/etc/riyic/lambom.conf'
|
7
|
+
|
8
|
+
def self.load
|
9
|
+
config = ::OpenStruct.new
|
10
|
+
config.server = nil
|
11
|
+
config.private_key_file = nil
|
12
|
+
config.environment = 'production'
|
13
|
+
config.loglevel = 'debug'
|
14
|
+
|
15
|
+
# si non existe o ficheiro de configuracion devolvemos a configuracion inicializada
|
16
|
+
# pode que se complete por linea de comandos
|
17
|
+
return config unless File.exists?(FILE)
|
18
|
+
|
19
|
+
h = {}
|
20
|
+
begin
|
21
|
+
h = YAML.load(IO::read(FILE))
|
22
|
+
rescue Exception => e
|
23
|
+
e.to_s =~ /line (\d+) column/
|
24
|
+
raise "Error loading yaml config file #{FILE}, syntax error in line #{$1}"
|
25
|
+
end
|
26
|
+
|
27
|
+
puts h.inspect if $debug
|
28
|
+
|
29
|
+
h.each do |k,v|
|
30
|
+
if validate(k,v)
|
31
|
+
config.send("#{k}=", v)
|
32
|
+
else
|
33
|
+
raise "Invalid value '#{v}' to parameter '#{k}'"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
config
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def self.validate(parametro,valor)
|
43
|
+
case parametro
|
44
|
+
when "server"
|
45
|
+
# uuid
|
46
|
+
valor =~ /^[\d\w\-]{36}$/
|
47
|
+
when "private_key_file"
|
48
|
+
#unix path
|
49
|
+
valor =~ /^[\w\s.\/\-_+%]+$/i
|
50
|
+
when "environment"
|
51
|
+
#env de rails
|
52
|
+
["production","development","test"].include?(valor)
|
53
|
+
when "loglevel"
|
54
|
+
#loglevel de chef
|
55
|
+
%w{debug info}.include?(valor)
|
56
|
+
else
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Lambom
|
2
|
+
class Converger
|
3
|
+
include ShellMixin
|
4
|
+
|
5
|
+
COOKBOOKS_URL = 'http://www2.ruleyourcloud.com/cookbooks.tar.gz'
|
6
|
+
|
7
|
+
DEFAULT_CHEF_PATH = '/var/chef'
|
8
|
+
|
9
|
+
TEMP = "#{DEFAULT_CHEF_PATH}/cache"
|
10
|
+
|
11
|
+
ENV_VARS_DELETE = %w{
|
12
|
+
GEM_PATH
|
13
|
+
RUBY_VERSION
|
14
|
+
GEM_HOME
|
15
|
+
MY_RUBY_HOME
|
16
|
+
rvm_bin_path
|
17
|
+
rvm_path
|
18
|
+
rvm_gem_options
|
19
|
+
rvm_prefix
|
20
|
+
rvm_version
|
21
|
+
}
|
22
|
+
|
23
|
+
CHEF_CONF_FILE = '/etc/chef/solo.rb'
|
24
|
+
|
25
|
+
CHEF_CONF = {
|
26
|
+
development: '
|
27
|
+
cookbook_path ["/mnt/opscode/cookbooks", "/mnt/others/cookbooks", "/mnt/riyic/cookbooks"]
|
28
|
+
'
|
29
|
+
}
|
30
|
+
|
31
|
+
def initialize(conf, json)
|
32
|
+
@conf = conf
|
33
|
+
@attributes_json = json
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
attr_reader :conf,:attributes_json
|
38
|
+
|
39
|
+
def run
|
40
|
+
preparar_entorno
|
41
|
+
|
42
|
+
descargar_cookbooks
|
43
|
+
|
44
|
+
ejecutar_converger
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def ejecutar_converger
|
51
|
+
|
52
|
+
filename = "#{TEMP}/#{conf.server}.json"
|
53
|
+
file = File.new(filename,"w")
|
54
|
+
file.write(attributes_json)
|
55
|
+
file.close
|
56
|
+
|
57
|
+
run_cmd('/usr/bin/chef-solo',
|
58
|
+
'--log_level', conf.loglevel,
|
59
|
+
'--logfile', "#{conf.logdir}/#{conf.logfile}",
|
60
|
+
'-j', filename)
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def preparar_entorno
|
65
|
+
ENV_VARS_DELETE.each {|v| ENV.delete(v)}
|
66
|
+
ENV["PATH"] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
67
|
+
|
68
|
+
#creamos directorio de logs
|
69
|
+
FileUtils.mkdir_p(conf.logdir) unless Dir.exists?(conf.logdir)
|
70
|
+
File.chmod(0750, conf.logdir)
|
71
|
+
|
72
|
+
#creamos o directorio cache de chef
|
73
|
+
FileUtils.mkdir_p(TEMP) unless Dir.exists?(TEMP)
|
74
|
+
File.chmod(0750,TEMP)
|
75
|
+
|
76
|
+
# establecemos o archivo de configuracion de chef segun o entorno
|
77
|
+
switch_chef_conf(conf.environment)
|
78
|
+
end
|
79
|
+
|
80
|
+
def descargar_cookbooks
|
81
|
+
unless (conf.environment == 'development')
|
82
|
+
# aqui podemos meter unha ejecucion de berkshelf para descargar os cookbooks necesarios
|
83
|
+
run_cmd('curl','-o','/tmp/cookbooks.tar.gz', '-L',COOKBOOKS_URL)
|
84
|
+
FileUtils.mkdir_p(DEFAULT_CHEF_PATH) unless Dir.exists?(DEFAULT_CHEF_PATH)
|
85
|
+
run_cmd('tar','xzf','/tmp/cookbooks.tar.gz','--no-same-owner','-C', DEFAULT_CHEF_PATH);
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def switch_chef_conf(env)
|
90
|
+
if CHEF_CONF.has_key?(env)
|
91
|
+
IO.write(CHEF_CONF_FILE,CHEF_CONF[env])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mixlib/shellout'
|
2
|
+
|
3
|
+
module Lambom
|
4
|
+
module ShellMixin
|
5
|
+
def run_cmd(*cmd)
|
6
|
+
puts "RUN_CMD: #{cmd}" if $debug
|
7
|
+
com = Mixlib::ShellOut.new(cmd)
|
8
|
+
com.run_command
|
9
|
+
com.error!
|
10
|
+
puts "salida: #{com.stdout}" if $debug
|
11
|
+
com.stdout
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/lambom.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "oj"
|
2
|
+
require 'time'
|
3
|
+
require "mixlib/authentication"
|
4
|
+
require "mixlib/authentication/signedheaderauth"
|
5
|
+
require 'digest/sha1'
|
6
|
+
require 'openssl'
|
7
|
+
require 'net/http'
|
8
|
+
|
9
|
+
require "lambom/shell_mixin"
|
10
|
+
require "lambom/config"
|
11
|
+
require "lambom/api"
|
12
|
+
require "lambom/converger"
|
13
|
+
|
14
|
+
|
15
|
+
module Lambom
|
16
|
+
$debug = false
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def run(argv)
|
20
|
+
puts "DEBUG ENABLED" if $debug
|
21
|
+
puts "args recibidos #{argv.inspect}" if $debug
|
22
|
+
|
23
|
+
#cargar config
|
24
|
+
conf = Lambom::Config.new.load
|
25
|
+
|
26
|
+
# sobreescribimos a configuracion ca linea de comandos
|
27
|
+
conf.merge(argv)
|
28
|
+
|
29
|
+
attributes = {}
|
30
|
+
# descargar atributos do servidor (a menos que nos pasen json_file => file.json)
|
31
|
+
if argv.has_key?(:json_file)
|
32
|
+
json_attributes = IO.read(argv[:json_file])
|
33
|
+
else
|
34
|
+
json_attributes = Lambom::ApiClient.new(conf).get_server_config
|
35
|
+
end
|
36
|
+
|
37
|
+
# executar converxencia
|
38
|
+
Lambom::Converger.new(conf,json_attributes).run
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def enable_debug
|
43
|
+
$debug = true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "lambom"
|
2
|
+
require "lambom/api"
|
3
|
+
|
4
|
+
describe Lambom::ApiClient do
|
5
|
+
conf = Lambom::Config.new.load
|
6
|
+
|
7
|
+
conf.merge(environment: 'development',
|
8
|
+
server: '61a75d44-9856-4e64-a269-f95a232c9bcd',
|
9
|
+
private_key_file: "spec/private_key.pem")
|
10
|
+
|
11
|
+
api = Lambom::ApiClient.new(conf)
|
12
|
+
|
13
|
+
it "must be an ApiClient object" do
|
14
|
+
expect(api).to be_an_instance_of(Lambom::ApiClient)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "getAttributes" do
|
18
|
+
it "must connect to riyic api" do
|
19
|
+
expect(api.get_server_config).to match(/^\{.+\}$/)
|
20
|
+
end
|
21
|
+
it "must fail to connect to api" do
|
22
|
+
conf.merge(server: "61a75d44-9856-4e64-a269-111111111111")
|
23
|
+
api2 = Lambom::ApiClient.new(conf)
|
24
|
+
expect{api2.get_server_config}.to raise_error(/api error/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "lambom"
|
2
|
+
require "lambom/config"
|
3
|
+
|
4
|
+
describe Lambom::Config do
|
5
|
+
Lambom.enable_debug
|
6
|
+
|
7
|
+
describe "load config" do
|
8
|
+
Lambom::Config::FILE = 'spec/test_config.yml'
|
9
|
+
config = Lambom::Config.new.load
|
10
|
+
|
11
|
+
it "must load config file if exists" do
|
12
|
+
expect(config).to be_an_instance_of(Lambom::Config)
|
13
|
+
end
|
14
|
+
it "must have test file values" do
|
15
|
+
expect(config.server).to eq("1ca71cd6-08c4-4855-9381-2f41aeffe59c")
|
16
|
+
expect(config.environment).to eq("development")
|
17
|
+
expect(config.private_key_file).to eq("/etc/riyic/private.pem")
|
18
|
+
expect(config.loglevel).to eq("debug")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must have merged values" do
|
22
|
+
merge_key_file = 'test.pem'
|
23
|
+
merge_server = "1ca71cd6-08c4-4855-9381-111111111111"
|
24
|
+
merge_env = 'test'
|
25
|
+
merge_loglevel = 'info'
|
26
|
+
|
27
|
+
options = {
|
28
|
+
private_key_file: merge_key_file,
|
29
|
+
server: merge_server,
|
30
|
+
environment: merge_env,
|
31
|
+
loglevel: merge_loglevel
|
32
|
+
}
|
33
|
+
|
34
|
+
config.merge(options)
|
35
|
+
expect(config.private_key_file).to eq(merge_key_file)
|
36
|
+
expect(config.server).to eq(merge_server)
|
37
|
+
expect(config.environment).to eq(merge_env)
|
38
|
+
expect(config.loglevel).to eq(merge_loglevel)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "loading bad yaml file" do
|
43
|
+
it "must raise error if config file has bad yaml format" do
|
44
|
+
expect {
|
45
|
+
Lambom::Config::FILE = 'spec/test_config_bad_yaml.yml'
|
46
|
+
Lambom::Config.new.load
|
47
|
+
}.to raise_error(/yaml/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "bad options in config file" do
|
52
|
+
it "must raise error if config options not validate" do
|
53
|
+
expect {
|
54
|
+
Lambom::Config::FILE = 'spec/test_config_bad_options.yml'
|
55
|
+
Lambom::Config.new.load
|
56
|
+
}.to raise_error(/Invalid value/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "lambom"
|
2
|
+
require "lambom/converger"
|
3
|
+
|
4
|
+
describe Lambom::Converger do
|
5
|
+
conf = Lambom::Config.new
|
6
|
+
|
7
|
+
conf.merge(environment: 'test',
|
8
|
+
server: '61a75d44-9856-4e64-a269-f95a232c9bcd',
|
9
|
+
private_key_file: "spec/private_key.pem")
|
10
|
+
json = <<EOF
|
11
|
+
{
|
12
|
+
"riyic": {
|
13
|
+
"dockerized": "no",
|
14
|
+
"updates_check_interval": "never",
|
15
|
+
"env": "development"
|
16
|
+
},
|
17
|
+
"run_list": [
|
18
|
+
"recipe[riyic::default]"
|
19
|
+
]
|
20
|
+
}
|
21
|
+
EOF
|
22
|
+
|
23
|
+
it "must run convergence tool" do
|
24
|
+
expect{
|
25
|
+
Lambom::Converger.new(conf, json).run
|
26
|
+
}.not_to raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEpAIBAAKCAQEA5CLLZToKmeqMnkcdE5ibIB3dh28nEeKF07XOEq9MrxKwHtNX
|
3
|
+
D5oMS9eyvQxesbolXYDUCDSQmFYA4jEh8CJBE0sJsgGXi1/gkbSbTdAujH4LHAPS
|
4
|
+
RiFS9m5yQVHPHmf7FK/EKoNTEWokiOVf3UayZ8oKolOLqno6BAqDYPvp7g4+5G1s
|
5
|
+
LiblxZVuS/l4Z4OqkhIKJBygjMHXkFk5PiCG/NeM6hJ+in5RXdWJK7lorJooRUY5
|
6
|
+
7YoNRN0bkiDyPJLxGE19hHT42oghmdXKKi4h8FUkA+BCQ7GuDKqmtltCDFX6ypIn
|
7
|
+
Q2SGlDC6UIyGkmbKbSEfXZdz5mRpGGcAzuY+dwIDAQABAoIBAFGRPzfKMNAnVG+i
|
8
|
+
7Xp8Lbql8vbhfw6d90tizXNQyhIulFnxJkelxI+5Z2bAbXsOGx37WdQ1Nx3AYkB9
|
9
|
+
YK0DElFbmvPSLeTfOuPdt0lzDbGdv0sc8qmwcIE7rA4+udcdRmB3F6Q7oA+x664m
|
10
|
+
lMgA5vjE/Fhdlqo1WVjoiWC7sUAzmtZrRq/U1NBmMcCnw97/JXzTpeDVY3K1g5vl
|
11
|
+
viF+q7XBz0AtLsMIavrzx9AwSBZC+99GWuxU02zTVfz8OeZwrQJLCALQfBYfGsoW
|
12
|
+
YvMEt4o5EDBnVX8i3bkrqFnHwbzBGbgXaf7e6TksH7PkMDdw0HOlGCkmZxqg5yAg
|
13
|
+
yo5Hl4ECgYEA+MCytVGSJ5xEJgWGMpSHR5yvdU6xh4aqbYqINvD4NqSlh/b3YWVN
|
14
|
+
rn0j5M+PzUc+avNGRkcGYDYlWs58lDT250r7Juc2KJaPqMXoMJDmye6+AjD/vrEh
|
15
|
+
qXTPeKdjqdmRCnG33C4J5BVkykxa1kqi1TLk9BijFvwkGsl0X+sGW38CgYEA6shT
|
16
|
+
37tUc6NMMIOz0DHfDtWlU6uaxbqQ1WyWE/cDordQ0UYAd8dUUWHjKy19KQC5rFb1
|
17
|
+
FwTS3V9nOaMxGLDg9e3sDZHgsZpJ66ks/6szIEFjGgdpJV66tFBvDBZOyHt05Tvp
|
18
|
+
Cpl+583WPc3JorGCq3+/Di8ISazlIGlBsqSSeQkCgYAzTxwNhmvNO9Bav1z05eoZ
|
19
|
+
fVo7qiW4PLC+s4pxOrcYHlH+f5R7RHgHe8yBj8arovxe9xsRt+i6w7Bk0J6lu18K
|
20
|
+
Sk8PsTVcneG4AEpqahkQoewTa6P043h8CZoZ2v0VtcjTDK3N/rkPkNIfYCyEcxSv
|
21
|
+
QTY0mzhYr12LIO6eMk43ZQKBgQCpgcCsgz9RzdAwJqYn5hm5SB547ihsIWp37FHe
|
22
|
+
UDTbwaYjsXqc/9iseRPeFJWMiO2Es7N3zw++rCaGwn+r5+hDJmeK1It5Ln+4GQhX
|
23
|
+
/m6HFy5JmJgdVutNS9Ug0OpIbHnVFxAFixTInx/St0SgpbBFyZFS2DoPlzhF0jiQ
|
24
|
+
laj6oQKBgQDnKVnTvJimmztji2/nw24dVX0peHM0puuNfkpZg1MjNf7/kMiLl2ur
|
25
|
+
P3S8ohb4voe04gyPGzh6Cy0g10silYFCJJr1+gXrn/e/WdtHRirp+0DlE4sH3xQ/
|
26
|
+
F7JtKg840udKVxgKUdoS4POsXnMa6AQzW9Hc2vl/LwpdNACcaiGjEg==
|
27
|
+
-----END RSA PRIVATE KEY-----
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lambom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J. Gomez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mixlib-authentication
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mixlib-shellout
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description: Riyic is a server configuration service based on chef (http://riyic.com).
|
56
|
+
The lambom gem is a tool to apply, through chef-solo, your riyic configurations
|
57
|
+
in your server
|
58
|
+
email: alambike@gmail.com
|
59
|
+
executables:
|
60
|
+
- lambom
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- .rspec
|
66
|
+
- bin/lambom
|
67
|
+
- lambom.gemspec
|
68
|
+
- lib/lambom.rb
|
69
|
+
- lib/lambom/api.rb
|
70
|
+
- lib/lambom/attribute_mixin.rb
|
71
|
+
- lib/lambom/config.rb
|
72
|
+
- lib/lambom/config_static.rb
|
73
|
+
- lib/lambom/converger.rb
|
74
|
+
- lib/lambom/shell_mixin.rb
|
75
|
+
- spec/api_client_spec.rb
|
76
|
+
- spec/config_spec.rb
|
77
|
+
- spec/converger_spec.rb
|
78
|
+
- spec/private_key.pem
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/test_config.yml
|
81
|
+
- spec/test_config_bad_options.yml
|
82
|
+
- spec/test_config_bad_yaml.yml
|
83
|
+
homepage: https://github.com/RIYIC/lambom
|
84
|
+
licenses:
|
85
|
+
- Apache-2.0
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.1.11
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Tool to apply riyic configurations
|
107
|
+
test_files: []
|