crowbar-validate-databags 1.0.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +6 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/crowbar-validate-databags +24 -0
- data/crowbar-validate-databags.gemspec +27 -0
- data/lib/crowbar/validate/crowbarvalidator.rb +100 -0
- data/lib/crowbar/validate/databags.rb +65 -0
- data/lib/crowbar/validate/databags/version.rb +7 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03c3f56b163ad37d65048aa7e734c142e59258a3e341f9ea7337022bbe5bebd1
|
4
|
+
data.tar.gz: 94cb0dbd2f1a634f5fb7db253143ce0774a08d2171b3da5fa45acad47f2b8c4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0faff363042d37c5f17946b10967d303384de7eda4c8c953e4bd95f5120531ebbd66fc441bf6304c6a02dd1844ae002ef7d4d415aca4d15cb83b14e19b723ff4
|
7
|
+
data.tar.gz: d555259b2b97b4dbb77c9153c2e3e4a0d2d1b7ba9e226753987f10de5046440fdffd7ea28d8d382de9f735cc7f069437ecafd76b285ce2b85bb7dd490672a13f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.1.9
|
5
|
+
before_install: gem install bundler -v 1.16.1
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: "FGp9C8nO47WgQqI/yml1jDUQ6+B3rVeNtwSBnapXG/8ivb8rUHFKkkwnh4ayxMmIyUpqtJiqq6la94mtNYve1hI1sbp3siWvHac7RUJ8vQbdioFktSuxKZ41y0p4o00Mu1SE+8rjJVIzKn+lryLO1LglINrjVHC/ky7DNe9iSwtjjh1PYlgVzMoh+9HMUjJfd+x78zkrA0SLS3A+n1BJsL4QfnGgBlF3dbXa/GAmiFL4k1VYqfzVo9ApBpVJHbrGYEBn5B4bU6GRoFvN9Yy4ZtiKmY9sVkWMxrwe3mn/MQjCkBCTVi+Idp3mMj2yQqjMbs/iBIDGwyzaexzJWakmKhoQ/NEFzutq4w9oujbtA+Ts07SPdcW0jPR6wYdfeOxxzQwojg5HMXrB03LzTwE+k1oYLZJxQ8qJxB88jY7QhOKr+Cylxn0r9/rlTOZgDtDPGd/tTRPKQci5SK44RCBCB7whvMhUz+ZGyBZzzKFesskULmUIMo0sARY/+EBf61AYrKxT6ESMjsa3LwuYbsSPbVOqb1uhnVtBnrlDiTJmPAnjwXlkKbp6GxJ4nWHSJt25mSVuXvBZ9FmrXRYMT3bSvyI608lbf95Eyn9s15493U0+PVfQv3l8Zomb046jjprPDjz0F2PfQQsaPsk1fquvjTT/KSI0LuVz3GDb54Z/VN4="
|
10
|
+
on:
|
11
|
+
tags: true
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Crowbar::Validate::Databags
|
2
|
+
|
3
|
+
A gem to validate crowbar databags
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'crowbar-validate-databags'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install crowbar-validate-databags
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$ crowbar-validate-databags PATH/TO/DATABAGS/
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
28
|
+
|
29
|
+
To release a new version, first of all create a new local branch like `git checkout -b feature/version`
|
30
|
+
for updating the `CHANGELOG.md` (please handle it the same way as in previous
|
31
|
+
versions) and for raising the version number, you can find the version in
|
32
|
+
`lib/crowbar/validate/databags/version.rb`.
|
33
|
+
|
34
|
+
After merging the pull request it's time to build the rubygem and to release it.
|
35
|
+
This is done automatically by Travis once a tag is pushed.
|
36
|
+
|
37
|
+
Last, go to https://github.com/crowbar/crowbar-validate-databags/releases/new and select
|
38
|
+
the pushed tag. Then you should put the latest changelog into the description
|
39
|
+
form field.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'crowbar/validate/databags'
|
4
|
+
|
5
|
+
if true
|
6
|
+
if ARGV.size != 1
|
7
|
+
puts "Must specify the dir where the files are to validate (i.e. /opt/dell/crowbar/data_bags/crowbar/)\n"
|
8
|
+
exit -4
|
9
|
+
end
|
10
|
+
if !File.exists?(ARGV[0])
|
11
|
+
puts "#{ARGV[0]} must exist\n"
|
12
|
+
exit -5
|
13
|
+
end
|
14
|
+
|
15
|
+
rc = Crowbar::Validate::Databags.validate(ARGV[0])
|
16
|
+
if rc.include?(-1)
|
17
|
+
puts "Schema validation failed.\n"
|
18
|
+
elif rc.include?(-2)
|
19
|
+
puts "Json validation failed.\n"
|
20
|
+
elif rc.include?(-3)
|
21
|
+
puts "Migration files validation failed.\n"
|
22
|
+
end
|
23
|
+
exit rc.min
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "crowbar/validate/databags/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "crowbar-validate-databags"
|
7
|
+
spec.version = Crowbar::Validate::Databags::VERSION
|
8
|
+
spec.authors = ["Itxaka Serrano Garcia", "Rick Salevsky"]
|
9
|
+
spec.email = ["igarcia@suse.com", "rsalevsky@suse.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Validates databags of crowbar.}
|
12
|
+
spec.homepage = "http://github.com/itxaka/crowbar-validate-databags"
|
13
|
+
spec.license = "GPL-2.0"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = ["crowbar-validate-databags"]
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "kwalify", "~> 0.7"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'kwalify'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
|
5
|
+
class CrowbarValidator < Kwalify::Validator
|
6
|
+
def initialize(schema_filename)
|
7
|
+
super(Kwalify::Yaml.load_file(schema_filename))
|
8
|
+
end
|
9
|
+
|
10
|
+
## hook method called by Validator#validate()
|
11
|
+
def validate_hook(value, rule, path, errors)
|
12
|
+
case rule.name
|
13
|
+
when "DiskURL"
|
14
|
+
begin
|
15
|
+
arr = URI.split(value)
|
16
|
+
if arr[0] != "disk"
|
17
|
+
msg = "Should have protocol disk: #{value}"
|
18
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
19
|
+
end
|
20
|
+
if arr[2] == ""
|
21
|
+
msg = "Should have host specified: #{value}"
|
22
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
23
|
+
end
|
24
|
+
if arr[5] == ""
|
25
|
+
msg = "Should have path specified: #{value}"
|
26
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
27
|
+
end
|
28
|
+
rescue URI::InvalidURIError
|
29
|
+
msg = "Should be a valid URI: #{value}"
|
30
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
31
|
+
end
|
32
|
+
when "FQDN"
|
33
|
+
subregex = /[a-zA-Z0-9\-]{1,63}/
|
34
|
+
endregex = /[\-]\z/
|
35
|
+
startregex = /\A[\-]/
|
36
|
+
numberregex = /\A\d+\z/
|
37
|
+
|
38
|
+
if value.length > 254
|
39
|
+
msg = "Should be a shorter than 254 characters: #{value}"
|
40
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
41
|
+
end
|
42
|
+
|
43
|
+
arr = value.split(".")
|
44
|
+
if arr.length < 2
|
45
|
+
msg = "Must contain 2 or more subdomains: #{value}"
|
46
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
47
|
+
end
|
48
|
+
if arr.last.length < 2
|
49
|
+
msg = "Last subdomain must be more than 1 character: #{value}"
|
50
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
51
|
+
end
|
52
|
+
arr.each do |dn|
|
53
|
+
if dn[subregex].nil?
|
54
|
+
msg = "Can only contain _-A-Za-z0-9: #{value}"
|
55
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
56
|
+
end
|
57
|
+
if !dn[endregex].nil?
|
58
|
+
msg = "Last character can not be - or _: #{value}"
|
59
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
60
|
+
end
|
61
|
+
if !dn[startregex].nil?
|
62
|
+
msg = "First character can not be - or _: #{value}"
|
63
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
64
|
+
end
|
65
|
+
if !dn[numberregex].nil?
|
66
|
+
msg = "Subdomain can not be only numbers: #{value}"
|
67
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
when "Email"
|
71
|
+
regex = /\A([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)\z/
|
72
|
+
if value[regex].nil?
|
73
|
+
msg = "Should be an Email Address: #{value}"
|
74
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
75
|
+
end
|
76
|
+
when "DomainName"
|
77
|
+
# http://tools.ietf.org/html/rfc1034#section-3.5
|
78
|
+
label = /[a-z]([a-z0-9\-]{0,61}[a-z0-9])?/i
|
79
|
+
regex = /\A#{label}(\.#{label})*\z/
|
80
|
+
if value[regex].nil?
|
81
|
+
msg = "Should be a Domain Name: #{value}"
|
82
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
83
|
+
end
|
84
|
+
when "IpAddress"
|
85
|
+
regex = /\A(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)){3}\z/
|
86
|
+
if value[regex].nil?
|
87
|
+
msg = "Should be an IP Address: #{value}"
|
88
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
89
|
+
end
|
90
|
+
when "IpAddressMap"
|
91
|
+
regex = /\A(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)){3}\z/
|
92
|
+
value.each_key do |key|
|
93
|
+
if key[regex].nil?
|
94
|
+
msg = "Should be an IP Address: #{key}"
|
95
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'crowbar/validate/databags/version'
|
2
|
+
require 'crowbar/validate/crowbarvalidator'
|
3
|
+
require 'kwalify'
|
4
|
+
|
5
|
+
module Crowbar
|
6
|
+
module Validate
|
7
|
+
module Databags
|
8
|
+
def self.validate(dir)
|
9
|
+
# add missing slash if needed
|
10
|
+
dir = "#{dir}/" unless dir[-1] == "/"
|
11
|
+
|
12
|
+
schema_files = Dir["#{dir}*.schema"].reject { |f| File.directory? f }
|
13
|
+
migration_folders = Dir["#{dir}migrate/*/"]
|
14
|
+
|
15
|
+
rc = []
|
16
|
+
schema_files.each { |schema| rc.push(validate_schema(schema)) }
|
17
|
+
schema_files.each { |schema| rc.push(validate_json(schema)) }
|
18
|
+
migration_folders.each { |folder| rc.push(validate_migrations(folder)) }
|
19
|
+
return rc.uniq
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.validate_schema(schema_filename)
|
24
|
+
metavalidator = Kwalify::MetaValidator.instance
|
25
|
+
parser = Kwalify::Yaml::Parser.new(metavalidator)
|
26
|
+
parser.parse_file(schema_filename)
|
27
|
+
|
28
|
+
if parser.errors && !parser.errors.empty?
|
29
|
+
parser.errors.each do |e|
|
30
|
+
puts "#{schema_filename}: #{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
31
|
+
end
|
32
|
+
return -1
|
33
|
+
end
|
34
|
+
return 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.validate_json(schema_filename)
|
38
|
+
config_filename = schema_filename.sub(".schema", ".json")
|
39
|
+
validator = CrowbarValidator.new(schema_filename)
|
40
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
41
|
+
parser.parse_file(config_filename)
|
42
|
+
|
43
|
+
if parser.errors && !parser.errors.empty?
|
44
|
+
parser.errors.each do |e|
|
45
|
+
puts "#{config_filename}: #{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
46
|
+
end
|
47
|
+
return -2
|
48
|
+
end
|
49
|
+
return 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.validate_migrations(folder)
|
53
|
+
folder = "#{folder}/" unless folder[-1] == "/"
|
54
|
+
files = Dir["#{folder}*.rb"]
|
55
|
+
migration_numbers = files.map { |f| File.basename(f)[0, 3] }
|
56
|
+
duplicated = migration_numbers.select { |m| migration_numbers.count(m) > 1 }.uniq
|
57
|
+
unless duplicated.empty?
|
58
|
+
puts "Found duplicated number migration(s) on #{folder} with number(s) #{duplicated}"
|
59
|
+
return -3
|
60
|
+
end
|
61
|
+
return 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crowbar-validate-databags
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Itxaka Serrano Garcia
|
8
|
+
- Rick Salevsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: kwalify
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.7'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.16'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.16'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
description:
|
71
|
+
email:
|
72
|
+
- igarcia@suse.com
|
73
|
+
- rsalevsky@suse.com
|
74
|
+
executables:
|
75
|
+
- crowbar-validate-databags
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- CHANGELOG.md
|
83
|
+
- Gemfile
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/crowbar-validate-databags
|
87
|
+
- crowbar-validate-databags.gemspec
|
88
|
+
- lib/crowbar/validate/crowbarvalidator.rb
|
89
|
+
- lib/crowbar/validate/databags.rb
|
90
|
+
- lib/crowbar/validate/databags/version.rb
|
91
|
+
homepage: http://github.com/itxaka/crowbar-validate-databags
|
92
|
+
licenses:
|
93
|
+
- GPL-2.0
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Validates databags of crowbar.
|
115
|
+
test_files: []
|