From 4173154a177b00c11a36b3168b1ce12af59f04af Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 30 Jun 2017 00:08:07 -0700 Subject: leap new -- when generating initial provider.json, use a template from the platform if available --- lib/leap_cli/commands/new.rb | 32 ++++++++++++++++++++++++++++++-- 1 file 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]}", -- cgit v1.2.3