avm-tools 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c43972836fb5b4414055f3b478a1f85e814c1c86bf84d2975031c7aa1890902
4
- data.tar.gz: c0ab56207e455dee36a9dc480b23f8e1d6e494421913c830dd746779d9293f4d
3
+ metadata.gz: d6a03e86cba8b7cc3cefba9163e093176460fc22f9155414ad6cc113ebe3cd5d
4
+ data.tar.gz: bd31ac49d42c4020a81543f099b5cdc693628821601ef196f185b675d03285ed
5
5
  SHA512:
6
- metadata.gz: 1e482a38d4fa941481cf58e635776884ed86fece1df69e458b2be979de63f67f345ae738218d4f911ac6e0c184811eb6b77d88dce6b6169670e7e7fc48ae3781
7
- data.tar.gz: 5a969b9d92a2b1d21dd85f99d0d286a7e4f01bc9d101d60632d43eea5a70fea98e41bbf00f7a2331c62e7855b9c079b5171eae5208ee25354b8b40eb9dd9a2b1
6
+ metadata.gz: 01b434bc5a5bc72b9de6ab1679886ef5587fba84e1095d114702dfae4d180b169fcc8c823df7adef6965a4c1a0b9c266649f0de86eb912bb0f5e3141663369a3
7
+ data.tar.gz: ee37b11970672b1c90b313517807349381f93ae0fd892e6d85dd0c7dbcbd766efe7073351a5bf4f5dc316516983ca7368636acbd1e7154b8911a44e548831972
@@ -4,8 +4,19 @@ require 'eac_ruby_utils/console/configs'
4
4
 
5
5
  module Avm
6
6
  class << self
7
+ attr_reader :configs_storage_path
8
+
7
9
  def configs
8
- @configs ||= ::EacRubyUtils::Console::Configs.new('avm-tools')
10
+ @configs ||= ::EacRubyUtils::Console::Configs.new('avm-tools', configs_options)
11
+ end
12
+
13
+ def configs_options
14
+ configs_storage_path.if_present({}) { |v| { storage_path: v } }
15
+ end
16
+
17
+ def configs_storage_path=(path)
18
+ @configs_storage_path = path
19
+ @configs = nil
9
20
  end
10
21
  end
11
22
  end
@@ -1,14 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
3
4
  require 'eac_ruby_utils/simple_cache'
4
5
  require 'avm/instances/entries'
6
+ ::EacRubyUtils.require_sub(__FILE__)
5
7
 
6
8
  module Avm
7
9
  module Instances
8
10
  class Base
11
+ include ::EacRubyUtils::Listable
9
12
  include ::EacRubyUtils::SimpleCache
13
+ include ::Avm::Instances::Base::AutoValues
10
14
  include ::Avm::Instances::Entries
11
15
 
16
+ lists.add_string :access, :local, :ssh
17
+
12
18
  ID_PATTERN = /\A([a-z]+(?:\-[a-z]+)*)_(.+)\z/.freeze
13
19
 
14
20
  class << self
@@ -44,10 +50,11 @@ module Avm
44
50
  end
45
51
 
46
52
  def host_env_uncached
47
- if read_entry('host') == 'localhost'
48
- ::EacRubyUtils::Envs.local
49
- else
50
- ::EacRubyUtils::Envs.ssh("#{read_entry('user')}@#{read_entry('host')}")
53
+ access = read_entry(:access, list: ::Avm::Instances::Base.lists.access.values)
54
+ case access
55
+ when 'local' then return ::EacRubyUtils::Envs.local
56
+ when 'ssh' then return ::EacRubyUtils::Envs.ssh(read_entry('ssh.url'))
57
+ else raise("Unmapped access value: \"#{access}\"")
51
58
  end
52
59
  end
53
60
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Instances
8
+ class Base
9
+ module AutoValues
10
+ extend ::ActiveSupport::Concern
11
+
12
+ included do
13
+ %w[Access Database Filesystem Source].each do |class_name|
14
+ include const_get(class_name)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Access
8
+ def auto_access
9
+ read_entry_optional('ssh.url').present? ? 'ssh' : 'local'
10
+ end
11
+
12
+ def auto_ssh_hostname
13
+ inherited_entry_value(:host_id, 'ssh.hostname')
14
+ end
15
+
16
+ def auto_ssh_port
17
+ inherited_entry_value(:host_id, 'ssh.port') || 22
18
+ end
19
+
20
+ def auto_ssh_username
21
+ inherited_entry_value(:host_id, 'ssh.username')
22
+ end
23
+
24
+ def auto_ssh_url
25
+ inherited_entry_value(:host_id, 'ssh.url') || auto_ssh_url_by_parts
26
+ end
27
+
28
+ def auto_ssh_url_by_parts
29
+ read_entry_optional('ssh.hostname').if_present do |a|
30
+ a = read_entry_optional('ssh.username').if_present(a) { |v| "#{v}@#{a}" }
31
+ a = read_entry_optional('ssh.port').if_present(a) { |v| "#{a}:#{v}" }
32
+ "ssh://#{a}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Database
8
+ DEFAULT_HOSTNAME = '127.0.0.1'
9
+ DEFAULT_PORTS = {
10
+ 'postgresql' => 5432,
11
+ 'mysql' => 3306,
12
+ 'oracle' => 1521,
13
+ 'sqlserver' => 1433
14
+ }.freeze
15
+ DEFAULT_SYSTEM = 'postgresql'
16
+
17
+ def auto_database_name
18
+ inherited_entry_value(:database_id, 'database.name') || id
19
+ end
20
+
21
+ def auto_database_hostname
22
+ database_auto_common('hostname') || DEFAULT_HOSTNAME
23
+ end
24
+
25
+ def auto_database_password
26
+ database_auto_common('password')
27
+ end
28
+
29
+ def auto_database_port
30
+ database_auto_common('port') || database_port_by_system
31
+ end
32
+
33
+ def auto_database_username
34
+ database_auto_common('username')
35
+ end
36
+
37
+ def auto_database_system
38
+ database_auto_common('system') || DEFAULT_SYSTEM
39
+ end
40
+
41
+ private
42
+
43
+ def database_auto_common(suffix)
44
+ inherited_entry_value(:database_id, "database.#{suffix}") ||
45
+ inherited_entry_value(:host_id, "database.#{suffix}")
46
+ end
47
+
48
+ def database_port_by_system
49
+ read_entry_optional('database.system').if_present do |v|
50
+ DEFAULT_PORTS.fetch(v)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Filesystem
8
+ def auto_fs_path
9
+ inherited_entry_value(:host_id, :fs_path) { |v| v + '/' + id }
10
+ end
11
+
12
+ def auto_data_fs_path
13
+ inherited_entry_value(:host_id, :data_fs_path) { |v| v + '/' + id }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Instances
5
+ class Base
6
+ module AutoValues
7
+ module Source
8
+ def auto_source_instance_id
9
+ "#{application.id}_dev"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patches/object/asserts'
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/require_sub'
4
5
  require 'avm/configs'
