avm 0.33.0 → 0.35.1

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: a138a71c9d6253cf06cb24540bdb765dff78cea3cd9a93689952bdb60795833e
4
- data.tar.gz: fa16c54d070882c7c3babda535010f0cfd66727a6c126e65a0b7da58b7e328d3
3
+ metadata.gz: 4ebc7e5eed486245f3a85a5dba5ecaa430af32cc398b9ef8fffd7c111cab8dd6
4
+ data.tar.gz: bfc1ad0135ec283b838820e3e002e465a2f2770ab848909d7c04cb3ed2ebc92f
5
5
  SHA512:
6
- metadata.gz: 9bf6e089f8eba0bfed6ad0783c28948d1ee2653f3940c879e8e1d6451ff49009f639dff737c606e5d5baafd45108cf645b8dcc772481f2fb116f73cbb90586b1
7
- data.tar.gz: fd7986157d7b494b934ebe1d491040252d2b2a73cc000eba1b25e29bbf26bc935a9ab07b54ab8e5fca0a42fefbea4ee7e82820c635d990d5194b6e44976ec288
6
+ metadata.gz: 1059898047cbf217a4b7e21f9e18d18ba9a6a8f81216803c27cab4b87654ce4fbeffb044aeebb7a1b92931add5e69264fa9fcdbb7683aa75837e38464d3fe80f
7
+ data.tar.gz: 3998adffe3154008f6b0fd14234d1d400a1efe437e132ecd032076b665054d27b26dde8fe62d5f058f507cf9b5470d46d88470bcbbd2a4a557859ccb295f35b4
@@ -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,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
@@ -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
@@ -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
@@ -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]
@@ -7,10 +7,12 @@ module Avm
7
7
  module Instances
8
8
  class Runner < ::Avm::Runners::Base
9
9
  class << self
10
- def instance_class
11
- ::Avm.const_get(stereotype_name).const_get('Instance')
10
+ def application_stereotype
11
+ ::Avm::Registry.application_stereotypes.detect(stereotype_name)
12
12
  end
13
13
 
14
+ delegate :instance_class, to: :application_stereotype
15
+
14
16
  def stereotype_module
15
17
  ::Avm.const_get(stereotype_name)
16
18
  end
@@ -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.33.0'
4
+ VERSION = '0.35.1'
5
5
  end
@@ -5,9 +5,7 @@ require 'eac_ruby_utils/core_ext'
5
5
  module Avm
6
6
  module With
7
7
  module ApplicationStereotype
8
- common_concern do
9
- include ClassMethods
10
- end
8
+ common_concern
11
9
 
12
10
  module ClassMethods
13
11
  # @return [Avm::ApplicationStereotype::Base]
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.33.0
4
+ version: 0.35.1
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-04 00:00:00.000000000 Z
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.27'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.27.6
22
+ version: 0.27.8
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.27'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.27.6
32
+ version: 0.27.8
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_config
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,62 +50,74 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.3'
53
+ version: '0.4'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.2
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - "~>"
59
62
  - !ruby/object:Gem::Version
60
- version: '0.3'
63
+ version: '0.4'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.4.2
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: eac_git
63
69
  requirement: !ruby/object:Gem::Requirement
64
70
  requirements:
65
71
  - - "~>"
66
72
  - !ruby/object:Gem::Version
67
- version: '0.6'
73
+ version: '0.12'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.12.1
68
77
  type: :runtime
69
78
  prerelease: false
70
79
  version_requirements: !ruby/object:Gem::Requirement
71
80
  requirements:
72
81
  - - "~>"
73
82
  - !ruby/object:Gem::Version
74
- version: '0.6'
83
+ version: '0.12'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 0.12.1
75
87
  - !ruby/object:Gem::Dependency
76
88
  name: eac_ruby_utils
77
89
  requirement: !ruby/object:Gem::Requirement
78
90
  requirements:
79
91
  - - "~>"
80
92
  - !ruby/object:Gem::Version
81
- version: '0.97'
93
+ version: '0.98'
82
94
  type: :runtime
83
95
  prerelease: false
84
96
  version_requirements: !ruby/object:Gem::Requirement
85
97
  requirements:
