dapp 0.12.8 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +0 -4
  3. data/config/en/common.yml +1 -0
  4. data/config/en/net_status.yml +5 -0
  5. data/lib/dapp.rb +20 -8
  6. data/lib/dapp/cli.rb +2 -5
  7. data/lib/dapp/cli/command/base.rb +1 -5
  8. data/lib/dapp/dapp.rb +0 -22
  9. data/lib/dapp/dapp/shellout/streaming.rb +2 -2
  10. data/lib/dapp/deployment/cli/command/deployment.rb +1 -3
  11. data/lib/dapp/deployment/cli/command/deployment/apply.rb +1 -1
  12. data/lib/dapp/deployment/dapp/dapp.rb +0 -2
  13. data/lib/dapp/dimg/cli/command/base.rb +4 -0
  14. data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +1 -3
  15. data/lib/dapp/dimg/dimg.rb +1 -0
  16. data/lib/dapp/dimg/dimg/path.rb +0 -6
  17. data/lib/dapp/helper/trivia.rb +4 -0
  18. data/lib/dapp/kube.rb +1 -0
  19. data/lib/dapp/kube/cli/cli.rb +1 -0
  20. data/lib/dapp/kube/cli/command/base.rb +14 -0
  21. data/lib/dapp/kube/cli/command/kube.rb +21 -0
  22. data/lib/dapp/kube/cli/command/kube/deploy.rb +30 -0
  23. data/lib/dapp/kube/cli/command/kube/dismiss.rb +21 -0
  24. data/lib/dapp/kube/cli/command/kube/secret_file_encrypt.rb +23 -0
  25. data/lib/dapp/kube/cli/command/kube/secret_generate.rb +13 -0
  26. data/lib/dapp/kube/cli/command/kube/secret_key_generate.rb +13 -0
  27. data/lib/dapp/kube/dapp/command/common.rb +29 -0
  28. data/lib/dapp/kube/dapp/command/deploy.rb +192 -0
  29. data/lib/dapp/kube/dapp/command/dismiss.rb +25 -0
  30. data/lib/dapp/kube/dapp/command/secret_file_encrypt.rb +22 -0
  31. data/lib/dapp/{deployment → kube}/dapp/command/secret_generate.rb +3 -3
  32. data/lib/dapp/{deployment → kube}/dapp/command/secret_key_generate.rb +2 -2
  33. data/lib/dapp/kube/dapp/dapp.rb +16 -0
  34. data/lib/dapp/kube/error/base.rb +7 -0
  35. data/lib/dapp/kube/error/command.rb +7 -0
  36. data/lib/dapp/kube/kubernetes.rb +191 -0
  37. data/lib/dapp/kube/secret.rb +93 -0
  38. data/lib/dapp/version.rb +1 -1
  39. metadata +23 -37
  40. data/lib/dapp/dapp/sentry.rb +0 -112
  41. data/lib/dapp/deployment/cli/command/deployment/secret_generate.rb +0 -13
  42. data/lib/dapp/deployment/cli/command/deployment/secret_key_generate.rb +0 -13
  43. data/lib/dapp/helper/url.rb +0 -23
