avm 0.31.0 → 0.34.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: aea575c3e0ebcc43678325a4a682ea17c915ecae1eb6d133335b3e94ace56ca3
4
- data.tar.gz: 2ed8fc21068a44f5ae816aa098a866650f32511b09afca2e75af2b620cd89f9b
3
+ metadata.gz: 7f010253f1247e81a5935385a2c1070e5d4217948b31258c5e4286d3b1453fee
4
+ data.tar.gz: 000a1a2a76b966b3f353c251cbb8ded41cf9719cf9b13f056f768d6a16d6c377
5
5
  SHA512:
6
- metadata.gz: 3c87d398c755f55f71a827167bfbe0131d08d5df55af5497ccc7fd239cd059e59c9f251dbe448ca13df30c31da76e147dc2bd8e0d1501130000a219313b5e39d
7
- data.tar.gz: e188963cfc504522f52eb86e7de7490427c194496c61e2d6771bdfdd697de9d9e6647cc0c1c772c6f19b3799bdd05c3054f999caa8168708a29e910d19398431
6
+ metadata.gz: a9f61d3c21cef4aaed1a8c5c4eecbcc20aab3247c8a28098f0aefff9818a578bb3e8450aff34b9b1bcced1ecbbb58ce3f011ee426d470e51cb840396fd98a8d8
7
+ data.tar.gz: c6019a2b01b64630a9c61d870e48d35a3e4ded56c6e67e1be74fdfa524d7700c72b55cae69a188ac1f3df318c8a0d7aca87c1eac7eda5f0f4b2be807c6da8069
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/instances/entries'
3
+ require 'avm/entries/base'
4
4
  require 'avm/registry'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
 
@@ -9,7 +9,7 @@ module Avm
9
9
  class Base
10
10
  enable_simple_cache
11
11
  require_sub __FILE__, include_modules: true
12
- include ::Avm::Instances::Entries
12
+ include ::Avm::Entries::Base
13
13
 
14
14
  LOCAL_INSTANCE_SUFFIX = 'dev'
15
15
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/node'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Entries
8
+ module AutoValues
9
+ class Entry
10
+ class << self
11
+ def auto_value_method_name(suffix)
12
+ "auto_#{suffix.to_s.gsub('.', '_')}"
13
+ end
14
+ end
15
+
16
+ common_constructor :entries_provider, :suffix
17
+
18
+ def auto_value_method
19
+ self.class.auto_value_method_name(suffix)
20
+ end
21
+
22
+ def found?
23
+ entries_provider.respond_to?(auto_value_method, true)
24
+ end
25
+
26
+ def value
27
+ entries_provider.if_respond(auto_value_method)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Entries
7
+ module AutoValues
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
- require 'avm/instances/entry'
4
+ require 'avm/entries/entry'
5
5
 
6
6
  module Avm
7
- module Instances
8
- module Entries
7
+ module Entries
8
+ module Base
9
+ def entries_provider_id
10
+ id
11
+ end
12
+
9
13
  def entry(suffix, options = {})
10
- ::Avm::Instances::Entry.new(self, suffix, options)
14
+ ::Avm::Entries::Entry.new(self, suffix, options)
11
15
  end
12
16
 
13
17
  def path_prefix
14
- @path_prefix ||= [id].freeze
18
+ @path_prefix ||= [entries_provider_id].freeze
15
19
  end
16
20
 
17
21
  def read_entry(entry_suffix, options = {})
@@ -1,25 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/entries/auto_values/entry'
3
4
  require 'eac_config/node'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
 
6
7
  module Avm
7
- module Instances
8
+ module Entries
8
9
  class Entry
9
- class << self
10
- def auto_value_method_name(suffix)
11
- "auto_#{suffix.to_s.gsub('.', '_')}"
12
- end
13
- end
14
-
15
10
  common_constructor :parent, :suffix, :options
16
11
 
17
12
  def auto_value
18
- parent.respond_to?(auto_value_method, true) ? parent.send(auto_value_method) : nil
19
- end
20
-
21
- def auto_value_method
22
- self.class.auto_value_method_name(suffix)
13
+ ::Avm::Entries::AutoValues::Entry.new(parent, suffix).value
23
14
  end
24
15
 
25
16
  def full_path
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Entries
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -6,11 +6,11 @@ module Avm
6
6
  module AutoValues
7
7
  module Admin
8
8
  def auto_admin_email
9
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.email')
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'admin.email')
10
10
  end
11
11
 
12
12
  def auto_admin_name
13
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'admin.name')
13
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'admin.name')
14
14
  end
15
15
  end
16
16
  end
@@ -61,7 +61,7 @@ module Avm
61
61
  def database_auto_common(suffix)
