oo-cartridge-tools 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # OpenShift Cartridge Lint
2
+
3
+ The OpenShift Cartridge Lint is an utility which helps developers to test
4
+ the validity and syntax of the cartridge metadata.
5
+
6
+ In future this command will be expanded to provide more functionality, but for
7
+ now you can use it to validate the cartridge 'manifest.yml' file to make sure
8
+ you haven't missed some required attribute or you not made the syntax error.
9
+
10
+ ## Using oo-cartridge-lint
11
+
12
+ ### Dependencies:
13
+
14
+ * [kwalify](http://www.kuwata-lab.com/kwalify)
15
+ * [commander](http://visionmedia.github.io/commander)
16
+
17
+ (Don't worry, these dependencies are installed automatically for you)
18
+
19
+ ### Installation:
20
+
21
+ ```
22
+ $ gem install oo-cartridge-lint
23
+ ```
24
+
25
+ (the Fedora/RHEL packages are TBD)
26
+
27
+ ### Usage:
28
+
29
+ To check your current cartridge, you can run the following command:
30
+
31
+ ```
32
+ $ cd cartridge-dir/
33
+ $ oo-cartridge-lint manifest
34
+ ```
35
+
36
+ The output should tell you if your manifest.yml has correct syntax or not. The
37
+ sample output might look like this:
38
+
39
+ ```
40
+ ~/code/openshift-origin-cartridge-ruby → oo-cartridge-lint manifest --file metadata/manifest.yml.rhel
41
+ [openshift-origin-cartridge-ruby/metadata/manifest.yml.rhel] INVALID
42
+ [/] - key 'Description:' is required.
43
+ [/Architecture] - 'arm': invalid Architecture value.
44
+ ```
45
+
46
+ (Note: The --file option is optional, by default the command will check the `metadata/manifest.yml` path.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+
6
+ require_relative '../lib/openshift/cartridge_utils'
7
+
8
+ program :name, 'OpenShift cartridge lint'
9
+ program :version, '1.0.0'
10
+ program :description, 'Validate the OpenShift cartridge'
11
+
12
+ command :manifest do |c|
13
+ c.syntax = 'manifest'
14
+ c.description = 'Validates the manifest.yml'
15
+ c.option '--file STRING', String, 'The manifest.yml path (default: ./metadata/manifest.yml'
16
+ c.option '--schema STRING', String, 'Override the manifest.yaml kwalify schema'
17
+
18
+ c.action do |_, options|
19
+ manifest_file = OpenShift::CartridgeUtils::Lint.guess_manifest_path(options.file)
20
+ schema_file = OpenShift::CartridgeUtils::Lint.guess_schema_path(options.schema)
21
+ result = OpenShift::CartridgeUtils::Lint.parse(manifest_file, schema_file)
22
+ if result.errors?
23
+ say "[#{manifest_file}] INVALID"
24
+ result.errors.each { |e| say " [#{e.path}] - #{e.message}" }
25
+ exit(1)
26
+ else
27
+ say "[#{manifest_file}] VALID"
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ module OpenShift
2
+ module CartridgeTools
3
+ require_relative './cartridge_tools/lint'
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'kwalify'
3
+
4
+ module OpenShift
5
+ module CartridgeTools
6
+
7
+ class Lint
8
+
9
+ CURRENT_MANIFEST_SCHEMA = "manifest_schema_20130929.yml"
10
+
11
+ def self.guess_manifest_path(file=nil)
12
+ base_path = Dir.pwd
13
+ unless file.nil?
14
+ file_path = File.join(base_path, file)
15
+ else
16
+ file_path = File.join(base_path, 'metadata', 'manifest.yml')
17
+ end
18
+ raise "File not found: #{file_path}" unless File.exists?(file_path)
19
+ return file_path
20
+ end
21
+
22
+ def self.guess_schema_path(schema=nil)
23
+ base_path = Dir.pwd
24
+ unless schema.nil?
25
+ schema_path = File.join(base_path, schema)
26
+ else
27
+ schema_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'schema', CURRENT_MANIFEST_SCHEMA)
28
+ end
29
+ raise "Schema not found: #{schema_path}" unless File.exists?(schema_path)
30
+ return schema_path
31
+ end
32
+
33
+ def self.parse(manifest_file, schema_file=nil)
34
+ manifest = YAML.load_file(manifest_file)
35
+ schema = Kwalify::Yaml.load_file(schema_file)
36
+ validator = Kwalify::Validator.new(schema)
37
+ LintResult.get(validator.validate(manifest))
38
+ end
39
+
40
+ class LintResult
41
+ attr_accessor :errors
42
+
43
+ def initialize(errors)
44
+ @errors = errors
45
+ end
46
+
47
+ def self.get(validator)
48
+ self.new(validator)
49
+ end
50
+
51
+ def errors?; !errors.empty?; end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,165 @@
1
+ &manifest
2
+ type: map
3
+ required: yes
4
+ mapping:
5
+ "Name":
6
+ required: yes
7
+ "Cartridge-Short-Name":
8
+ required: yes
9
+ pattern: /[A-Z_]+/
10
+ "Display-Name":
11
+ required: yes
12
+ "Architecture":
13
+ enum: [ 'noarch', 'i386', 'x86_64' ]
14
+ "Description":
15
+ required: yes
16
+ "Version":
17
+ required: yes
18
+ pattern: /^([\d\.]+)$/
19
+ "Versions":
20
+ type: seq
21
+ sequence:
22
+ - { unique: yes }
23
+ "License":
24
+ required: yes
25
+ "License-Url":
26
+ pattern: /^http(s?):\/\//
27
+ "Vendor":
28
+ required: yes
29
+ "Cartridge-Version":
30
+ required: yes
31
+ pattern: /[0-9][0-9\.]*/
32
+ "Compatible-Versions":
33
+ type: seq
34
+ sequence:
35
+ - { unique: yes, pattern: "/[0-9][0-9\.]*/" }
36
+ "Cartridge-Vendor":
37
+ required: yes
38
+ "Categories":
39
+ type: seq
40
+ required: yes
41
+ sequence:
42
+ - { unique: yes, required: true, pattern: "/[a-z][a-z_]*/" }
43
+ "Website":
44
+ pattern: /^http(s?):\/\//
45
+ "Help-Topics":
46
+ type: map
47
+ mapping:
48
+ "Developer Center":
49
+ "=": { type: str }
50
+ "Cart-Data":
51
+ type: seq
52
+ sequence:
53
+ - type: map
54
+ mapping:
55
+ "Key":
56
+ required: true
57
+ "Type":
58
+ required: true
59
+ enum: [environment, cart_data]
60
+ "Description":
61
+ required: true
62
+ "Publishes": &publishes
63
+ type: map
64
+ mapping:
65
+ "=":
66
+ type: map
67
+ mapping:
68
+ "Type":
69
+ pattern: /^(ENV|STRING|NET_TCP|NET_UDP|FILESYSTEM)\:/
70
+ "Subscribes": &subscribes
71
+ type: map
72
+ mapping:
73
+ "=":
74
+ type: map
75
+ mapping:
76
+ "Type":
77
+ pattern: /^(ENV|STRING|NET_TCP|NET_UDP|FILESYSTEM)\:/
78
+ "Required":
79
+ type: bool
80
+ "Scaling": &scaling
81
+ type: map
82
+ mapping:
83
+ "Min": &scale_type
84
+ type: int
85
+ range: { max: 10, min: -10 }
86
+ "Max": *scale_type
87
+ "Multiplier": *scale_type
88
+ "Provides":
89
+ type: seq
90
+ sequence:
91
+ - { unique: yes }
92
+ "Endpoints":
93
+ type: seq
94
+ sequence:
95
+ - type: map
96
+ mapping:
97
+ "Private-IP-Name": { required: yes, pattern: "/[A-Z][A-Z_]+/" }
98
+ "Private-Port-Name": { required: yes, pattern: "/[A-Z][A-Z_]+/" }
99
+ "Private-Port": { type: int, range: { min-ex: 1024 } }
100
+ "Public-Port-Name": { unique: yes, pattern: "/[A-Z][A-Z_]+/" }
101
+ "WebSocket-Port": { type: int, range: { min-ex: 1024 } }
102
+ "WebSocket-Port-Name": { unique: yes, pattern: "/[A-Z][A-Z_]+/" }
103
+ "Protocols":
104
+ type: seq
105
+ sequence:
106
+ - { unique: yes }
107
+ "Options":
108
+ type: map
109
+ mapping:
110
+ "ssl_to_gear": {type: bool}
111
+ "Mappings":
112
+ type: seq
113
+ sequence:
114
+ - type: map
115
+ mapping:
116
+ "Frontend": { required: yes }
117
+ "Backend": { required: yes }
118
+ "Options":
119
+ type: map
120
+ mapping:
121
+ "websocket": { type: any, enum: [true, false, 1, 0] }
122
+ "health": {type: any, enum: [true, false, 1,0] }
123
+ "target_update": { type: any, enum: [true, false, 1, 0] }
124
+ "connections": { type: int }
125
+ "file": {type: any, enum: [true, false, 1, 0] }
126
+ "tohttps": {type: any, enum: [true, false, 1, 0] }
127
+ "Additional-Control-Actions":
128
+ type: seq
129
+ sequence:
130
+ - { unique: yes, enum: [threaddump] }
131
+ "Configure-Order":
132
+ type: seq
133
+ sequence:
134
+ - { unique: yes, pattern: "/[a-z-]+/" }
135
+ "Group-Overrides":
136
+ type: seq
137
+ sequence:
138
+ - type: map
139
+ mapping:
140
+ "components":
141
+ type: seq
142
+ sequence:
143
+ - { type: str, unique: yes, pattern: "/[a-z-]+/" }
144
+ "Components":
145
+ type: map
146
+ mapping:
147
+ "=":
148
+ type: map
149
+ mapping:
150
+ "Publishes": *publishes
151
+ "Subscribes": *subscribes
152
+ "Scaling": *scaling
153
+ "Version-Overrides":
154
+ type: map
155
+ mapping:
156
+ "=":
157
+ type: map
158
+ mapping:
159
+ "=": { type: any }
160
+ "Suggests":
161
+ type: seq
162
+ sequence:
163
+ - { unique: yes }
164
+ "Install-Build-Required":
165
+ type: bool
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oo-cartridge-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michal Fojtik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kwalify
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: commander
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Various utilities to help with OpenShift cartridge development
47
+ email:
48
+ - mfojtik@redhat.com
49
+ executables:
50
+ - oo-cartridge-lint
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/openshift/cartridge_tools.rb
55
+ - lib/openshift/cartridge_tools/lint.rb
56
+ - bin/oo-cartridge-lint
57
+ - schema/manifest_schema_20130929.yml
58
+ - README.md
59
+ homepage: https://github.com/mfojtik/oo-cartridge-tools
60
+ licenses:
61
+ - ASL 2.0
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.23
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: OpenShift Cartridge utilities
84
+ test_files: []