ops_team 0.9.9 → 0.10.4

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: bb111c3faceceae92cb8ae9907b7bf9da2c4984191bb22f47c3f14237c287c05
4
- data.tar.gz: 8fa74d1592b5b66a66b637325d737358220157796b08e2ab64a8248275ef4624
3
+ metadata.gz: 6f2b052b1a1dfd1e4cc30acca43495993be28499f2b1fa9eb8e587da57931d3a
4
+ data.tar.gz: 27b21a20f77b1a0bf416f3d3a56be4142baa0b7553b3161e0b916da61b0f3422
5
5
  SHA512:
6
- metadata.gz: cea8868f0451869d8c4988b920c76d6c0d2ef6a9b878181da05ba8a7b35b66e5638c7062b4485e29f7fe9298b863c60f712fa12f7364fc723beada03e32bb323
7
- data.tar.gz: 6dc28aae33915e08e482eb0373ba7babedf30b454cfd6189fefd9e3084a7ef0f61227ce8714e0a1433cc1b32ef08f28f56322f16da78051598a7d030058d34b3
6
+ metadata.gz: 67f1395a225c91a2ee619ecd1eb6eb26e16ca05bafb5f82916508875a7b58c0eafe40be120f83ec2b55a42aa3695bcb91cf1b1ca5973c521029bd377f9c02c86
7
+ data.tar.gz: cf644c0878ce56c6f11c6e45719044a72aa71a566bca492c5f51966436ef25010ec19dd6c5d8f5a0f4cd408177a114975f4e3160b27977bda3360db4ce456282
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AppConfig
4
+ class ParsingError < StandardError; end
5
+
4
6
  class << self
5
7
  def load
6
8
  new(app_config_path).load
@@ -36,8 +38,7 @@ class AppConfig
36
38
  def config
37
39
  @config ||= file_contents ? YAML.safe_load(file_contents) : {}
38
40
  rescue YAML::SyntaxError => e
39
- Output.error("Error parsing config data: #{e}")
40
- {}
41
+ raise ParsingError, "Error parsing config data: #{e}"
41
42
  end
42
43
 
43
44
  def file_contents
@@ -52,6 +52,8 @@ module Builtins
52
52
  end
53
53
 
54
54
  def actions
55
+ return [] unless @config["actions"]
56
+
55
57
  @config["actions"].map do |name, value|
