Created
January 10, 2020 17:32
-
-
Save brodygov/8cbe88236db2b80cc55f555ae40f36ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit d9d38c14c11fa7c15eae01c96f839f2278021ada (origin/brody/no-yaml-anchors, brody/no-yaml-anchors) | |
Author: Andy Brody <[email protected]> | |
Date: Mon Aug 5 17:31:34 2019 -0400 | |
WIP | |
diff --git a/cloudlib/lib/cloudlib/lambda.rb b/cloudlib/lib/cloudlib/lambda.rb | |
index 94b75d46..dcb6e8dd 100644 | |
--- a/cloudlib/lib/cloudlib/lambda.rb | |
+++ b/cloudlib/lib/cloudlib/lambda.rb | |
@@ -18,6 +18,9 @@ module Cloudlib | |
CloudlibSourceConfigName = '.cloudlib-source.yaml' | |
CloudlibYamlName = 'cloudlib.yaml' | |
+ # Version upgrade ratchet | |
+ ConfigProtocolVersion = 2 | |
+ | |
def initialize | |
log.debug('#initialize') | |
end | |
@@ -242,7 +245,10 @@ module Cloudlib | |
def cloudlib_yaml_data! | |
log.debug("Loading main config from #{cloudlib_yaml_path.inspect}") | |
- YAML.safe_load(File.read(cloudlib_yaml_path), aliases: true) | |
+ data = YAML.safe_load(File.read(cloudlib_yaml_path)) | |
+ verify_config_protocol_version(data) | |
+ populate_aliases!(data) | |
+ data | |
end | |
# @return [Hash] | |
@@ -362,6 +368,7 @@ module Cloudlib | |
if ref.start_with?('-') | |
raise ArgumentError.new('Ref cannot start with -') | |
end | |
+ | |
cmd = %W[git rev-parse --verify #{ref} --] | |
log.debug('+ ' + cmd.join(' ')) | |
Subprocess.check_output(cmd).chomp | |
@@ -433,5 +440,44 @@ module Cloudlib | |
cl_source_path.inspect) | |
end | |
end | |
+ | |
+ # Given a data hash loaded from YAML, look for any environment aliases and | |
+ # turn them into actual environments. | |
+ def populate_aliases!(data) | |
+ return unless data.include?('environments') | |
+ | |
+ new_envs = {} | |
+ | |
+ data.fetch('environments').each_pair do |env, env_data| | |
+ # copy primary env to output | |
+ new_envs[env] = env_data | |
+ | |
+ env_data.fetch('aliases', []).each do |alias_name| | |
+ # Create a new environment under the alias name, copying everything | |
+ # except the list of aliases. | |
+ new_envs[alias_name] = env_data.reject { |x| x == 'aliases' } | |
+ end | |
+ end | |
+ | |
+ data['environments'] = new_envs | |
+ | |
+ nil | |
+ end | |
+ | |
+ # This can be used as a ratchet to ensure that users have newer versions of | |
+ # Cloudlib. Returns the protocol version from | |
+ # data['config_protocol_version']. | |
+ # @param [Hash] data | |
+ def verify_config_protocol_version(data) | |
+ theirs = data.fetch('config_protocol_version', 0) | |
+ if theirs > ConfigProtocolVersion | |
+ raise Cloudlib::CLIError.new( | |
+ "Config protocol version from config #{theirs.inspect} exceeds" + | |
+ ' version from this Cloudlib codebase. Try upgrading cloudlib?' | |
+ ) | |
+ end | |
+ | |
+ theirs | |
+ end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment