envirobly 1.9.0 → 1.10.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67a8f774fbb1618b3b2ed3401af23dd53a0455e3b2439cc540724c95566ee063
4
- data.tar.gz: 27cf8de4722ce015fcf4be795212912e84319b4ce3a9ca7a293b5ecb01f9631a
3
+ metadata.gz: 78d045fc1a7ddd776a3f83e20a5e3b8f49882e6477075c6f10ecd7308af9132e
4
+ data.tar.gz: dca43cc5b0184b7efdf18c867109f1eea1cb2f70e23b233d2182a99715a95e98
5
5
  SHA512:
6
- metadata.gz: 5dc44c7ef4dc39dd1b80e71301309e749cadda497f03a5088c15d20c35af27d5e305751980e824b5503022115aa67afff4968c56c57c09560ec229c690f344af
7
- data.tar.gz: 8deea030920fa4aacc0d0018e6eb2256c7c7982a2376aedbbcb58f0374e3d26d90a2352e80ec35defb65b3e1515f1c267a491b0d2c9a90f93b536387a39be38f
6
+ metadata.gz: 4a9b3835b2002fbdac6aed8f9981c8261d5509cb9bdde6e2398612e58cf432176d486b89311f61eb24e25c4e783925f93349b797f16961e45141c04609f1ae66
7
+ data.tar.gz: 15ca73d3b36db3b9d812516d71cbc6af2e8a5afe3a4a6db8fc928a3e18d8148ce88a8d3703f6e84395661b2d5e6a6ed6729c3ca32797f3be1a79dc9dda26c0f0
@@ -36,14 +36,14 @@ class Envirobly::Cli::Main < Envirobly::Base
36
36
  Envirobly::Defaults::Region.new(shell:).require_value
37
37
  end
38
38
 
39
- desc "validate", "Validates config"
40
- def validate
39
+ desc "validate", "Validates config (for given environ)"
40
+ def validate(environ_name = nil)
41
41
  Envirobly::AccessToken.new(shell:).require!
42
42
 
43
43
  config = Envirobly::Config.new
44
44
  api = Envirobly::Api.new
45
45
 
46
- params = { validation: { configs: config.configs } }
46
+ params = { validation: { config: config.merge(environ_name).to_yaml } }
47
47
  api.validate_shape params
48
48
 
49
49
  say "Config is valid #{green_check}"
@@ -1,26 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Envirobly::Config
4
- DIR = ".envirobly"
5
- BASE = "deploy.yml"
6
- OVERRIDES_PATTERN = /deploy\.([a-z0-9\-_]+)\.yml/i
3
+ module Envirobly
4
+ class Config
5
+ DIR = ".envirobly"
6
+ BASE = "deploy.yml"
7
+ OVERRIDES_PATTERN = /deploy\.([a-z0-9\-_]+)\.yml/i
7
8
 
8
- def initialize(dir = DIR)
9
- @dir = Pathname.new dir
10
- end
9
+ attr_reader :errors
11
10
 
12
- def configs
13
- Dir.entries(@dir).map do |file|
14
- path = File.join(@dir, file)
11
+ def initialize(dir = DIR)
12
+ @dir = Pathname.new dir
13
+ @errors = []
14
+ end
15
15
 
16
- next unless File.file?(path) && config_file?(file)
16
+ def configs
17
+ Dir.entries(@dir).map do |file|
18
+ path = File.join(@dir, file)
17
19
 
18
- [ "#{DIR}/#{file}", ERB.new(File.read(path)).result ]
19
- end.compact.to_h
20
- end
20
+ next unless File.file?(path) && config_file?(file)
21
+
22
+ [ "#{DIR}/#{file}", File.read(path) ]
23
+ end.compact.to_h
24
+ end
25
+
26
+ def merge(environ_name = nil)
27
+ path = Pathname.new(DIR).join(BASE).to_s
28
+ yaml = configs.fetch(path)
29
+ result = parse yaml, path
21
30
 
