summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2017-06-30 00:08:07 -0700
committerelijah <elijah@riseup.net>2017-06-30 00:08:21 -0700
commit4173154a177b00c11a36b3168b1ce12af59f04af (patch)
tree9c376ae6b1d70c90dd4e3a85867a72b6f2d59fab
parentffa464c6b23a25a3e0589e647d10b4ba1ca1a4e8 (diff)
leap new -- when generating initial provider.json, use a template from the platform if available
-rw-r--r--lib/leap_cli/commands/new.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/leap_cli/commands/new.rb b/lib/leap_cli/commands/new.rb
index 46e5024..bbef92f 100644
--- a/lib/leap_cli/commands/new.rb
+++ b/lib/leap_cli/commands/new.rb
@@ -91,8 +91,21 @@ module LeapCli; module Commands
bail!
end
end
+
+ template = {
+ yml: File.join(platform_dir, 'provider_base', 'templates', 'provider.yml'),
+ json: File.join(platform_dir, 'provider_base', 'templates', 'provider.json')
+ }
+
+ if File.exists?(template[:yml])
+ write_file! 'provider.json', provider_template(template[:yml], options)
+ elsif File.exists?(template[:json])
+ write_file! 'provider.json', provider_template(template[:json], options)
+ else
+ write_file! 'provider.json', provider_content(options)
+ end
+
write_file! '.gitignore', GITIGNORE_CONTENT
- write_file! 'provider.json', provider_content(options)
write_file! 'common.json', COMMON_CONTENT
write_file! 'Leapfile', leapfile_content(options)
["nodes", "services", "tags"].each do |dir|
@@ -106,6 +119,17 @@ module LeapCli; module Commands
Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(Path.provider)).to_s
end
+ #
+ # unreleased ERB has #result_with_hash. Instead, we must fake it.
+ #
+ def provider_template(template, options)
+ require 'erb'
+ require 'ostruct'
+ ERB.new(File.read(template)).result(
+ OpenStruct.new(options).instance_eval {binding}
+ )
+ end
+
def leapfile_content(options)
%[@platform_directory_path = "#{options[:platform]}"\n# see https://leap.se/en/docs/platform/config for more options]
end
@@ -117,9 +141,13 @@ test/openvpn
test/cert
EOS
+ #
+ # deprecated: use template in platform instead.
+ #
def provider_content(options)
%[//
-// General service provider configuration.
+// This file defines global aspects of your service provider
+// See https://leap.se/provider-configuration
//
{
"domain": "#{options[:domain]}",