@@ -0,0 +1,93 @@
1
+ module Dapp
2
+ module Kube
3
+ class Secret
4
+ attr_reader :key
5
+
6
+ def initialize(key)
7
+ self.class._validate_key!(key)
8
+ @key = key
9
+ end
10
+
11
+ def generate(value)
12
+ cipher = self.class._openssl_cipher
13
+ cipher.encrypt
14
+ cipher.key = self.class._hex_to_binary key
15
+ iv = cipher.random_iv
16
+
17
+ iv_size_prefix = [iv.bytesize].pack('S')
18
+ encrypted = cipher.update(value.to_s) + cipher.final
19
+
20
+ self.class._binary_to_hex "#{iv_size_prefix}#{iv}#{encrypted}"
21
+ end
22
+
23
+ def extract(hexdata)
24
+ data = self.class._hex_to_binary hexdata.to_s
25
+
26
+ iv_size = data.unpack('S').first
27
+ data = data.byteslice(2..-1)
28
+ raise ExtractionError, code: :bad_data, data: {data: hexdata} unless data
29
+
30
+ iv = data.byteslice(0, iv_size)
31
+ data = data.byteslice(iv_size..-1)
32
+ raise ExtractionError, code: :bad_data, data: {data: hexdata} unless data
33
+
34
+ decipher = self.class._openssl_cipher
35
+ decipher.decrypt
36
+ decipher.key = self.class._hex_to_binary(key)
37
+
38
+ begin
39
+ decipher.iv = iv
40
+ rescue OpenSSL::Cipher::CipherError
41
+ raise ExtractionError, code: :bad_data, data: {data: hexdata}
42
+ end
43
+
44
+ begin
45
+ value = decipher.update(data) + decipher.final
46
+ rescue OpenSSL::Cipher::CipherError
47
+ raise ExtractionError, code: :bad_data, data: {data: hexdata}
48
+ end
49
+ value.force_encoding('utf-8')
50
+ end
51
+
52
+ class << self
53
+ def generate_key
54
+ _binary_to_hex _openssl_cipher.random_key
55
+ end
56
+
57
+ def _openssl_cipher
58
+ OpenSSL::Cipher::AES.new(128, :CBC)
59
+ end
60
+
61
+ def _hex_to_binary(key)
62
+ [key].pack('H*')
63
+ end
64
+
65
+ def _binary_to_hex(key)
66
+ key.unpack('H*').first
67
+ end
68
+
69
+ def _validate_key!(key)
70
+ # Требуется 128 битный ключ — это 16 байт.
71
+ # Ключ закодирован в hex кодировке для пользователя.
72
+ # 2 hex символа на 1 байт в hex кодировке.
73
+ # Поэтому требуется длина ключа в hex кодировке в 32 символа.
74
+ if key.bytesize < 32
75
+ raise InvalidKeyError, code: :key_length_too_short, data: {required_size: 32}
76
+ end
77
+ end
78
+ end
79
+
80
+ class Error < ::Dapp::Deployment::Error::Base
81
+ def initialize(**net_status)
82
+ super(net_status.merge(context: :secret))
83
+ end
84
+ end
85
+
86
+ class InvalidKeyError < Error
87
+ end
88
+
89
+ class ExtractionError < Error
90
+ end
91
+ end
92
+ end
93
+ end
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.12.8'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  BUILD_CACHE_VERSION = 13
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.8
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -166,34 +166,6 @@ dependencies:
166
166
  - - "~>"
167
167
  - !ruby/object:Gem::Version
168
168
  version: 0.1.6
169
- - !ruby/object:Gem::Dependency
170
- name: sentry-raven
171
- requirement: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - "~>"
174
- - !ruby/object:Gem::Version
175
- version: 2.7.2
176
- type: :runtime
177
- prerelease: false
178
- version_requirements: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - "~>"
181
- - !ruby/object:Gem::Version
182
- version: 2.7.2
183
- - !ruby/object:Gem::Dependency
184
- name: toml-rb
185
- requirement: !ruby/object:Gem::Requirement
186
- requirements:
187
- - - "~>"
188
- - !ruby/object:Gem::Version
189
- version: 1.1.1
190
- type: :runtime
191
- prerelease: false
192
- version_requirements: !ruby/object:Gem::Requirement
193
- requirements:
194
- - - "~>"
195
- - !ruby/object:Gem::Version
196
- version: 1.1.1
197
169
  - !ruby/object:Gem::Dependency
198
170
  name: bundler
199
171
  requirement: !ruby/object:Gem::Requirement
@@ -448,7 +420,6 @@ files:
448
420
  - lib/dapp/dapp/logging/i18n.rb
449
421
  - lib/dapp/dapp/logging/paint.rb
450
422
  - lib/dapp/dapp/logging/process.rb
451
- - lib/dapp/dapp/sentry.rb
452
423
  - lib/dapp/dapp/shellout/base.rb
453
424
  - lib/dapp/dapp/shellout/streaming.rb
454
425
  - lib/dapp/dapp/ssh_agent.rb
@@ -460,8 +431,6 @@ files:
460
431
  - lib/dapp/deployment/cli/command/deployment/apply.rb
461
432
  - lib/dapp/deployment/cli/command/deployment/minikube_setup.rb
462
433
  - lib/dapp/deployment/cli/command/deployment/mrproper.rb
463
- - lib/dapp/deployment/cli/command/deployment/secret_generate.rb
464
- - lib/dapp/deployment/cli/command/deployment/secret_key_generate.rb
465
434
  - lib/dapp/deployment/config/config.rb
466
435
  - lib/dapp/deployment/config/directive/app.rb
