mantra 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -2
  5. data/README.md +126 -16
  6. data/bin/mantra +17 -0
  7. data/ci/README.md +6 -0
  8. data/ci/docker/Dockerfile +20 -0
  9. data/ci/docker/build-docker-image +10 -0
  10. data/ci/pipeline.yml +42 -0
  11. data/ci/scripts/run-tests +3 -0
  12. data/ci/stub.example.yml +6 -0
  13. data/ci/stub.yml +33 -0
  14. data/ci/tasks/run-tests-dev.yml +10 -0
  15. data/ci/tasks/run-tests-stable.yml +13 -0
  16. data/lib/mantra/certificate.rb +35 -0
  17. data/lib/mantra/certificates/cortege.rb +64 -0
  18. data/lib/mantra/certificates/group.rb +26 -0
  19. data/lib/mantra/command.rb +51 -0
  20. data/lib/mantra/commands/find.rb +38 -0
  21. data/lib/mantra/commands/transform.rb +38 -0
  22. data/lib/mantra/helpers/object_with_type.rb +60 -0
  23. data/lib/mantra/helpers/regexp_helper.rb +12 -0
  24. data/lib/mantra/helpers/template_helper.rb +70 -0
  25. data/lib/mantra/manifest/array_element.rb +84 -0
  26. data/lib/mantra/manifest/element.rb +175 -0
  27. data/lib/mantra/manifest/ext.rb +33 -0
  28. data/lib/mantra/manifest/hash_element.rb +88 -0
  29. data/lib/mantra/manifest/leaf_element.rb +38 -0
  30. data/lib/mantra/manifest/root_element.rb +38 -0
  31. data/lib/mantra/manifest/scope/array_scope.rb +53 -0
  32. data/lib/mantra/manifest/scope/empty_scope.rb +24 -0
  33. data/lib/mantra/manifest/scope/hash_scope.rb +20 -0
  34. data/lib/mantra/manifest/scope/leaf_scope.rb +0 -0
  35. data/lib/mantra/manifest/scope.rb +94 -0
  36. data/lib/mantra/manifest.rb +47 -0
  37. data/lib/mantra/merge_tool/spiff.rb +23 -0
  38. data/lib/mantra/merge_tool.rb +13 -0
  39. data/lib/mantra/transform/extract.rb +10 -0
  40. data/lib/mantra/transform/extract_certificates.rb +18 -0
  41. data/lib/mantra/transform/extract_certificates_to_files.rb +12 -0
  42. data/lib/mantra/transform/extract_section.rb +10 -0
  43. data/lib/mantra/transform/inputs/any.rb +10 -0
  44. data/lib/mantra/transform/inputs/array.rb +16 -0
  45. data/lib/mantra/transform/inputs/file.rb +16 -0
  46. data/lib/mantra/transform/inputs/folder.rb +9 -0
  47. data/lib/mantra/transform/inputs/hash.rb +16 -0
  48. data/lib/mantra/transform/inputs/string.rb +9 -0
  49. data/lib/mantra/transform/merge.rb +26 -0
  50. data/lib/mantra/transform/replace.rb +34 -0
  51. data/lib/mantra/transform/templatize_ip_address.rb +129 -0
  52. data/lib/mantra/transform/templatize_value.rb +63 -0
  53. data/lib/mantra/transform.rb +118 -0
  54. data/lib/mantra/version.rb +1 -1
  55. data/lib/mantra.rb +9 -1
  56. data/mantra.gemspec +6 -5
  57. metadata +69 -8
  58. data/bin/console +0 -14
  59. data/bin/setup +0 -8
