avm 0.32.0 → 0.35.0

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: fc4f095582fb4fb51a80f667437b95281791bf218ba89e43ff402e337baaeb3a
4
- data.tar.gz: 3b4a59e42bf16ab8ace7031604f43f7e9efb876836c4b3bc33342b1862ba7fa9
3
+ metadata.gz: 8d1057f254c35e9a58a3e175d41bc3269a1870a436ae6f9c4906d1f0c1235e74
4
+ data.tar.gz: 4954952889777c08c9b0af69cf1c10b151e998b54a866c080960558cef5c83cb
5
5
  SHA512:
6
- metadata.gz: ab5e8effc7ce4575c18922fa0c777b2e61bd97cf20cfdb40981a81b166970e00b7fdd3d49b16b3155715743b59b063585e5d8bbc4b7c6edab7c2927597dc36e7
7
- data.tar.gz: 7cfaaaf7877b87c4a5de68d4c84ae70c1424f6287635b97b26468f97350d9000e858c1559758eabb8004b98765574cf63d928d8c6f3f609129c68bf5f4a19a98
6
+ metadata.gz: f5e770babac5244337114c9c9a537d1d9d8e589d64850feced6f699d12b789b82a7281e878a115dbc83476b60a22f27badd800cd73045bf8fa9af3f855c88cd5
7
+ data.tar.gz: 411a518bf695992eb94aac4c5765f553bc2355f44bac229712809a33eb9ceb87c36247feb9f832928b8e40516d3d6f4a2b153989965f1ff48837543919dbc30b
@@ -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,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/entries/uri_builder'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Entries
8
+ module AutoValues
9
+ class UriEntry
10
+ common_constructor :entries_provider, :suffix
11
+
12
+ def found?
13
+ value.present?
14
+ end
15
+
16
+ def value
17
+ ::Avm::Entries::UriBuilder.from_all_fields do |field_name|
18
+ entries_provider.entry([suffix, field_name]).value
19
+ end.to_uri.to_s
20
+ end
21
+ end
22
+ end
23
+ end
24
+ 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,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Entries
7
+ class UriBuilder
8
+ require_sub __FILE__
9
+
10
+ FIELDS = %w[scheme user password host port path query fragment].freeze
11
+ FIELDS_TRANSLATIONS = {
12
+ username: :user, hostname: :host
13
+ }.freeze
14
+ ENTRIES_FIELDS = FIELDS.map do |field|
15
+ FIELDS_TRANSLATIONS.key(field.to_sym).if_present(field).to_s
16
+ end
17
+
18
+ class << self
19
+ def from_all_fields(&block)
20
+ r = new
21
+ ENTRIES_FIELDS.each do |field_name|
22
+ field_value = block.call(field_name)
23
+ r.field_set(field_name, field_value) if field_value.present?
24
+ end
25
+ r
26
+ end
27
+
28
+ def from_source(source)
29
+ if source.is_a?(::Addressable::URI)
30
+ from_source_uri(source)
31
+ elsif source.blank?
32
+ new
33
+ else
34
+ raise "Unexpected source: #{source}"
35
+ end
36
+ end
37
+
38
+ def from_source_uri(source_uri)
39
+ new(source_uri.to_hash)
40
+ end
41
+ end
42
+
43
+ common_constructor :data, default: [{}]
44
+
45
+ def field_get(name)
46
+ data[name.to_sym].if_present(&:to_s)
47
+ end
48
+
49
+ def field_set(field, value)
50
+ tfield = translate_field(field)
51
+ if FIELDS.include?(tfield)
52
+ main_field_set(tfield, value)
53
+ else
54
+ sub_field_set(tfield, value)
55
+ end
56
+ end
57
+
58
+ def translate_field(field)
59
+ if FIELDS_TRANSLATIONS.key?(field.to_sym)
60
+ FIELDS_TRANSLATIONS.fetch(field.to_sym).to_s
61
+ else
62
+ field.to_s
63
+ end
64
+ end
65
+
66
+ # @return [Addressable::URI, nil]
67
+ def to_uri
68
+ to_required_uri
69
+ rescue ::Addressable::URI::InvalidURIError
70
+ nil
71
+ end
72
+
73
+ # @return [Addressable::URI]
74
+ def to_required_uri
75
+ ::Addressable::URI.new(FIELDS.map { |f| [f.to_sym, field_get(f)] }.to_h)
76
+ end
77
+
78
+ private
79
+
80
+ def main_field_set(name, value)
81
+ data[name.to_sym] = value
82
+ end
83
+ end
84
+ end
85
+ end
@@ -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
@@ -7,8 +7,10 @@ module Avm
7
7
  class Base