62
62
  database_key = ::Avm::Instances::EntryKeys.const_get("database_#{suffix}".upcase)
63
63
  inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID, database_key) ||
64
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, database_key)
64
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, database_key)
65
65
  end
66
66
 
67
67
  def database_port_by_system
@@ -8,29 +8,30 @@ module Avm
8
8
  module AutoValues
9
9
  module Filesystem
10
10
  def auto_fs_path
11
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
12
12
  ::Avm::Instances::EntryKeys::FS_PATH) { |v| v + '/' + id }
13
13
  end
14
14
 
15
15
  def auto_data_fs_path
16
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
16
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
17
17
  ::Avm::Instances::EntryKeys::DATA_FS_PATH) { |v| v + '/' + id }
18
18
  end
19
19
 
20
20
  def auto_fs_url
21
- auto_fs_url_with_ssh || auto_fs_url_without_ssh
21
+ auto_fs_url_with_install || auto_fs_url_without_install
22
22
  end
23
23
 
24
- def auto_fs_url_with_ssh
25
- read_entry_optional('ssh.url').if_present do |ssh_url|
24
+ def auto_fs_url_with_install
25
+ read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_URL)
26
+ .if_present do |install_url|
26
27
  read_entry_optional('fs_path').if_present do |fs_path|
27
- "#{ssh_url}#{fs_path}"
28
+ "#{install_url}#{fs_path}"
28
29
  end
29
30
  end
30
31
  end
31
32
 
32
- def auto_fs_url_without_ssh
33
- return nil if read_entry_optional('ssh.url').present?
33
+ def auto_fs_url_without_install
34
+ return nil if read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_URL).present?
34
35
 
35
36
  read_entry_optional('fs_path').if_present do |fs_path|
36
37
  "file://#{fs_path}"
@@ -12,22 +12,22 @@ module Avm
12
12
  end
13
13
 
14
14
  def auto_install_hostname
15
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
15
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
16
16
  ::Avm::Instances::EntryKeys::INSTALL_HOSTNAME)
17
17
  end
18
18
 
19
19
  def auto_install_port
20
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
20
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
21
21
  ::Avm::Instances::EntryKeys::INSTALL_PORT) || 22
22
22
  end
23
23
 
24
24
  def auto_install_username
25
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
25
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
26
26
  ::Avm::Instances::EntryKeys::INSTALL_USERNAME)
27
27
  end
28
28
 
29
29
  def auto_install_url
30
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
30
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
31
31
  ::Avm::Instances::EntryKeys::INSTALL_URL) ||
32
32
  auto_install_url_by_parts
33
33
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/instances/entry'
3
+ require 'avm/entries/auto_values/entry'
4
+ require 'avm/entries/entry'
4
5
  require 'avm/instances/entry_keys'
5
6
 
6
7
  module Avm
@@ -11,15 +12,15 @@ module Avm
11
12
  ::Avm::Instances::EntryKeys.all.select { |c| c.to_s.start_with?('mailer.') }
12
13
  .reject { |c| c == ::Avm::Instances::EntryKeys::MAILER_ID }
13
14
  .each do |mailer_key|
14
- define_method ::Avm::Instances::Entry.auto_value_method_name(mailer_key) do
15
+ define_method ::Avm::Entries::AutoValues::Entry.auto_value_method_name(mailer_key) do
15
16
  mailer_auto_common(mailer_key)
16
17
  end
17
18
  end
18
19
 
19
20
  def auto_mailer_id
20
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID,
21
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
21
22
  ::Avm::Instances::EntryKeys::MAILER_ID) ||
22
- read_entry_optional(::Avm::Instances::EntryKeys::HOST_ID)
23
+ read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_ID)
23
24
  end
24
25
 
25
26
  private
@@ -6,7 +6,7 @@ module Avm
6
6
  module AutoValues
7
7
  module Ruby
8
8
  def auto_ruby_version
9
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'ruby.version')
9
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'ruby.version')
10
10
  end
11
11
  end
12
12
  end
@@ -8,12 +8,12 @@ module Avm
8
8
  module AutoValues
9
9
  module System
10
10
  def auto_system_username
11
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.username') ||
12
- read_entry_optional('ssh.username')
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'system.username') ||
12
+ read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_USERNAME)
13
13
  end
14
14
 
15
15
  def auto_system_groupname
16
- inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, 'system.groupname') ||
16
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'system.groupname') ||
17
17
  read_entry_optional('system.username')
18
18
  end
19
19
  end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub(__FILE__)
3
+ require 'eac_ruby_utils/core_ext'
5
4
 
6
5
  module Avm
7
6
  module Instances
8
7
  class Base
9
8
  module AutoValues
10
- extend ::ActiveSupport::Concern
9
+ require_sub __FILE__
11
10
 
