aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-06-02 23:32:21 -0700
committerelijah <elijah@riseup.net>2013-06-02 23:32:21 -0700
commit93123466e50e24d1bbef9e819a45518981361d5d (patch)
treef47af837e4e722e77d4dbf8132f72d37060fb53a
parent407282d3730a64c8395e3a05822b49f7e4ce4793 (diff)
downloadleap_cli-93123466e50e24d1bbef9e819a45518981361d5d.tar.gz
leap_cli-93123466e50e24d1bbef9e819a45518981361d5d.tar.bz2
now we require a leap_platform/platform.rb config file.
-rw-r--r--leap_cli.gemspec5
-rw-r--r--lib/leap/platform.rb51
-rw-r--r--lib/leap_cli.rb2
-rw-r--r--lib/leap_cli/commands/node.rb4
-rw-r--r--lib/leap_cli/leapfile.rb15
-rw-r--r--lib/leap_cli/path.rb66
6 files changed, 75 insertions, 68 deletions
diff --git a/leap_cli.gemspec b/leap_cli.gemspec
index b13c90d..1a37ef3 100644
--- a/leap_cli.gemspec
+++ b/leap_cli.gemspec
@@ -68,8 +68,9 @@ spec = Gem::Specification.new do |s|
s.add_runtime_dependency('gpgme') # not essential, but used for some minor stuff in adding sysadmins
# misc gems
- s.add_runtime_dependency('ya2yaml') # pure ruby yaml, so we can better control output. see https://github.com/afunai/ya2yaml
- s.add_runtime_dependency('json_pure') # pure ruby json, so we can better control output.
+ s.add_runtime_dependency('ya2yaml') # pure ruby yaml, so we can better control output. see https://github.com/afunai/ya2yaml
+ s.add_runtime_dependency('json_pure') # pure ruby json, so we can better control output.
+ s.add_runtime_dependency('versionomy') # compare version strings
##
## DEPENDENCIES for VENDORED GEMS
diff --git a/lib/leap/platform.rb b/lib/leap/platform.rb
new file mode 100644
index 0000000..298e480
--- /dev/null
+++ b/lib/leap/platform.rb
@@ -0,0 +1,51 @@
+require 'versionomy'
+
+module Leap
+
+ class Platform
+ class << self
+ #
+ # configuration
+ #
+
+ attr_reader :version
+ attr_reader :compatible_cli
+ attr_accessor :facts
+ attr_accessor :paths
+ attr_accessor :node_files
+
+ def define(&block)
+ self.instance_eval(&block)
+ end
+
+ def version=(version)
+ @version = Versionomy.parse(version)
+ end
+
+ def compatible_cli=(range)
+ @compatible_cli = range
+ @minimum_cli_version = Versionomy.parse(range.first)
+ @maximum_cli_version = Versionomy.parse(range.last)
+ end
+
+ #
+ # return true if the cli_version is compatible with this platform.
+ #
+ def compatible_with_cli?(cli_version)
+ cli_version = Versionomy.parse(cli_version)
+ cli_version >= @minimum_cli_version && cli_version <= @maximum_cli_version
+ end
+
+ #
+ # return true if the platform version is within the specified range.
+ #
+ def version_in_range?(range)
+ minimum_platform_version = Versionomy.parse(range.first)
+ maximum_platform_version = Versionomy.parse(range.last)
+ @version >= minimum_platform_version && @version <= maximum_platform_version
+ end
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb
index 7b52ce4..5d74813 100644
--- a/lib/leap_cli.rb
+++ b/lib/leap_cli.rb
@@ -1,5 +1,7 @@
module LeapCli; end
+require 'leap/platform.rb'
+
require 'leap_cli/version.rb'
require 'leap_cli/constants.rb'
require 'leap_cli/requirements.rb'
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index 21822d1..bf552d3 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -75,7 +75,7 @@ module LeapCli; module Commands
node = get_node_from_args(args)
new_name = args.last
ensure_dir [:node_files_dir, new_name]
- Path::NODE_PATHS.each do |path|
+ Leap::Platform.node_files.each do |path|
rename_file! [path, node.name], [path, new_name]
end
remove_directory! [:node_files_dir, node.name]
@@ -87,7 +87,7 @@ module LeapCli; module Commands
node.command :rm do |rm|
rm.action do |global_options,options,args|
node = get_node_from_args(args)
- (Path::NODE_PATHS + [:node_files_dir]).each do |path|
+ (Leap::Platform.node_files + [:node_files_dir]).each do |path|
remove_file! [path, node.name]
end
if node.vagrant?
diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb
index 06db3b4..e37cd4e 100644
--- a/lib/leap_cli/leapfile.rb
+++ b/lib/leap_cli/leapfile.rb
@@ -28,10 +28,25 @@ module LeapCli
if directory == '/'
return nil
else
+ #
+ # set up paths
+ #
@provider_directory_path = directory
read_settings(directory + '/Leapfile')
read_settings(ENV['HOME'] + '/.leaprc')
@platform_directory_path = File.expand_path(@platform_directory_path || '../leap_platform', @provider_directory_path)
+
+ #
+ # load the platform
+ #
+ require "#{@platform_directory_path}/platform.rb"
+ if !Leap::Platform.compatible_with_cli?(LeapCli::VERSION)
+ Util.bail! "This leap command (version #{LeapCli::VERSION}) is not compatible with the platform #{@platform_directory_path} (which requires #{Platform.compatible_cli.first} to #{Platform.compatible_cli.last})."
+ end
+
+ #
+ # set defaults
+ #
if @allow_production_deploy.nil?
# by default, only allow production deploys from 'master' or if not a git repo
@allow_production_deploy = !LeapCli::Util.is_git_directory?(@provider_directory_path) ||
diff --git a/lib/leap_cli/path.rb b/lib/leap_cli/path.rb
index 4b17d45..b705788 100644
--- a/lib/leap_cli/path.rb
+++ b/lib/leap_cli/path.rb
@@ -2,68 +2,6 @@ require 'fileutils'
module LeapCli; module Path
- #
- # all the named paths, relative to provider directory.
- #
- NAMED_PATHS = {
- # directories
- :hiera_dir => 'hiera',
- :files_dir => 'files',
- :nodes_dir => 'nodes',
- :services_dir => 'services',
- :tags_dir => 'tags',
- :node_files_dir => 'files/nodes/#{arg}',
-
- # input config files
- :common_config => 'common.json',
- :provider_config => 'provider.json',
- :secrets_config => 'secrets.json',
- :node_config => 'nodes/#{arg}.json',
- :service_config => 'services/#{arg}.json',
- :tag_config => 'tags/#{arg}.json',
-
- # input templates
- :provider_json_template => 'files/service-definitions/provider.json.erb',
- :eip_service_json_template => 'files/service-definitions/#{arg}/eip-service.json.erb',
- :soledad_service_json_template => 'files/service-definitions/#{arg}/soledad-service.json.erb',
- :smtp_service_json_template => 'files/service-definitions/#{arg}/smtp-service.json.erb',
-
- # output files
- :user_ssh => 'users/#{arg}/#{arg}_ssh.pub',
- :user_pgp => 'users/#{arg}/#{arg}_pgp.pub',
- :known_hosts => 'files/ssh/known_hosts',
- :authorized_keys => 'files/ssh/authorized_keys',
- :ca_key => 'files/ca/ca.key',
- :ca_cert => 'files/ca/ca.crt',
- :client_ca_key => 'files/ca/client_ca.key',
- :client_ca_cert => 'files/ca/client_ca.crt',
- :dh_params => 'files/ca/dh.pem',
- :commercial_key => 'files/cert/#{arg}.key',
- :commercial_csr => 'files/cert/#{arg}.csr',
- :commercial_cert => 'files/cert/#{arg}.crt',
- :commercial_ca_cert => 'files/cert/commercial_ca.crt',
- :vagrantfile => 'test/Vagrantfile',
-
- # node output files
- :hiera => 'hiera/#{arg}.yaml',
- :node_ssh_pub_key => 'files/nodes/#{arg}/#{arg}_ssh.pub',
- :node_x509_key => 'files/nodes/#{arg}/#{arg}.key',
- :node_x509_cert => 'files/nodes/#{arg}/#{arg}.crt',
-
- # testing files
- :test_client_key => 'test/cert/client.key',
- :test_client_cert => 'test/cert/client.crt',
- :test_openvpn_config => 'test/openvpn/#{arg}.ovpn',
- :test_client_openvpn_template => 'test/openvpn/client.ovpn.erb'
- }
-
- #
- # paths that take node name as the argument
- #
- NODE_PATHS = [
- :node_config, :hiera, :node_x509_cert, :node_x509_key, :node_ssh_pub_key
- ]
-
def self.platform
@platform
end
@@ -122,8 +60,8 @@ module LeapCli; module Path
end
if name.is_a? Symbol
- Util::assert!(NAMED_PATHS[name], "Error, I don't know the path for :#{name} (with argument '#{arg}')")
- filename = eval('"' + NAMED_PATHS[name] + '"')
+ Util::assert!(Leap::Platform.paths[name], "Error, I don't know the path for :#{name} (with argument '#{arg}')")
+ filename = eval('"' + Leap::Platform.paths[name] + '"')
return provider_dir + '/' + filename
else
return name