8
8
  module AutoValues
9
9
  module Install
10
- def auto_access
11
- read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_URL).present? ? 'ssh' : 'local'
10
+ def auto_install_groupname
11
+ inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID,
12
+ ::Avm::Instances::EntryKeys::INSTALL_GROUPNAME) ||
13
+ read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_USERNAME)
12
14
  end
13
15
 
14
16
  def auto_install_hostname
@@ -33,13 +35,8 @@ module Avm
33
35
  end
34
36
 
35
37
  def auto_install_url_by_parts
36
- read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_HOSTNAME).if_present do |a|
37
- a = read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_USERNAME)
38
- .if_present(a) { |v| "#{v}@#{a}" }
39
- a = read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_PORT)
40
- .if_present(a) { |v| "#{a}:#{v}" }
41
- "ssh://#{a}"
42
- end
38
+ require 'avm/entries/auto_values/uri_entry'
39
+ ::Avm::Entries::AutoValues::UriEntry.new(self, 'install').value
43
40
  end
44
41
  end
45
42
  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,7 +12,7 @@ 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
@@ -6,14 +6,8 @@ module Avm
6
6
  module Instances
7
7
  class Base
8
8
  module AutoValues
9
- require_sub __FILE__
10
-
11
- common_concern do
12
- %w[Admin Data Database Filesystem Install Mailer Ruby Source System Web]
13
- .each do |class_name|
14
- include const_get(class_name)
15
- end
16
- end
9
+ require_sub __FILE__, include_modules: true
10
+ common_concern
17
11
  end
18
12
  end
19
13
  end
@@ -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
 
@@ -49,7 +49,7 @@ module Avm
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 + %w[id],
52
+ install: URI_FIELDS + %w[id groupname],
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.32.0'
4
+ VERSION = '0.35.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.32.0
4
+ version: 0.35.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-03 00:00:00.000000000 Z
11
+ date: 2022-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -213,6 +213,13 @@ 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/auto_values/uri_entry.rb
220
+ - lib/avm/entries/base.rb
221
+ - lib/avm/entries/entry.rb
222
+ - lib/avm/entries/uri_builder.rb
216
223
  - lib/avm/executables.rb
217
224
  - lib/avm/instances.rb
218
225
  - lib/avm/instances/base.rb
@@ -225,13 +232,10 @@ files:
225
232
  - lib/avm/instances/base/auto_values/mailer.rb
226
233
  - lib/avm/instances/base/auto_values/ruby.rb
227
234
  - lib/avm/instances/base/auto_values/source.rb
228
- - lib/avm/instances/base/auto_values/system.rb
229
235
  - lib/avm/instances/base/auto_values/web.rb
230
236
  - lib/avm/instances/base/dockerizable.rb
231
237
  - lib/avm/instances/base/entry_keys.rb
232
238
  - lib/avm/instances/docker_image.rb
233
- - lib/avm/instances/entries.rb
234
- - lib/avm/instances/entry.rb
235
239
  - lib/avm/instances/entry_keys.rb
236
240
  - lib/avm/instances/runner.rb
237
241
  - lib/avm/jobs.rb
@@ -269,6 +273,9 @@ files:
269
273
  - lib/avm/self/instance/entry_keys.rb
270
274
  - lib/avm/source_generators.rb
271
275
  - lib/avm/source_generators/base.rb
276
+ - lib/avm/source_generators/option.rb
277
+ - lib/avm/source_generators/option_list.rb
278
+ - lib/avm/source_generators/runner.rb
272
279
  - lib/avm/sources.rb
273
280
  - lib/avm/sources/base.rb
274
281
  - lib/avm/sources/base/configuration.rb
@@ -280,6 +287,7 @@ files:
280
287
  - lib/avm/sources/base/testing.rb
281
288
  - lib/avm/sources/configuration.rb
282
289
  - lib/avm/sources/configuration/rubocop.rb
290
+ - lib/avm/sources/runner.rb
283
291
  - lib/avm/sources/tests.rb
284
292
  - lib/avm/sources/tests/builder.rb
285
293
  - lib/avm/sources/tests/performer.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'addressable'
4
-
5
- module Avm
6
- module Instances
7
- class Base
8
- module AutoValues
9
- module System
10
- def auto_system_username
11
- inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'system.username') ||
12
- read_entry_optional(::Avm::Instances::EntryKeys::INSTALL_USERNAME)
13
- end
14
-
15
- def auto_system_groupname
16
- inherited_entry_value(::Avm::Instances::EntryKeys::INSTALL_ID, 'system.groupname') ||
17
- read_entry_optional('system.username')
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end