467
436
  - lib/dapp/deployment/config/directive/app/instance_methods.rb
@@ -479,8 +448,6 @@ files:
479
448
  - lib/dapp/deployment/dapp/command/common.rb
480
449
  - lib/dapp/deployment/dapp/command/minikube_setup.rb
481
450
  - lib/dapp/deployment/dapp/command/mrproper.rb
482
- - lib/dapp/deployment/dapp/command/secret_generate.rb
483
- - lib/dapp/deployment/dapp/command/secret_key_generate.rb
484
451
  - lib/dapp/deployment/dapp/dapp.rb
485
452
  - lib/dapp/deployment/dapp/dappfile.rb
486
453
  - lib/dapp/deployment/deployment.rb
@@ -649,7 +616,26 @@ files:
649
616
  - lib/dapp/helper/net_status.rb
650
617
  - lib/dapp/helper/sha256.rb
651
618
  - lib/dapp/helper/trivia.rb
652
- - lib/dapp/helper/url.rb
619
+ - lib/dapp/kube.rb
620
+ - lib/dapp/kube/cli/cli.rb
621
+ - lib/dapp/kube/cli/command/base.rb
622
+ - lib/dapp/kube/cli/command/kube.rb
623
+ - lib/dapp/kube/cli/command/kube/deploy.rb
624
+ - lib/dapp/kube/cli/command/kube/dismiss.rb
625
+ - lib/dapp/kube/cli/command/kube/secret_file_encrypt.rb
626
+ - lib/dapp/kube/cli/command/kube/secret_generate.rb
627
+ - lib/dapp/kube/cli/command/kube/secret_key_generate.rb
628
+ - lib/dapp/kube/dapp/command/common.rb
629
+ - lib/dapp/kube/dapp/command/deploy.rb
630
+ - lib/dapp/kube/dapp/command/dismiss.rb
631
+ - lib/dapp/kube/dapp/command/secret_file_encrypt.rb
632
+ - lib/dapp/kube/dapp/command/secret_generate.rb
633
+ - lib/dapp/kube/dapp/command/secret_key_generate.rb
634
+ - lib/dapp/kube/dapp/dapp.rb
635
+ - lib/dapp/kube/error/base.rb
636
+ - lib/dapp/kube/error/command.rb
637
+ - lib/dapp/kube/kubernetes.rb
638
+ - lib/dapp/kube/secret.rb
653
639
  - lib/dapp/prctl.rb
654
640
  - lib/dapp/version.rb
655
641
  homepage: https://github.com/flant/dapp
@@ -672,7 +658,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
672
658
  version: 2.5.0
673
659
  requirements: []
674
660
  rubyforge_project:
675
- rubygems_version: 2.5.1
661
+ rubygems_version: 2.4.8
676
662
  signing_key:
677
663
  specification_version: 4
678
664
  summary: Build docker packaged apps using chef or shell