@@ -0,0 +1,118 @@
1
+ require "pathname"
2
+ require "yaml"
3
+
4
+ module Mantra
5
+ class Transform
6
+ include Helpers::ObjectWithType
7
+
8
+ class ValidationError < Exception; end
9
+
10
+ class Input
11
+ include Helpers::ObjectWithType
12
+ def validate(value, name = nil)
13
+ return if self.options[:validate].nil?
14
+ Array(self.options[:validate]).each do |validate_verb|
15
+ if self.respond_to?("validate_#{validate_verb}")
16
+ self.send(:"validate_#{validate_verb}", value, name)
17
+ else
18
+ raise ValidationError.new("There is no validator defined: #{validate_verb}.")
19
+ end
20
+ end
21
+ end
22
+
23
+ def required?
24
+ !self.options[:optional]
25
+ end
26
+
27
+ def validate_required(value, name)
28
+ raise ValidationError.new("#{name} must be specified.") if value.nil?
29
+ end
30
+ end
31
+
32
+ def self.inputs
33
+ @inputs ||= {}
34
+ end
35
+
36
+ def self.input(name, options={type: :string})
37
+ self.inputs[name] = Input.create(options)
38
+ define_method name do
39
+ self.options[name]
40
+ end
41
+ define_method "#{name}_defined?" do
42
+ !self.options[name].nil?
43
+ end
44
+ end
45
+
46
+ def self.description(description)
47
+ @description = description
48
+ end
49
+
50
+ def run
51
+ validate_inputs
52
+ self.perform
53
+ end
54
+
55
+ def validate_inputs
56
+ self.class.inputs.each_pair do |name, input|
57
+ input_value = self.options[name]
58
+ input.validate_required(input_value, name) if input.required?
59
+ input_value = self.options[name]
60
+ input.validate(input_value, name)
61
+ end
62
+ end
63
+
64
+ def perform
65
+ raise "not implemented"
66
+ end
67
+
68
+ def ensure_yml_file_exist(path)
69
+ return if File.exist?(path)
70
+ pathname = Pathname.new(path)
71
+ directory = pathname.dirname
72
+ FileUtils.mkdir_p(directory)
73
+ File.open(path, "w+") { |file| file.write({}.to_yaml) }
74
+ end
75
+
76
+ def raise_error_if_no_source_manifest
77
+ if self.source.nil? || !File.exist?(self.source)
78
+ raise Manifest::FileNotFoundError.new("Source manifest does not exist: #{self.source.inspect}")
79
+ end
80
+ end
81
+
82
+ def merge_tool
83
+ return @merge_tool unless @merge_tool.nil?
84
+ merge_tool_type = self.options[:merge_tool] || :spiff
85
+ @merge_tool = MergeTool.create(type: merge_tool_type)
86
+ end
87
+
88
+ def source_manifest
89
+ @source_manifest ||= Manifest.new(self.source)
90
+ end
91
+
92
+ def target_manifest
93
+ @target_manifest ||= Manifest.new(self.target)
94
+ end
95
+
96
+ def previous_transform
97
+ self.options[:previous_transform]
98
+ end
99
+
100
+
101
+
102
+ end
103
+ end
104
+
105
+ require "mantra/transform/inputs/string"
106
+ require "mantra/transform/inputs/hash"
107
+ require "mantra/transform/inputs/array"
108
+ require "mantra/transform/inputs/file"
109
+ require "mantra/transform/inputs/folder"
110
+ require "mantra/transform/inputs/any"
111
+
112
+ require "mantra/transform/merge"
113
+ require "mantra/transform/replace"
114
+ require "mantra/transform/extract_section"
115
+ require "mantra/transform/extract_certificates"
116
+ require "mantra/transform/extract_certificates_to_files"
117
+ require "mantra/transform/templatize_value"
118
+ require "mantra/transform/templatize_ip_address"
@@ -1,3 +1,3 @@
1
1
  module Mantra
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/mantra.rb CHANGED
@@ -1,5 +1,13 @@
1
+ require "yaml"
1
2
  require "mantra/version"