56
58
  format("%<name>-35s %<desc>s",
57
59
  name: name.yellow,
@@ -32,12 +32,18 @@ module Builtins
32
32
 
33
33
  private
34
34
 
35
- def template_name_arg
35
+ def template_name
36
36
  @args[0]
37
37
  end
38
38
 
39
39
  def template_path
40
- format(OPS_YML_TEMPLATE, template_name: template_name_arg || DEFAULT_TEMPLATE_NAME)
40
+ return template_name if template_name && File.exist?(template_name)
41
+
42
+ builtin_template_path
43
+ end
44
+
45
+ def builtin_template_path
46
+ format(OPS_YML_TEMPLATE, template_name: template_name || DEFAULT_TEMPLATE_NAME)
41
47
  end
42
48
 
43
49
  def template_name_list
@@ -20,7 +20,7 @@ module Dependencies
20
20
  end
21
21
 
22
22
  def should_meet?
23
- `uname`.chomp == "Linux" && system("which apk &>/dev/null")
23
+ `uname`.chomp == "Linux" && system("which apk")
24
24
  end
25
25
  end
26
26
  end
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dependency'
4
+ require 'dependencies/helpers/apt_cache_policy'
4
5
 
5
6
  module Dependencies
6
7
  class Apt < Dependency
8
+ PACKAGE_NAME_SEPARATOR = "/"
9
+
7
10
  def met?
8
- execute("dpkg-query --show --showformat '${db:Status-Status}\n' #{name} | grep -q ^installed")
11
+ return apt_cache_policy.installed_version == package_version if package_version
12
+
13
+ apt_cache_policy.installed?
9
14
  end
10
15
 
11
16
  def meet
@@ -18,13 +23,29 @@ module Dependencies
18
23
  end
19
24
 
20
25
  def should_meet?
21
- `uname`.chomp == "Linux" && system("which apt-get &>/dev/null")
26
+ `uname`.chomp == "Linux" && system("which apt-get")
22
27
  end
23
28
 
24
29
  private
25
30
 
31
+ def package_name
32
+ name_components[0]
33
+ end
34
+
35
+ def package_version
36
+ name_components[1]
37
+ end
38
+
39
+ def name_components
40
+ name.split(PACKAGE_NAME_SEPARATOR, 2)
41
+ end
42
+
43
+ def apt_cache_policy
44
+ @apt_cache_policy ||= Dependencies::Helpers::AptCachePolicy.new(package_name)
45
+ end
46
+
26
47
  def sudo_string
27
- return "" if ENV['USER'] == "root" || Options.get("apt.use_sudo") == false
48
+ return "" if ENV['USER'] == "root" || `whoami` == "root" || Options.get("apt.use_sudo") == false
28
49
 
29
50
  "sudo "
30
51
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependencies
4
+ module Helpers
5
+ class AptCachePolicy
6
+ INSTALLED_VERSION_REGEX = / Installed: ([-+.a-z0-9]+)/.freeze
7
+
8
+ attr_reader :name
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ end
13
+
14
+ def installed_version
15
+ version_from_policy_version_line(installed_version_line)
16
+ end
17
+
18
+ def installed?
19
+ !!installed_version
20
+ end
21
+
22
+ private
23
+
24
+ def installed_version_line
25
+ apt_cache_lines.find { |line| line.match(/#{INSTALLED_VERSION_REGEX}/) }
26
+ end
27
+
28
+ def version_from_policy_version_line(line)
29
+ return nil if line.nil?
30
+
31
+ # E.g.:
32
+ # Installed: 7.52.1-5+deb9u7
33
+ match = line.match(/#{INSTALLED_VERSION_REGEX}/)
34
+
35
+ match.nil? ? nil : match[1]
36
+ end
37
+
38
+ def apt_cache_lines
39
+ @apt_cache_lines ||= `apt-cache policy #{name}`.split("\n")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -6,6 +6,7 @@ class Environment
6
6
  end
7
7
 
8
8
  def set_variables
9
+ set_ops_variables
9
10
  set_environment_aliases
10
11
  set_configured_variables
11
12
  end
@@ -18,6 +19,10 @@ class Environment
18
19
 
19
20
  private
20
21
 
22
+ def set_ops_variables
23
+ ENV["OPS_YML_DIR"] = Dir.pwd
24
+ end
25
+
21
26
  def set_environment_aliases
22
27
  environment_aliases.each do |alias_name|
23
28
  ENV[alias_name] = environment
data/lib/ops.rb CHANGED
@@ -18,6 +18,7 @@ class Ops
18
18
 
19
19
  INVALID_SYNTAX_EXIT_CODE = 64
20
20
  UNKNOWN_ACTION_EXIT_CODE = 65
21
+ ERROR_LOADING_APP_CONFIG_EXIT_CODE = 66
21
22
 
22
23
  class << self
23
24
  def project_name
@@ -60,6 +61,9 @@ class Ops
60
61
 
61
62
  Output.notice("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
62
63
  action.run
64
+ rescue AppConfig::ParsingError => e
65
+ Output.error("Error parsing app config: #{e}")
66
+ exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
63
67
  end
64
68
 
65
69
  def builtin
@@ -94,7 +98,8 @@ class Ops
94
98
  @config ||= begin
95
99
  Output.warn("File '#{CONFIG_FILE}' does not exist.") unless File.exist?(CONFIG_FILE)
96
100
  YAML.load_file(CONFIG_FILE)
97
- rescue StandardError
101
+ rescue StandardError => e
102
+ Output.warn("Error parsing '#{CONFIG_FILE}': #{e}")
98
103
  {}
99
104
  end
100
105
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'open3'
4
5
 
5
6
  require 'output'
6
7
  require 'app_config'
@@ -38,6 +39,19 @@ class Secrets < AppConfig
38
39
  end
39
40
 
40
41
  def file_contents
41
- @file_contents ||= @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : super
42
+ @file_contents ||= begin
43
+ @filename.match(/\.ejson$/) ? ejson_contents : super
44
+ end
45
+ end
46
+
47
+ def ejson_contents
48
+ @ejson_contents ||= begin
49
+ out, err, _status = Open3.capture3("ejson decrypt #{@filename}")
50
+
51
+ # TODO: err is only nil in testing, but I can't figure out why the stubbing isn't working
52
+ raise ParsingError, "Error decrypting EJSON file: #{err}" unless err.nil? || err.empty?
53
+
54
+ out
55
+ end
42
56
  end
43
57
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.9.9'
5
+ s.version = '0.10.4'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  'lib/builtins/*',
18
18
  'lib/builtins/helpers/*',
19
19
  'lib/dependencies/*',
20
+ 'lib/dependencies/helpers/*',
20
21
  'loader.rb',
21
22
  'ops_team.gemspec'
22
23
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -166,6 +166,7 @@ files:
166
166
  - lib/dependencies/dir.rb
167
167
  - lib/dependencies/docker.rb
168
168
  - lib/dependencies/gem.rb
169
+ - lib/dependencies/helpers/apt_cache_policy.rb
169
170
  - lib/dependencies/sshkey.rb
170
171
  - lib/dependency.rb
171
172
  - lib/environment.rb