22
- private
23
- def config_file?(file)
24
- file == BASE || file.match?(OVERRIDES_PATTERN)
31
+ if environ_name.present?
32
+ override_path = Pathname.new(DIR).join("deploy.#{environ_name}.yml").to_s
33
+
34
+ if configs.key?(override_path)
35
+ other_yaml = configs.fetch(override_path)
36
+ override = parse other_yaml, override_path
37
+ result = result.deep_merge(override) if override.is_a?(Hash)
38
+ end
39
+ end
40
+
41
+ @errors.empty? ? result : nil
25
42
  end
43
+
44
+ private
45
+ def config_file?(file)
46
+ file == BASE || file.match?(OVERRIDES_PATTERN)
47
+ end
48
+
49
+ def parse(content, path)
50
+ begin
51
+ yaml = ERB.new(content).result
52
+ rescue Exception => e
53
+ @errors << { message: e.message, path: }
54
+ return
55
+ end
56
+
57
+ YAML.safe_load yaml, aliases: true, permitted_classes: [ Secret ]
58
+ rescue Psych::Exception => e
59
+ @errors << { message: e.message, path: }
60
+ end
61
+ end
26
62
  end
@@ -6,7 +6,7 @@ module Envirobly
6
6
  class Deployment
7
7
  include Colorize
8
8
 
9
- attr_reader :params
9
+ attr_reader :params, :shell
10
10
 
11
11
  def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:)
12
12
  @commit = commit
@@ -53,19 +53,40 @@ module Envirobly
53
53
  commit_time: @commit.time,
54
54
  commit_message: @commit.message,
55
55
  object_tree_checksum: @commit.object_tree_checksum,
56
- configs: @config.configs
56
+ config: @config.merge(@environ_name).to_yaml
57
57
  }
58
58
  }
59
59
  end
60
60
 
61
61
  def perform(dry_run:)
62
+ if dry_run
63
+ shell.say "This is a dry run, nothing will be deployed.", :green
64
+ end
65
+
66
+ # TODO: Replace with shell
62
67
  puts [ "Deploying commit", yellow(@commit.short_ref), faint("→"), green(@environ_name) ].join(" ")
63
68
  puts
69
+ # TODO: Multiline indent
64
70
  puts " #{@commit.message}"
65
71
  puts
66
72
 
67
73
  if dry_run
68
- puts YAML.dump(@params)
74
+ puts green("Config:")
75
+ puts @params[:deployment][:config]
76
+
77
+ shell.say
78
+ shell.say "Targeting:", :green
79
+
80
+ targets_and_values = [
81
+ [ "Account ID", @params[:account_id].to_s ],
82
+ [ "Project ID", @params[:project_id].to_s ],
83
+ [ "Region", @params[:region] ],
84
+ [ "Project Name", @params[:project_name] ],
85
+ [ "Environ Name", @params[:deployment][:environ_name] ]
86
+ ]
87
+
88
+ shell.print_table targets_and_values, borders: true
89
+
69
90
  return
70
91
  end
71
92
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envirobly
4
+ class Secret
5
+ attr_reader :plain
6
+
7
+ def initialize(value)
8
+ @plain = value
9
+ end
10
+
11
+ def init_with(coder)
12
+ @plain = coder.scalar
13
+ end
14
+
15
+ def encode_with(coder)
16
+ coder.scalar = @plain
17
+ end
18
+
19
+ def to_s
20
+ "[SECRET]"
21
+ end
22
+
23
+ def ==(other)
24
+ other.is_a?(Secret) && other.plain == plain
25
+ end
26
+ end
27
+ end
28
+
29
+ YAML.add_tag("!secret", Envirobly::Secret)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Envirobly
4
- VERSION = "1.9.0"
4
+ VERSION = "1.10.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envirobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
@@ -180,6 +180,7 @@ files:
180
180
  - lib/envirobly/git/commit.rb
181
181
  - lib/envirobly/git/unstaged.rb
182
182
  - lib/envirobly/numeric.rb
183
+ - lib/envirobly/secret.rb
183
184
  - lib/envirobly/target.rb
184
185
  - lib/envirobly/version.rb
185
186
  homepage: https://github.com/envirobly/envirobly-cli