3
+ require "mantra/helpers/regexp_helper"
4
+ require "mantra/helpers/template_helper"
5
+ require "mantra/helpers/object_with_type"
6
+ require "mantra/merge_tool"
7
+ require "mantra/manifest"
8
+ require "mantra/certificate"
9
+ require "mantra/transform"
10
+ require "mantra/command"
2
11
 
3
12
  module Mantra
4
- # Your code goes here...
5
13
  end
data/mantra.gemspec CHANGED
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
22
22
  # end
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.bindir = "bin"
26
+ spec.executables = ["mantra"]
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.11"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.4"
32
+ spec.add_development_dependency "rspec-its", "~> 1.2"
32
33
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lomov
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-29 00:00:00.000000000 Z
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,18 +44,33 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
55
69
  description: Manifest Transfromation for BOSH
56
70
  email:
57
71
  - lomov.as@gmail.com
58
- executables: []
72
+ executables:
73
+ - mantra
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
@@ -65,9 +80,55 @@ files:
65
80
  - Gemfile
66
81
  - README.md
67
82
  - Rakefile
68
- - bin/console
69
- - bin/setup
83
+ - bin/mantra
84
+ - ci/README.md
85
+ - ci/docker/Dockerfile
86
+ - ci/docker/build-docker-image
87
+ - ci/pipeline.yml
88
+ - ci/scripts/run-tests
89
+ - ci/stub.example.yml
90
+ - ci/stub.yml
91
+ - ci/tasks/run-tests-dev.yml
92
+ - ci/tasks/run-tests-stable.yml
70
93
  - lib/mantra.rb
94
+ - lib/mantra/certificate.rb
95
+ - lib/mantra/certificates/cortege.rb
96
+ - lib/mantra/certificates/group.rb
97
+ - lib/mantra/command.rb
98
+ - lib/mantra/commands/find.rb
99
+ - lib/mantra/commands/transform.rb
100
+ - lib/mantra/helpers/object_with_type.rb
101
+ - lib/mantra/helpers/regexp_helper.rb
102
+ - lib/mantra/helpers/template_helper.rb
103
+ - lib/mantra/manifest.rb
104
+ - lib/mantra/manifest/array_element.rb
105
+ - lib/mantra/manifest/element.rb
106
+ - lib/mantra/manifest/ext.rb
107
+ - lib/mantra/manifest/hash_element.rb
108
+ - lib/mantra/manifest/leaf_element.rb
109
+ - lib/mantra/manifest/root_element.rb
110
+ - lib/mantra/manifest/scope.rb
111
+ - lib/mantra/manifest/scope/array_scope.rb
112
+ - lib/mantra/manifest/scope/empty_scope.rb
113
+ - lib/mantra/manifest/scope/hash_scope.rb
114
+ - lib/mantra/manifest/scope/leaf_scope.rb
115
+ - lib/mantra/merge_tool.rb
116
+ - lib/mantra/merge_tool/spiff.rb
117
+ - lib/mantra/transform.rb
118
+ - lib/mantra/transform/extract.rb
119
+ - lib/mantra/transform/extract_certificates.rb
120
+ - lib/mantra/transform/extract_certificates_to_files.rb
121
+ - lib/mantra/transform/extract_section.rb
122
+ - lib/mantra/transform/inputs/any.rb
123
+ - lib/mantra/transform/inputs/array.rb
124
+ - lib/mantra/transform/inputs/file.rb
125
+ - lib/mantra/transform/inputs/folder.rb
126
+ - lib/mantra/transform/inputs/hash.rb
127
+ - lib/mantra/transform/inputs/string.rb
128
+ - lib/mantra/transform/merge.rb
129
+ - lib/mantra/transform/replace.rb
130
+ - lib/mantra/transform/templatize_ip_address.rb
131
+ - lib/mantra/transform/templatize_value.rb
71
132
  - lib/mantra/version.rb
72
133
  - mantra.gemspec
73
134
  homepage:
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "mantra"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here