@@ -1,112 +0,0 @@
1
- module Dapp
2
- class Dapp
3
- module Sentry
4
- def sentry_message(msg, **kwargs)
5
- return if not ensure_sentry_configured
6
- kwargs[:level] ||= "info"
7
- Raven.capture_message(msg, _make_sentry_params(**kwargs))
8
- end
9
-
10
- def sentry_exception(exception, **kwargs)
11
- return if not ensure_sentry_configured
12
- (kwargs[:tags] ||= {})['error-code'] = begin
13
- net_status = exception.net_status
14
- [net_status[:context], net_status[:code]].compact.join('_')
15
- end
16
- Raven.capture_exception(exception, _make_sentry_params(**kwargs))
17
- end
18
-
19
- def ensure_sentry_configured
20
- return false unless sentry_settings = settings["sentry"]
21
-
22
- unless @sentry_settings_configured
23
- Raven.configure do |config|
24
- logger = ::Logger.new(STDOUT)
25
- logger.level = ::Logger::WARN
26
-
27
- config.logger = logger
28
- config.dsn = sentry_settings["dsn"]
29
- end
30
-
31
- @sentry_settings_configured = true
32
- end
33
-
34
- return true
35
- end
36
-
37
- def _make_sentry_params(level: nil, tags: {}, extra: {}, user: {})
38
- {
39
- level: level,
40
- tags: _sentry_tags_context.merge(tags),
41
- extra: _sentry_extra_context.merge(extra),
42
- user: _sentry_user_context.merge(user),
43
- }
44
- end
45
-
46
- def _sentry_extra_context
47
- @_sentry_extra_context ||= {
48
- "pwd" => Dir.pwd,
49
- "dapp-dir" => self.work_dir,
50
- "options" => self.options,
51
- "env-options" => {
52
- "DAPP_FORCE_SAVE_CACHE" => ENV["DAPP_FORCE_SAVE_CACHE"],
53
- "DAPP_BIN_DAPPFILE_YML" => ENV["DAPP_BIN_DAPPFILE_YML"],
54
- "ANSIBLE_ARGS" => ENV["ANSIBLE_ARGS"],
55
- "DAPP_CHEF_DEBUG" => ENV["DAPP_CHEF_DEBUG"],
56
- },
57
- }.tap {|extra|
58
- extra["ci-env"] = {"CI" => ENV["CI"]}
59
- ENV.select {|k, v| k.start_with?("CI_")}.each do |k, v|
60
- extra["ci-env"][k] = v
61
- end
62
- }
63
- end
64
-
65
- def _sentry_tags_context
66
- name = options[:name] ||
67
- @_sentry_tags_context ||= {
68
- "dapp-short-version" => ::Dapp::VERSION.split(".")[0..1].join("."),
69
- "dapp-version" => ::Dapp::VERSION,
70
- "dapp-build-cache-version" => ::Dapp::BUILD_CACHE_VERSION,
71
- "dapp-command" => self.options[:dapp_command],
72
- }.tap {|tags|
73
- git_config_path = File.join(Dir.pwd, ".git/config")
74
-
75
- tags["dapp-name"] = options[:name]
76
-
77
- if File.exists? git_config_path
78
- cfg = IniFile.load(File.join(Dir.pwd, ".git/config"))
79
- remote_origin_cfg = cfg['remote "origin"']
80
- remote_origin_url = remote_origin_cfg["url"]
81
- if remote_origin_url
82
- tags["dapp-name"] ||= begin
83
- repo_name = remote_origin_url.split('/').last
84
- repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
85
- repo_name
86
- end
87
-
88
- tags["git-host"] = self.get_host_from_git_url(remote_origin_url)
89
-
90
- git_name = self.git_url_to_name(remote_origin_url)
91
-
92
- tags["git-group"] = git_name.partition("/")[0]
93
- tags["git-name"] = git_name
94
- end
95
- end
96
-
97
- tags["dapp-name"] ||= File.basename(Dir.pwd)
98
-
99
- begin
100
- ver = self.class.host_docker_minor_version
101
- tags["docker-minor-version"] = ver.to_s
102
- rescue ::Exception
103
- end
104
- }
105
- end
106
-
107
- def _sentry_user_context
108
- @_sentry_user_context ||= {}
109
- end
110
- end # Sentry
111
- end # Dapp
112
- end # Dapp
@@ -1,13 +0,0 @@
1
- module Dapp::Deployment::CLI::Command
2
- class Deployment < ::Dapp::CLI
3
- class SecretGenerate < Base
4
- banner <<BANNER.freeze
5
- Usage:
6
-
7
- dapp deployment secret generate
8
-
9
- Options:
10
- BANNER
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Dapp::Deployment::CLI::Command
2
- class Deployment < ::Dapp::CLI
3
- class SecretKeyGenerate < Base
4
- banner <<BANNER.freeze
5
- Usage:
6
-
7
- dapp deployment secret key generate
8
-
9
- Options:
10
- BANNER
11
- end
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- module Dapp
2
- module Helper
3
- module Url
4
- def git_url_to_name(url)
5
- url_without_scheme = url.split("://", 2).last
6
- # This may be broken, because "@" should delimit creds, not a ":"
7
- url_without_creds = url_without_scheme.split(":", 2).last
8
- url_without_creds.gsub(%r{.*?([^\/ ]+\/[^\/ ]+)\.git}, '\\1')
9
- end
10
-
11
- def get_host_from_git_url(url)
12
- url_without_scheme = url.split("://", 2).last
13
- url_without_creds = url_without_scheme.split("@", 2).last
14
-
15
- # Split out part after ":" in this kind of url: github.com:flant/dapp.git
16
- url_part = url_without_creds.split(":", 2).first
17
-
18
- # Split out part after first "/": github.com/flant/dapp.git
19
- url_part.split("/", 2).first
20
- end
21
- end # Url
22
- end # Helper
23
- end # Dapp