86
98
  - - "~>"
87
99
  - !ruby/object:Gem::Version
88
- version: '0.97'
100
+ version: '0.98'
89
101
  - !ruby/object:Gem::Dependency
90
102
  name: eac_templates
91
103
  requirement: !ruby/object:Gem::Requirement
92
104
  requirements:
93
105
  - - "~>"
94
106
  - !ruby/object:Gem::Version
95
- version: '0.1'
107
+ version: '0.3'
96
108
  - - ">="
97
109
  - !ruby/object:Gem::Version
98
- version: 0.1.1
110
+ version: 0.3.1
99
111
  type: :runtime
100
112
  prerelease: false
101
113
  version_requirements: !ruby/object:Gem::Requirement
102
114
  requirements:
103
115
  - - "~>"
104
116
  - !ruby/object:Gem::Version
105
- version: '0.1'
117
+ version: '0.3'
106
118
  - - ">="
107
119
  - !ruby/object:Gem::Version
108
- version: 0.1.1
120
+ version: 0.3.1
109
121
  - !ruby/object:Gem::Dependency
110
122
  name: filesize
111
123
  requirement: !ruby/object:Gem::Requirement
@@ -126,20 +138,20 @@ dependencies:
126
138
  requirements:
127
139
  - - "~>"
128
140
  - !ruby/object:Gem::Version
129
- version: '1.3'
141
+ version: '1.4'
130
142
  - - ">="
131
143
  - !ruby/object:Gem::Version
132
- version: 1.3.1
144
+ version: 1.4.2
133
145
  type: :runtime
134
146
  prerelease: false
135
147
  version_requirements: !ruby/object:Gem::Requirement
136
148
  requirements:
137
149
  - - "~>"
138
150
  - !ruby/object:Gem::Version
139
- version: '1.3'
151
+ version: '1.4'
140
152
  - - ">="
141
153
  - !ruby/object:Gem::Version
142
- version: 1.3.1
154
+ version: 1.4.2
143
155
  - !ruby/object:Gem::Dependency
144
156
  name: minitar
145
157
  requirement: !ruby/object:Gem::Requirement
@@ -216,8 +228,10 @@ files:
216
228
  - lib/avm/entries.rb
217
229
  - lib/avm/entries/auto_values.rb
218
230
  - lib/avm/entries/auto_values/entry.rb
231
+ - lib/avm/entries/auto_values/uri_entry.rb
219
232
  - lib/avm/entries/base.rb
220
233
  - lib/avm/entries/entry.rb
234
+ - lib/avm/entries/uri_builder.rb
221
235
  - lib/avm/executables.rb
222
236
  - lib/avm/instances.rb
223
237
  - lib/avm/instances/base.rb
@@ -230,7 +244,6 @@ files:
230
244
  - lib/avm/instances/base/auto_values/mailer.rb
231
245
  - lib/avm/instances/base/auto_values/ruby.rb
232
246
  - lib/avm/instances/base/auto_values/source.rb
233
- - lib/avm/instances/base/auto_values/system.rb
234
247
  - lib/avm/instances/base/auto_values/web.rb
235
248
  - lib/avm/instances/base/dockerizable.rb
236
249
  - lib/avm/instances/base/entry_keys.rb
@@ -272,6 +285,9 @@ files:
272
285
  - lib/avm/self/instance/entry_keys.rb
273
286
  - lib/avm/source_generators.rb
274
287
  - lib/avm/source_generators/base.rb
288
+ - lib/avm/source_generators/option.rb
289
+ - lib/avm/source_generators/option_list.rb
290
+ - lib/avm/source_generators/runner.rb
275
291
  - lib/avm/sources.rb
276
292
  - lib/avm/sources/base.rb
277
293
  - lib/avm/sources/base/configuration.rb
@@ -283,6 +299,7 @@ files:
283
299
  - lib/avm/sources/base/testing.rb
284
300
  - lib/avm/sources/configuration.rb
285
301
  - lib/avm/sources/configuration/rubocop.rb
302
+ - lib/avm/sources/runner.rb
286
303
  - lib/avm/sources/tests.rb
287
304
  - lib/avm/sources/tests/builder.rb
288
305
  - 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