mantra 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/bin/mantra +13 -5
- data/lib/mantra/command.rb +21 -3
- data/lib/mantra/commands/detect_certificates.rb +17 -0
- data/lib/mantra/commands/find.rb +3 -1
- data/lib/mantra/commands/help.rb +17 -0
- data/lib/mantra/commands/highlight.rb +23 -0
- data/lib/mantra/commands/merge.rb +8 -5
- data/lib/mantra/commands/render_release_template.rb +23 -0
- data/lib/mantra/commands/transform.rb +4 -2
- data/lib/mantra/helpers/object_with_type.rb +8 -3
- data/lib/mantra/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bde299aead3e479dcc120a2cac913f12db69610
|
4
|
+
data.tar.gz: 22b16fe9b31eb8254f5403c15d461b55a2ad38dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ca75ec86cd4208543bddc0e135dd59f6fb280cdb02341fd2ea17b81a8b1dda76f3b6b67af7d83c2a55a7872d9c66042acb585313fcfa655004394d0e83bf8f2
|
7
|
+
data.tar.gz: d6dd4ec38e35a77849248c1edf9e7711ee9ffb089172edaa11b90026a752f34ca2bf9c18a7412c716ba4c8e18aa9efa3f4ea3a6481bbe980e904c99bec7d7f50
|
data/README.md
CHANGED
@@ -24,12 +24,25 @@ Mantra tends to be an easily extendable tool, so you can add new commands and tr
|
|
24
24
|
|
25
25
|
While some actions performed on manifest can be automated, anther require special configuration and extra knowledges about source manifes. Here is a small glossery that I use:
|
26
26
|
|
27
|
-
`Transformation Manifest` - config file that describes how your manifest should be udpated
|
27
|
+
`Transformation Manifest` - config file that describes how your manifest should be udpated.
|
28
|
+
|
28
29
|
`Source Manifest` - your source BOSH manifest, if you run templatizers on source manifest they can change it.
|
30
|
+
|
29
31
|
`Target Manifest` - manifest that will contain extracted template properties, to restore source manifest you'll need to run merge tool with resulting source manifest.
|
32
|
+
|
30
33
|
`Transform` - a ruby class that declares how specific transformation should be done.
|
31
34
|
|
32
|
-
One more concept: no nokogiri and native dependencies
|
35
|
+
One more concept: **no nokogiri and native dependencies**.
|
36
|
+
|
37
|
+
### Dependencies
|
38
|
+
|
39
|
+
Ruby.
|
40
|
+
|
41
|
+
### How to install
|
42
|
+
|
43
|
+
```
|
44
|
+
gem install mantra
|
45
|
+
```
|
33
46
|
|
34
47
|
### Examples
|
35
48
|
|
data/bin/mantra
CHANGED
@@ -2,16 +2,24 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
4
|
require "mantra"
|
5
|
+
include Mantra::Helpers
|
5
6
|
|
6
|
-
if ARGV.empty?
|
7
|
+
if ARGV.empty? || ARGV.first == "-h" || ARGV.first == "--help"
|
7
8
|
puts Mantra::Command.usage
|
8
9
|
exit 0
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
options = {type:
|
12
|
+
command_name = ARGV.shift
|
13
|
+
options = {type: command_name.to_sym, args: ARGV}
|
14
|
+
|
15
|
+
begin
|
16
|
+
command = Mantra::Command.create(options)
|
17
|
+
command.run
|
18
|
+
rescue ObjectWithType::UnknownType, ObjectWithType::UnspecifiedType
|
19
|
+
puts "Error: Unknown command '#{command_name}', see command usage\n\n"
|
20
|
+
puts Mantra::Command.usage
|
21
|
+
exit 1
|
22
|
+
end
|
13
23
|
|
14
|
-
command = Mantra::Command.create(options)
|
15
24
|
|
16
|
-
command.run
|
17
25
|
|
data/lib/mantra/command.rb
CHANGED
@@ -9,8 +9,22 @@ module Mantra
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.usage
|
12
|
-
"
|
13
|
-
"\
|
12
|
+
"Mantra is Manifest Transformation tool to ease work with BOSH manifest.\n" +
|
13
|
+
"\nUsage:\tmantra <command> [options]" +
|
14
|
+
"\n\nCommands:\n" +
|
15
|
+
self.subclasses.map { |s| "#{" "*6}#{s.type}#{" "*20}\t#{s.description}" }.join("\n") +
|
16
|
+
"\n\n" +
|
17
|
+
"For help on any command run:\n" +
|
18
|
+
["mantra <command> -h", "mantra <command> help", "mantra <command> --help"].map { |s| " " * 6 + s }.join("\n") +
|
19
|
+
"\n\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description(description=nil)
|
23
|
+
description.nil? ? full_description : (@description = description)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.full_description
|
27
|
+
[@description, aliases.empty? ? nil : "(aliases: #{aliases.join(", ")})"].compact.join(" ")
|
14
28
|
end
|
15
29
|
|
16
30
|
def self.option(name, long_option, short_option, description)
|
@@ -33,7 +47,7 @@ module Mantra
|
|
33
47
|
def parse_options
|
34
48
|
@options = {}
|
35
49
|
OptionParser.new do |options_parser|
|
36
|
-
options_parser.banner = "Usage: mantra
|
50
|
+
options_parser.banner = "Usage: mantra [options]"
|
37
51
|
self.class.option_descriptors.each do |option|
|
38
52
|
option_name = option.shift.to_s
|
39
53
|
options_parser.on(*option) do |value|
|
@@ -50,3 +64,7 @@ end
|
|
50
64
|
require "mantra/commands/find"
|
51
65
|
require "mantra/commands/merge"
|
52
66
|
require "mantra/commands/transform"
|
67
|
+
require "mantra/commands/highlight"
|
68
|
+
require "mantra/commands/render_release_template"
|
69
|
+
require "mantra/commands/detect_certificates"
|
70
|
+
require "mantra/commands/help"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mantra
|
2
|
+
class Commands
|
3
|
+
class DetectCertificates < Command
|
4
|
+
type :"detect-certificates"
|
5
|
+
aliases "certs", "dc"
|
6
|
+
description "Find and group certificates in manifest"
|
7
|
+
|
8
|
+
option :manifest, "--manifest manifest-file", "-m manifest-file", "manifest file"
|
9
|
+
|
10
|
+
def perform
|
11
|
+
m = Manifest.new(manifest)
|
12
|
+
raise "Not implemented yet"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/mantra/commands/find.rb
CHANGED
@@ -5,7 +5,9 @@ module Mantra
|
|
5
5
|
class Commands
|
6
6
|
class Find < Command
|
7
7
|
type :find
|
8
|
-
|
8
|
+
aliases :f
|
9
|
+
description "Transform manifest using transform config"
|
10
|
+
|
9
11
|
option :scope, "--scope scope-path", "-s scope", "path scope you want to find"
|
10
12
|
option :manifest, "--manifest manifest-file", "-m manifest-file", "manifest"
|
11
13
|
option :format, "--format format", "-f format", "format (yaml or json)"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Mantra
|
5
|
+
class Commands
|
6
|
+
class Highlight < Command
|
7
|
+
type :highlight
|
8
|
+
aliases :h
|
9
|
+
description "Highlight manifest path or values"
|
10
|
+
|
11
|
+
option :scope, "--scope scope-path", "-s scope", "path scope you want to highlight"
|
12
|
+
option :value, "--value value", "-v value", "value to highlight"
|
13
|
+
option :regex, "--regex value", "-r regex", "regex of value to highlight"
|
14
|
+
option :manifest, "--manifest manifest-file", "-m manifest-file", "manifest file"
|
15
|
+
|
16
|
+
def perform
|
17
|
+
m = Manifest.new(manifest)
|
18
|
+
raise "Not implemented yet"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -5,14 +5,17 @@ module Mantra
|
|
5
5
|
class Commands
|
6
6
|
class Merge < Command
|
7
7
|
type :merge
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
option :json, "--json JSON_STRING", "-j", "
|
12
|
-
option :file, "--file JSON_FILE", "-f", "
|
8
|
+
aliases :m
|
9
|
+
description "Merge object to manifest to specified path"
|
10
|
+
|
11
|
+
option :json, "--json JSON_STRING", "-j", "String with JSON object that should be merged to the manifest"
|
12
|
+
option :file, "--file JSON_FILE", "-f", "JSON file that should be merged to the manifest"
|
13
|
+
option :yaml_file, "--yaml YAML_FILE", "-y", "File that should be merged to the manifest (not implemented)"
|
13
14
|
option :path, "--scope PATH", "-s", "Scope (or path) in Manifest where to merge this value"
|
14
15
|
option :manifest_path, "--manifest MANIFEST", "-m", "Manifest path"
|
15
16
|
|
17
|
+
attr_accessor :manifest
|
18
|
+
|
16
19
|
def perform
|
17
20
|
if json.nil? && file.nil?
|
18
21
|
raise "json of file should be specified"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Mantra
|
5
|
+
class Commands
|
6
|
+
class RenderReleaseTemplate < Command
|
7
|
+
type :"render-release-template"
|
8
|
+
aliases "render-template", "rt", "rrt"
|
9
|
+
description "Transform manifest using transform config"
|
10
|
+
|
11
|
+
option :release_folder, "--release-folder release-folder", "-r scope", "path scope you want to find"
|
12
|
+
option :template_name, "--template template-path", "-m manifest-file", "manifest"
|
13
|
+
option :context, "--context format", "-f format", "format (yaml or json)"
|
14
|
+
option :context_file, "--context-file", "-p", "format (yaml or json)"
|
15
|
+
|
16
|
+
def perform
|
17
|
+
# see this gist: https://gist.github.com/allomov/c2e7780384674fa85486cc3c3f6bf54f
|
18
|
+
raise "Not implemented yet"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -4,12 +4,14 @@ module Mantra
|
|
4
4
|
class Commands
|
5
5
|
class Transform < Command
|
6
6
|
type :transform
|
7
|
-
|
8
|
-
|
7
|
+
aliases :t
|
8
|
+
description "Transform manifest using transform config"
|
9
9
|
|
10
10
|
option :transform_config_path, "--config CONFIG", "-t", "Transformation config path"
|
11
11
|
option :manifest_path, "--manifest MANIFEST", "-m", "Manifest path"
|
12
12
|
|
13
|
+
attr_accessor :manifest
|
14
|
+
|
13
15
|
def transform_config
|
14
16
|
@transform_config ||= YAML.load_file(transform_config_path)
|
15
17
|
end
|
@@ -15,8 +15,13 @@ module Mantra
|
|
15
15
|
type.nil? ? @type : (@type = type.to_sym)
|
16
16
|
end
|
17
17
|
|
18
|
-
def alias_type(alias_type
|
19
|
-
|
18
|
+
def alias_type(alias_type)
|
19
|
+
aliases(alias_type)
|
20
|
+
end
|
21
|
+
|
22
|
+
def aliases(*args)
|
23
|
+
@aliases = [] if @aliases.nil?
|
24
|
+
args.empty? ? @aliases : (@aliases.concat(args.map {|a| a.to_sym }))
|
20
25
|
end
|
21
26
|
|
22
27
|
def create(options)
|
@@ -31,7 +36,7 @@ module Mantra
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def find_by_type(type)
|
34
|
-
self.subclasses.find { |s| s.type == type || s.
|
39
|
+
self.subclasses.find { |s| s.type == type || s.aliases.include?(type) }
|
35
40
|
end
|
36
41
|
|
37
42
|
def inherited(subclass)
|
data/lib/mantra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mantra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lomov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,8 +120,12 @@ files:
|
|
120
120
|
- lib/mantra/certificates/cortege.rb
|
121
121
|
- lib/mantra/certificates/group.rb
|
122
122
|
- lib/mantra/command.rb
|
123
|
+
- lib/mantra/commands/detect_certificates.rb
|
123
124
|
- lib/mantra/commands/find.rb
|
125
|
+
- lib/mantra/commands/help.rb
|
126
|
+
- lib/mantra/commands/highlight.rb
|
124
127
|
- lib/mantra/commands/merge.rb
|
128
|
+
- lib/mantra/commands/render_release_template.rb
|
125
129
|
- lib/mantra/commands/transform.rb
|
126
130
|
- lib/mantra/helpers/object_with_type.rb
|
127
131
|
- lib/mantra/helpers/regexp_helper.rb
|