12
- included do
11
+ common_concern do
13
12
  %w[Admin Data Database Filesystem Install Mailer Ruby Source System Web]
14
13
  .each do |class_name|
15
14
  include const_get(class_name)
@@ -4,7 +4,7 @@ require 'avm/with/application_stereotype'
4
4
  require 'avm/with/extra_subcommands'
5
5
  require 'eac_ruby_utils/require_sub'
6
6
  require 'eac_ruby_utils/simple_cache'
7
- require 'avm/instances/entries'
7
+ require 'avm/entries/base'
8
8
 
9
9
  module Avm
10
10
  module Instances
@@ -13,7 +13,7 @@ module Avm
13
13
  enable_listable
14
14
  enable_simple_cache
15
15
  require_sub __FILE__, include_modules: true
16
- include ::Avm::Instances::Entries
16
+ include ::Avm::Entries::Base
17
17
  include ::Avm::With::ExtraSubcommands
18
18
  include ::Avm::With::ApplicationStereotype
19
19
 
@@ -51,11 +51,11 @@ module Avm
51
51
  end
52
52
 
53
53
  def host_env_uncached
54
- access = read_entry(:access, list: ::Avm::Instances::Base.lists.access.values)
55
- case access
54
+ install_uri = entry(::Avm::Instances::EntryKeys::INSTALL_URL).value.to_uri
55
+ case install_uri.scheme
56
56
  when 'local' then ::EacRubyUtils::Envs.local
57
- when 'ssh' then ::EacRubyUtils::Envs.ssh(read_entry('ssh.url'))
58
- else raise("Unmapped access value: \"#{access}\"")
57
+ when 'ssh' then ::EacRubyUtils::Envs.ssh(install_uri)
58
+ else raise("Unmapped access value: \"#{install_uri}\"")
59
59
  end
60
60
  end
61
61
 
@@ -44,12 +44,12 @@ module Avm
44
44
  end
45
45
 
