ops_team 0.9.8 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app_config.rb +3 -2
- data/lib/builtins/help.rb +2 -0
- data/lib/dependencies/apk.rb +1 -1
- data/lib/dependencies/apt.rb +24 -3
- data/lib/dependencies/helpers/apt_cache_policy.rb +43 -0
- data/lib/dependencies/sshkey.rb +2 -3
- data/lib/environment.rb +5 -0
- data/lib/ops.rb +6 -1
- data/lib/secrets.rb +15 -1
- data/ops_team.gemspec +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a78e3661dac6cc0796d00dc840eeb9fedbbc7f358bf3c6af4609d37175e8d53e
|
4
|
+
data.tar.gz: f919b18cdcec154a9dac78020c20f229771b3bd870baf86ef020002c74394acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54d21b402bce3e50963b679be2393a7cf1cd993fa51c2c73481c348c4fa019748d5511a4654d9c94c175a985bb7545580cf000594fd2a7c05c7a43d849895cdd
|
7
|
+
data.tar.gz: 64ef22c5c1a2264b3734166fef0b0752c2cc3ae18003ee376d1a86e0cba97d49fdb1c3de74606e0eb0aef050899d8e20c306165190d5cefc78dc030abe26997c
|
data/lib/app_config.rb
CHANGED
@@ -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
|
-
|
40
|
-
{}
|
41
|
+
raise ParsingError, "Error parsing config data: #{e}"
|
41
42
|
end
|
42
43
|
|
43
44
|
def file_contents
|
data/lib/builtins/help.rb
CHANGED
data/lib/dependencies/apk.rb
CHANGED
data/lib/dependencies/apt.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
data/lib/dependencies/sshkey.rb
CHANGED
@@ -18,8 +18,9 @@ module Dependencies
|
|
18
18
|
def meet
|
19
19
|
Secrets.load
|
20
20
|
|
21
|
-
|
21
|
+
Output.warn("\nNo passphrase set for SSH key '#{priv_key_name}'") if passphrase.nil? || passphrase.empty?
|
22
22
|
|
23
|
+
FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
|
23
24
|
generate_key unless File.exist?(priv_key_name) && File.exist?(pub_key_name)
|
24
25
|
add_key if success? && should_add_key?
|
25
26
|
end
|
@@ -35,8 +36,6 @@ module Dependencies
|
|
35
36
|
private
|
36
37
|
|
37
38
|
def generate_key
|
38
|
-
Output.warn("\nNo passphrase set for SSH key '#{priv_key_name}'") if passphrase.nil? || passphrase.empty?
|
39
|
-
|
40
39
|
execute("ssh-keygen -b #{opt_key_size} -t #{opt_key_algo} -f #{priv_key_name} -q -N '#{passphrase}'")
|
41
40
|
end
|
42
41
|
|
data/lib/environment.rb
CHANGED
@@ -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
|
data/lib/secrets.rb
CHANGED
@@ -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 ||=
|
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
|
data/ops_team.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ops_team'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.10.3'
|
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.
|
4
|
+
version: 0.10.3
|
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
|