6
+ ::EacRubyUtils.require_sub(__FILE__)
5
7
 
6
8
  module Avm
7
9
  module Instances
@@ -11,7 +13,11 @@ module Avm
11
13
  end
12
14
 
13
15
  def read_entry(entry_suffix, options = {})
14
- ::Avm.configs.read_entry(full_entry_path(entry_suffix), options)
16
+ entry(entry_suffix, options).value
17
+ end
18
+
19
+ def read_entry_optional(entry_suffix, options = {})
20
+ entry(entry_suffix, options).optional_value
15
21
  end
16
22
 
17
23
  def full_entry_path(entry_suffix)
@@ -20,6 +26,22 @@ module Avm
20
26
  end
21
27
  (path_prefix + entry_suffix).join('.')
22
28
  end
29
+
30
+ def inherited_entry_value(source_entry_suffix, target_entry_suffix, &block)
31
+ read_entry_optional(source_entry_suffix).if_present do |instance_id|
32
+ other_entry_value(instance_id, target_entry_suffix).if_present(&block)
33
+ end
34
+ end
35
+
36
+ def other_entry_value(instance_id, entry_suffix)
37
+ ::Avm::Instances::Base.by_id(instance_id).read_entry_optional(entry_suffix)
38
+ end
39
+
40
+ private
41
+
42
+ def entry(suffix, options)
43
+ ::Avm::Instances::Entries::EntryReader.new(self, suffix, options)
44
+ end
23
45
  end
24
46
  end
25
47
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Entries
8
+ class EntryReader
9
+ common_constructor :parent, :suffix, :options
10
+
11
+ def auto_value
12
+ parent.respond_to?(auto_value_method, true) ? parent.send(auto_value_method) : nil
13
+ end
14
+
15
+ def auto_value_method
16
+ "auto_#{suffix.to_s.gsub('.', '_')}"
17
+ end
18
+
19
+ def full_path
20
+ (parent.path_prefix + suffix_as_array).join('.')
21
+ end
22
+
23
+ def optional_value
24
+ read(required: false, noinput: true) || auto_value
25
+ end
26
+
27
+ def read(extra_options = {})
28
+ ::Avm.configs.read_entry(full_path, options.merge(extra_options))
29
+ end
30
+
31
+ def suffix_as_array
32
+ if suffix.is_a?(::Array)
33
+ suffix.dup
34
+ else
35
+ ::EacRubyUtils::PathsHash.parse_entry_key(suffix.to_s)
36
+ end
37
+ end
38
+
39
+ def value
40
+ optional_value || read
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -9,7 +9,7 @@ module Avm
9
9
  include ::EacRubyUtils::SimpleCache
10
10
 
11
11
  VARIABLE_DELIMITER = ::Regexp.quote('%%')
12
- VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z_][a-z0-9_]*)#{VARIABLE_DELIMITER}/i.freeze
12
+ VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
13
13
 
14
14
  attr_reader :path
15
15
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.16.0'
5
+ VERSION = '0.17.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -76,14 +76,14 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '0.15'
79
+ version: '0.16'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '0.15'
86
+ version: '0.16'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: filesize
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -132,14 +132,14 @@ dependencies:
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: 0.74.0
135
+ version: 0.76.0
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: 0.74.0
142
+ version: 0.76.0
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rubocop-rspec
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +202,13 @@ files:
202
202
  - lib/avm/instances.rb
203
203
  - lib/avm/instances/application.rb
204
204
  - lib/avm/instances/base.rb
205
+ - lib/avm/instances/base/auto_values.rb
206
+ - lib/avm/instances/base/auto_values/access.rb
207
+ - lib/avm/instances/base/auto_values/database.rb
208
+ - lib/avm/instances/base/auto_values/filesystem.rb
209
+ - lib/avm/instances/base/auto_values/source.rb
205
210
  - lib/avm/instances/entries.rb
211
+ - lib/avm/instances/entries/entry_reader.rb
206
212
  - lib/avm/patches.rb
207
213
  - lib/avm/patches/eac_launcher_git_base.rb
208
214
  - lib/avm/patches/object/template.rb