46
46
  {
47
- '' => %w[data_fs_path fs_path host_id name source_instance_id],
47
+ '' => %w[data_fs_path fs_path name source_instance_id],
48
48
  admin: URI_FIELDS + %w[api_key],
49
49
  database: URI_FIELDS + %w[id limit name system timeout extra],
50
50
  docker: %w[registry],
51
51
  fs: %w[url],
52
- install: URI_FIELDS,
52
+ install: URI_FIELDS + %w[id],
53
53
  mailer: {
54
54
  '' => %w[id from reply_to],
55
55
  smtp: URI_FIELDS + %w[address domain authentication openssl_verify_mode starttls_auto tls]
@@ -8,8 +8,9 @@ module Avm
8
8
  class SourceGenerators < ::Avm::Registry::FromGems
9
9
  # @return [Avm::Instances::Base, nil]
10
10
  def class_detect(klass, detect_args)
11
- stereotype_name, target_path = detect_args
12
- klass.application_stereotype.name == stereotype_name ? klass.new(target_path) : nil
11
+ detect_args = detect_args.dup
12
+ stereotype_name = detect_args.shift
13
+ klass.application_stereotype.name == stereotype_name ? klass.new(*detect_args) : nil
13
14
  end
14
15
  end
15
16
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/source_generators/option_list'
3
4
  require 'avm/with/application_stereotype'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
 
@@ -7,8 +8,22 @@ module Avm
7
8
  module SourceGenerators
8
9
  class Base
9
10
  include ::Avm::With::ApplicationStereotype
10
- common_constructor :target_path do
11
+
12
+ class << self
13
+ # @return [Avm::SourceGenerators::OptionList]
14
+ def option_list
15
+ Avm::SourceGenerators::OptionList.new
16
+ end
17
+ end
18
+
19
+ common_constructor :target_path, :options, default: [{}] do
11
20
  self.target_path = target_path.to_pathname
21
+ self.options = option_list.validate(options)
22
+ end
23
+
24
+ # @return [Avm::SourceGenerators::OptionList]
25
+ def option_list
26
+ self.class.option_list
12
27
  end
13
28
 
14
29
  def perform
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module SourceGenerators
5
+ class Option
6
+ common_constructor :name, :description, default: [nil] do
7
+ self.name = name.to_sym
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/source_generators/option'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module SourceGenerators
8
+ class OptionList
9
+ enable_immutable
10
+ immutable_accessor :option, type: :array
11
+
12
+ alias immutable_option option
13
+
14
+ def option(*args)
15
+ immutable_option(::Avm::SourceGenerators::Option.new(*args))
16
+ end
17
+
18
+ # @return [Hash<Symbol, String>]
19
+ def validate(options_hash)
20
+ options_hash.transform_keys { |k| validate_option(k) }
21
+ end
22
+
23
+ def validate_option(option_name)
24
+ option_name = option_name.to_sym
25
+
26
+ return option_name if options.any? { |option| option.name == option_name }
27
+
28
+ raise "No option found with name \"#{option_name}\""
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry'
4
+ require 'eac_cli/core_ext'
5
+
6
+ module Avm
7
+ module SourceGenerators
8
+ class Runner
9
+ OPTION_NAME_VALUE_SEPARATOR = ':'
10
+
11
+ runner_with :help do
12
+ arg_opt '-o', '--option', 'Option for generator.', repeat: true, optional: true
13
+ pos_arg :stereotype_name
14
+ pos_arg :target_path
15
+ end
16
+
17
+ def run
18
+ start_banner
19
+ generate
20
+ end
21
+
22
+ def generate
23
+ infom 'Generating...'
24
+ generator.perform
25
+ success "Source generated in \"#{generator.target_path}\""
26
+ end
27
+
28
+ def start_banner
29
+ infov 'Stereotype', stereotype_name
30
+ infov 'Target path', target_path
31
+ infov 'Generator', generator.class
32
+ end
33
+
34
+ def generator_uncached
35
+ ::Avm::Registry.source_generators
36
+ .detect_optional(stereotype_name, target_path, options) ||
37
+ fatal_error("No generator found for stereotype \"#{stereotype_name}\"")
38
+ end
39
+
40
+ delegate :stereotype_name, to: :parsed
41
+
42
+ # @return [Hash<String, String>]
43
+ def options
44
+ parsed.option.map { |v| v.split(OPTION_NAME_VALUE_SEPARATOR) }.to_h
45
+ end
46
+
47
+ def target_path
48
+ parsed.target_path.to_pathname
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module Sources
7
+ class Runner
8
+ runner_with :help, :subcommands do
9
+ desc 'Root command for sources.'
10
+ arg_opt '-C', '--path', 'Path to the source.', default: '.'
11
+ subcommands
12
+ end
13
+
14
+ def extra_available_subcommands
15
+ optional_source.if_present({}, &:extra_available_subcommands)
16
+ end
17
+
18
+ def source_banner
19
+ infov 'Source', source
20
+ end
21
+
22
+ # @return [Pathname]
23
+ def source_path
24
+ parsed.path.to_pathname
25
+ end
26
+
27
+ private
28
+
29
+ def source_uncached
30
+ ::Avm::Registry.sources.detect(source_path)
31
+ end
32
+
33
+ def optional_source_uncached
34
+ ::Avm::Registry.sources.detect_optional(source_path)
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.31.0'
4
+ VERSION = '0.34.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -213,6 +213,11 @@ files:
213
213
  - lib/avm/docker/container.rb
214
214
  - lib/avm/docker/image.rb
215
215
  - lib/avm/docker/runner.rb
216
+ - lib/avm/entries.rb
217
+ - lib/avm/entries/auto_values.rb
218
+ - lib/avm/entries/auto_values/entry.rb
219
+ - lib/avm/entries/base.rb
220
+ - lib/avm/entries/entry.rb
216
221
  - lib/avm/executables.rb
217
222
  - lib/avm/instances.rb
218
223
  - lib/avm/instances/base.rb
@@ -230,8 +235,6 @@ files:
230
235
  - lib/avm/instances/base/dockerizable.rb
231
236
  - lib/avm/instances/base/entry_keys.rb
232
237
  - lib/avm/instances/docker_image.rb
233
- - lib/avm/instances/entries.rb
234
- - lib/avm/instances/entry.rb
235
238
  - lib/avm/instances/entry_keys.rb
236
239
  - lib/avm/instances/runner.rb
237
240
  - lib/avm/jobs.rb
@@ -269,6 +272,9 @@ files:
269
272
  - lib/avm/self/instance/entry_keys.rb
270
273
  - lib/avm/source_generators.rb
271
274
  - lib/avm/source_generators/base.rb
275
+ - lib/avm/source_generators/option.rb
276
+ - lib/avm/source_generators/option_list.rb
277
+ - lib/avm/source_generators/runner.rb
272
278
  - lib/avm/sources.rb
273
279
  - lib/avm/sources/base.rb
274
280
  - lib/avm/sources/base/configuration.rb
@@ -280,6 +286,7 @@ files:
280
286
  - lib/avm/sources/base/testing.rb
281
287
  - lib/avm/sources/configuration.rb
282
288
  - lib/avm/sources/configuration/rubocop.rb
289
+ - lib/avm/sources/runner.rb
283
290
  - lib/avm/sources/tests.rb
284
291
  - lib/avm/sources/tests/builder.rb
285
292
  - lib/avm/sources/tests/performer.rb