power_stencil 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +198 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/update_plugin_template +79 -0
- data/doc/builds.md +267 -0
- data/doc/entities.md +964 -0
- data/doc/example_use_cases.md +59 -0
- data/doc/images/power-stencil-entity-build.svg +481 -0
- data/doc/images/power-stencil-entity-creation.svg +375 -0
- data/doc/images/power-stencil-simple-flow.svg +265 -0
- data/doc/plugins.md +169 -0
- data/doc/templates.md +333 -0
- data/etc/base_commands_definition.yml +259 -0
- data/etc/meta_templates/plugin_seed/etc/command_line.yaml +12 -0
- data/etc/meta_templates/plugin_seed/etc/plugin_config.yaml +4 -0
- data/etc/meta_templates/plugin_seed/etc/templates/.git_keep +0 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}.rb.erb +34 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/plugin_helper.rb.erb +17 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb +3 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb +19 -0
- data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +36 -0
- data/etc/power_stencil.yaml +92 -0
- data/etc/templates/plugin_definition/.gitignore +11 -0
- data/etc/templates/plugin_definition/.rspec +3 -0
- data/etc/templates/plugin_definition/.travis.yml +5 -0
- data/etc/templates/plugin_definition/CODE_OF_CONDUCT.md +74 -0
- data/etc/templates/plugin_definition/Gemfile +6 -0
- data/etc/templates/plugin_definition/LICENSE.txt +21 -0
- data/etc/templates/plugin_definition/README.md +43 -0
- data/etc/templates/plugin_definition/Rakefile +6 -0
- data/etc/templates/plugin_definition/bin/console +14 -0
- data/etc/templates/plugin_definition/bin/setup +8 -0
- data/etc/templates/plugin_definition/etc/command_line.yaml +12 -0
- data/etc/templates/plugin_definition/etc/plugin_config.yaml +4 -0
- data/etc/templates/plugin_definition/etc/templates/.git_keep +1 -0
- data/etc/templates/plugin_definition/lib/{entity}.rb.erb +34 -0
- data/etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
- data/etc/templates/plugin_definition/lib/{entity}/plugin_helper.rb.erb +17 -0
- data/etc/templates/plugin_definition/lib/{entity}/version.rb.erb +3 -0
- data/etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb +19 -0
- data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +36 -0
- data/etc/templates/plugin_definition/spec/spec_helper.rb +14 -0
- data/etc/templates/plugin_definition/spec/{entity}_spec.rb +9 -0
- data/etc/templates/project/.copy_ignore +2 -0
- data/etc/templates/project/.gitignore.erb +6 -0
- data/etc/templates/project/.ps_project/entities/.gitkeep +0 -0
- data/etc/templates/project/.ps_project/entities/README.md +11 -0
- data/etc/templates/project/.ps_project/entity_definitions/.gitkeep +0 -0
- data/etc/templates/project/.ps_project/entity_definitions/README.md +15 -0
- data/etc/templates/project/.ps_project/personal-config.yaml +8 -0
- data/etc/templates/project/.ps_project/plugins/.gitkeep +0 -0
- data/etc/templates/project/.ps_project/templates-templates/.gitkeep +0 -0
- data/etc/templates/project/.ps_project/templates-templates/README.md +13 -0
- data/etc/templates/project/.ps_project/user_entities/.gitkeep +0 -0
- data/etc/templates/project/.ps_project/user_entities/README.md +12 -0
- data/etc/templates/project/.ps_project/versioned-config.yaml +6 -0
- data/etc/templates/simple_exec/main.sh +4 -0
- data/exe/power_stencil +28 -0
- data/lib/power_stencil.rb +53 -0
- data/lib/power_stencil/command_processors/build.rb +43 -0
- data/lib/power_stencil/command_processors/check.rb +35 -0
- data/lib/power_stencil/command_processors/create.rb +70 -0
- data/lib/power_stencil/command_processors/delete.rb +38 -0
- data/lib/power_stencil/command_processors/edit.rb +35 -0
- data/lib/power_stencil/command_processors/entity_helper.rb +105 -0
- data/lib/power_stencil/command_processors/get.rb +22 -0
- data/lib/power_stencil/command_processors/info.rb +41 -0
- data/lib/power_stencil/command_processors/init.rb +47 -0
- data/lib/power_stencil/command_processors/new_plugin.rb +31 -0
- data/lib/power_stencil/command_processors/root.rb +27 -0
- data/lib/power_stencil/command_processors/shell.rb +37 -0
- data/lib/power_stencil/command_processors/trace_helper.rb +20 -0
- data/lib/power_stencil/dsl/base.rb +24 -0
- data/lib/power_stencil/dsl/entities.rb +46 -0
- data/lib/power_stencil/dsl/plugin_generation.rb +17 -0
- data/lib/power_stencil/engine/base.rb +50 -0
- data/lib/power_stencil/engine/build_handling.rb +77 -0
- data/lib/power_stencil/engine/directory_processor.rb +111 -0
- data/lib/power_stencil/engine/entities_definitions.rb +42 -0
- data/lib/power_stencil/engine/entities_handling.rb +76 -0
- data/lib/power_stencil/engine/entity_engine.rb +20 -0
- data/lib/power_stencil/engine/init_engine.rb +18 -0
- data/lib/power_stencil/engine/project_engine.rb +75 -0
- data/lib/power_stencil/engine/renderers/erb.rb +21 -0
- data/lib/power_stencil/error.rb +20 -0
- data/lib/power_stencil/initializer.rb +87 -0
- data/lib/power_stencil/plugins/base.rb +54 -0
- data/lib/power_stencil/plugins/capabilities.rb +30 -0
- data/lib/power_stencil/plugins/command_line.rb +27 -0
- data/lib/power_stencil/plugins/config.rb +32 -0
- data/lib/power_stencil/plugins/dependencies.rb +32 -0
- data/lib/power_stencil/plugins/gem.rb +57 -0
- data/lib/power_stencil/plugins/require.rb +77 -0
- data/lib/power_stencil/plugins/templates.rb +21 -0
- data/lib/power_stencil/project/base.rb +79 -0
- data/lib/power_stencil/project/config.rb +54 -0
- data/lib/power_stencil/project/create.rb +30 -0
- data/lib/power_stencil/project/info.rb +72 -0
- data/lib/power_stencil/project/paths.rb +119 -0
- data/lib/power_stencil/project/plugins.rb +89 -0
- data/lib/power_stencil/project/proxy.rb +13 -0
- data/lib/power_stencil/project/templates.rb +56 -0
- data/lib/power_stencil/project/versioning.rb +29 -0
- data/lib/power_stencil/system_entity_definitions/all.rb +14 -0
- data/lib/power_stencil/system_entity_definitions/buildable.rb +23 -0
- data/lib/power_stencil/system_entity_definitions/entity_override.rb +8 -0
- data/lib/power_stencil/system_entity_definitions/entity_project_common.rb +33 -0
- data/lib/power_stencil/system_entity_definitions/has_associated_files.rb +13 -0
- data/lib/power_stencil/system_entity_definitions/non_persistent.rb +14 -0
- data/lib/power_stencil/system_entity_definitions/plugin.rb +17 -0
- data/lib/power_stencil/system_entity_definitions/process_descriptor.rb +15 -0
- data/lib/power_stencil/system_entity_definitions/project_config.rb +24 -0
- data/lib/power_stencil/system_entity_definitions/project_entity.rb +16 -0
- data/lib/power_stencil/system_entity_definitions/simple_exec.rb +47 -0
- data/lib/power_stencil/utils/directory_processor.rb +54 -0
- data/lib/power_stencil/utils/file_edit.rb +87 -0
- data/lib/power_stencil/utils/file_helper.rb +56 -0
- data/lib/power_stencil/utils/gem_utils.rb +13 -0
- data/lib/power_stencil/utils/secure_require.rb +26 -0
- data/lib/power_stencil/utils/semantic_version.rb +128 -0
- data/lib/power_stencil/version.rb +3 -0
- data/power_stencil.gemspec +32 -0
- metadata +287 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
PowerStencil project templates
|
2
|
+
==============================
|
3
|
+
|
4
|
+
|
5
|
+
In this directory, you can define project specific templates for entities
|
6
|
+
defined locally in this project.
|
7
|
+
|
8
|
+
Templates can be a whole tree structure in a directory named from the entity
|
9
|
+
type of entities you defined in `entity_definitions` folder that are `buildable`.
|
10
|
+
|
11
|
+
__It is strongly advised to keep this directory under source control__
|
12
|
+
|
13
|
+
This should be the PowerStencil default behaviour.
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
PowerStencil user entities
|
2
|
+
==========================
|
3
|
+
|
4
|
+
|
5
|
+
In this directory, you will find all project entities locally defined by
|
6
|
+
the user (overrides but also entities not meant to be versioned)
|
7
|
+
|
8
|
+
They are organized as `<entity_type>/<entity_name>.yaml`
|
9
|
+
|
10
|
+
__It is strongly advised NOT to keep this directory under source control__
|
11
|
+
|
12
|
+
This should be the default PowerStencil behaviour.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# This file has been generated on the <%= Time.now %> by the power stencil framework (v: <%= PowerStencil::VERSION %>)
|
2
|
+
# THIS FILE *IS* MEANT TO BE VERSIONED (and is by default)
|
3
|
+
# You can use it for any configuration you want to keep at repository level
|
4
|
+
|
5
|
+
# If you want to ensure a minimal version number of PowerStencil
|
6
|
+
:min_power_stencil_version: <%= PowerStencil::VERSION %>
|
data/exe/power_stencil
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'power_stencil'
|
5
|
+
require 'climatic/script/base'
|
6
|
+
|
7
|
+
PowerStencil.bootstrap
|
8
|
+
|
9
|
+
module PowerStencil
|
10
|
+
class Script
|
11
|
+
|
12
|
+
include Climatic::Script::Base
|
13
|
+
include Climatic::Proxy
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def display_help_and_exit
|
18
|
+
puts config.command_line_help
|
19
|
+
exit 0
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
PowerStencil::Script.start
|
26
|
+
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'power_stencil/version'
|
2
|
+
|
3
|
+
require 'universe_compiler'
|
4
|
+
require 'dir_glob_ignore'
|
5
|
+
|
6
|
+
$DO_NOT_AUTOSTART_CLIMATIC=true
|
7
|
+
require 'climatic'
|
8
|
+
|
9
|
+
require 'power_stencil/error'
|
10
|
+
require 'power_stencil/utils/semantic_version'
|
11
|
+
require 'power_stencil/utils/file_helper'
|
12
|
+
require 'power_stencil/utils/directory_processor'
|
13
|
+
require 'power_stencil/utils/secure_require'
|
14
|
+
require 'power_stencil/utils/gem_utils'
|
15
|
+
require 'power_stencil/utils/file_edit'
|
16
|
+
|
17
|
+
require 'climatic/script/unimplemented_processor'
|
18
|
+
require 'power_stencil/project/proxy'
|
19
|
+
|
20
|
+
require 'power_stencil/command_processors/trace_helper'
|
21
|
+
require 'power_stencil/command_processors/entity_helper'
|
22
|
+
require 'power_stencil/command_processors/root'
|
23
|
+
require 'power_stencil/command_processors/init'
|
24
|
+
require 'power_stencil/command_processors/info'
|
25
|
+
require 'power_stencil/command_processors/get'
|
26
|
+
require 'power_stencil/command_processors/check'
|
27
|
+
require 'power_stencil/command_processors/create'
|
28
|
+
require 'power_stencil/command_processors/edit'
|
29
|
+
require 'power_stencil/command_processors/delete'
|
30
|
+
require 'power_stencil/command_processors/shell'
|
31
|
+
require 'power_stencil/command_processors/new_plugin'
|
32
|
+
require 'power_stencil/command_processors/build'
|
33
|
+
|
34
|
+
|
35
|
+
module PowerStencil
|
36
|
+
|
37
|
+
# Module for plugins
|
38
|
+
module Plugin; end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'power_stencil/engine/base'
|
43
|
+
require 'power_stencil/plugins/base'
|
44
|
+
require 'power_stencil/project/base'
|
45
|
+
|
46
|
+
require 'power_stencil/initializer'
|
47
|
+
|
48
|
+
|
49
|
+
module PowerStencil
|
50
|
+
|
51
|
+
extend PowerStencil::Initializer
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Build
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def execute
|
14
|
+
if config.command_line_layer.extra_parameters.empty?
|
15
|
+
raise PowerStencil::Error, 'Please specify something to build'
|
16
|
+
end
|
17
|
+
|
18
|
+
if config[:'supported-builds']
|
19
|
+
project.engine.available_entities_hash.select do |_, klass|
|
20
|
+
klass.respond_to?(:buildable?) and klass.buildable?
|
21
|
+
end .each do |entity_type, _|
|
22
|
+
puts " - '#{entity_type}'"
|
23
|
+
end
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
|
28
|
+
raise PowerStencil::Error, 'No valid entity specified' if targets.empty?
|
29
|
+
project.engine.build targets, fail_on_error: config[:'fail-on-error'], parallelized: config[:parallelized]
|
30
|
+
project.engine.last_build_report.each do |entity_full_name, entity_report|
|
31
|
+
if entity_report == ['Ok']
|
32
|
+
puts " - '#{entity_full_name}' has been correctly built"
|
33
|
+
else
|
34
|
+
puts " - Failed to build '#{entity_full_name}' because ", entity_report
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Check
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
|
11
|
+
def execute
|
12
|
+
puts 'RAW ENTITIES'
|
13
|
+
targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
|
14
|
+
targets.sort {|a,b| a.as_path <=> b.as_path }
|
15
|
+
.map do |entity|
|
16
|
+
entity_info = [" '#{entity.as_path}':"]
|
17
|
+
entity_info << " - Storage path : '#{entity.source_uri}'"
|
18
|
+
entity_info << " - Templates path : '#{entity.templates_path}'" if entity.respond_to? :templates_path
|
19
|
+
entity_info << " - Status : #{entity.valid? ? 'Valid' : 'INVALID !'} "
|
20
|
+
entity_info << " - Buildable : #{entity.buildable?}"
|
21
|
+
entity_info
|
22
|
+
end .each { |l| puts l }
|
23
|
+
|
24
|
+
|
25
|
+
#
|
26
|
+
# targets.map do |entity|
|
27
|
+
# " - '#{entity.as_path}': '#{entity.source_uri}'"
|
28
|
+
# end .sort.each { |l| puts l }
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Create
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
include PowerStencil::Utils::FileEdit
|
11
|
+
|
12
|
+
def execute
|
13
|
+
analyse_extra_params.each do |search_criterion|
|
14
|
+
begin
|
15
|
+
puts_and_logs "Creating new entity '#{search_criterion.as_path}'"
|
16
|
+
entity_as_hash = {name: search_criterion.name}
|
17
|
+
unless config[:property].nil?
|
18
|
+
config[:property].each do |property_def|
|
19
|
+
if md = property_def.match(/^\s*(?<prop_name>[^:=]+)\s*[:=]\s*(?<prop_val>.*)\s*$/)
|
20
|
+
logger.debug "Using extra properties from command line '#{md['prop_name']}' = '#{md['prop_val']}'"
|
21
|
+
entity_as_hash[md['prop_name'].to_sym] = md['prop_val']
|
22
|
+
else
|
23
|
+
raise PowerStencil::Error, "Invalid command line property definition: '#{property_def}'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
new_entity = project.engine.new_entity project.engine.root_universe,
|
29
|
+
search_criterion.type,
|
30
|
+
fields: entity_as_hash,
|
31
|
+
user: config[:user]
|
32
|
+
|
33
|
+
if config[:edit]
|
34
|
+
logger.debug "Edit mode for entity #{new_entity.to_composite_key} in #{new_entity.source_uri}"
|
35
|
+
new_entity = edit_before_save new_entity
|
36
|
+
end
|
37
|
+
|
38
|
+
new_entity.valid? raise_error: true
|
39
|
+
new_entity.save
|
40
|
+
|
41
|
+
puts "Created '#{new_entity.as_path}'"
|
42
|
+
rescue => e
|
43
|
+
puts "Failed to create '#{search_criterion.as_path}' with message '#{e.message}'."
|
44
|
+
logger.debug PowerStencil::Error.report_error(e)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def modifications_valid?(modified_path, original_entity)
|
52
|
+
test_entity = UniverseCompiler::Entity::Persistence.load modified_path
|
53
|
+
test_entity.valid?
|
54
|
+
rescue => e
|
55
|
+
logger.debug PowerStencil::Error.report_error(e)
|
56
|
+
logger.debug "Modifications applied to '#{original_entity.as_path}' are invalid !"
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit_before_save(entity)
|
61
|
+
securely_edit_entity entity do |modified_path, _|
|
62
|
+
modifications_valid? modified_path, entity
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Delete
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
|
11
|
+
def execute
|
12
|
+
analyse_extra_params.each do |search_criterion|
|
13
|
+
begin
|
14
|
+
unless project.engine.entity *search_criterion.to_a, project.engine.root_universe
|
15
|
+
puts "Skipping '#{search_criterion.as_path}'. Entity not found."
|
16
|
+
next
|
17
|
+
end
|
18
|
+
puts_and_logs "Deleting entity '#{search_criterion.as_path}'"
|
19
|
+
if project.engine.delete_entity project.engine.root_universe,
|
20
|
+
*search_criterion.to_a,
|
21
|
+
delete_files: config[:'delete-files']
|
22
|
+
msg = "Deleted '#{search_criterion.as_path}'"
|
23
|
+
msg << ' and associated files.' if config[:'delete-files']
|
24
|
+
puts msg
|
25
|
+
else
|
26
|
+
puts 'Cancelled by user input.'
|
27
|
+
end
|
28
|
+
rescue => e
|
29
|
+
puts "Failed to delete '#{search_criterion.as_path}' with message '#{e.message}'."
|
30
|
+
logger.debug PowerStencil::Error.report_error(e)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
class Edit
|
5
|
+
|
6
|
+
include Climatic::Script::UnimplementedProcessor
|
7
|
+
include Climatic::Proxy
|
8
|
+
include PowerStencil::Project::Proxy
|
9
|
+
include PowerStencil::CommandProcessors::EntityHelper
|
10
|
+
include PowerStencil::Utils::FileEdit
|
11
|
+
|
12
|
+
def execute
|
13
|
+
targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
|
14
|
+
targets.each do |target|
|
15
|
+
securely_edit_file target.source_uri do |modified_path, _|
|
16
|
+
modifications_valid? modified_path, target
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def modifications_valid?(modified_path, original_entity)
|
24
|
+
test_entity = UniverseCompiler::Entity::Persistence.load modified_path
|
25
|
+
test_entity.valid?
|
26
|
+
rescue => e
|
27
|
+
logger.debug PowerStencil::Error.report_error(e)
|
28
|
+
logger.debug "Modifications applied to '#{original_entity.as_path}' are invalid !"
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module CommandProcessors
|
3
|
+
|
4
|
+
module EntityHelper
|
5
|
+
|
6
|
+
EntitySearchReference = Struct.new(:type, :name) do
|
7
|
+
def as_path
|
8
|
+
[type, name].map(&:to_s).join '/'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def display_entity(entity)
|
13
|
+
puts_and_logs "# Entity '#{entity.name}' (#{entity.type})"
|
14
|
+
if config[:'names-only']
|
15
|
+
puts "- #{entity.name}"
|
16
|
+
else
|
17
|
+
if config[:raw]
|
18
|
+
puts entity.to_yaml
|
19
|
+
else
|
20
|
+
puts entity.to_hash.to_yaml
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def targets_from_criteria(search_criteria, universe)
|
26
|
+
target_universe = if config[:compiled]
|
27
|
+
universe.compile scenario: config[:scenario]
|
28
|
+
else
|
29
|
+
universe
|
30
|
+
end
|
31
|
+
|
32
|
+
if config[:regexp]
|
33
|
+
target_universe.get_entities do |entity|
|
34
|
+
id = entity.as_path
|
35
|
+
keep = false
|
36
|
+
search_criteria.each do |criterion|
|
37
|
+
if md = id.match(/#{criterion}/i)
|
38
|
+
keep = true
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
keep
|
43
|
+
end
|
44
|
+
else
|
45
|
+
search_criteria.inject([]) do |res, criterion|
|
46
|
+
res.concat target_universe.get_entities(criterion: :by_uniq_key, value: criterion.to_a)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def extra_params_to_entity_search_criteria(params)
|
52
|
+
criteria = []
|
53
|
+
next_entity_reference = EntitySearchReference.new
|
54
|
+
stack = params.dup
|
55
|
+
if config[:regexp]
|
56
|
+
criteria = stack
|
57
|
+
else
|
58
|
+
stack.each do |param|
|
59
|
+
if md = param.match(/^\s*(?<type>[^\/]+)\/(?<name>.+)\s*$/)
|
60
|
+
next_entity_reference.type = md[:type].to_sym
|
61
|
+
next_entity_reference.name = md[:name]
|
62
|
+
else
|
63
|
+
if next_entity_reference.type.nil? or next_entity_reference.type.empty?
|
64
|
+
next_entity_reference.type = param.to_sym
|
65
|
+
else
|
66
|
+
next_entity_reference.name = param
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
next unless reference_complete? next_entity_reference
|
71
|
+
logger.debug "Found entity search pattern in params: #{next_entity_reference.inspect}"
|
72
|
+
criteria << next_entity_reference
|
73
|
+
next_entity_reference = EntitySearchReference.new
|
74
|
+
end
|
75
|
+
unless next_entity_reference.type.nil?
|
76
|
+
raise PowerStencil::Error, "Invalid parameter '#{next_entity_reference.type}' !"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
criteria
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
|
86
|
+
def analyse_extra_params(extra_params = config.command_line_layer.extra_parameters, default: [''])
|
87
|
+
params_to_check = if extra_params.empty? then
|
88
|
+
config[:regexp] = true
|
89
|
+
default
|
90
|
+
else
|
91
|
+
extra_params
|
92
|
+
end
|
93
|
+
extra_params_to_entity_search_criteria params_to_check
|
94
|
+
end
|
95
|
+
|
96
|
+
def reference_complete?(reference)
|
97
|
+
return false if (reference.type.nil? or reference.name.nil?)
|
98
|
+
return false if (reference.type.empty? or reference.name.empty?)
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|