metadata_json_deps 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +47 -0
- data/bin/metadata-json-deps +13 -0
- data/lib/metadata_json_deps/forge_versions.rb +31 -0
- data/lib/metadata_json_deps/metadata_checker.rb +26 -0
- data/lib/metadata_json_deps/runner.rb +32 -0
- data/lib/metadata_json_deps.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0a7a5bc8b50fa0665c13ff641af0c71eb6a7b8d968712b0f5e1ded9aa97e09d4
|
4
|
+
data.tar.gz: 240b09bfb0f276ad80aade880427ebd242adb17a3dc7f49d185c01b513af9f33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62f244b8ad184507bfe491620ce0441fe94f3cd1df6dd152fa3f3deca5d9ad32c2eb069d6c0b002cd79dc2fd0379776a285a212c8bb482773350f938dcab313c
|
7
|
+
data.tar.gz: 0acedb635823a5e5b7c25e29a2c192e237af76739fa6afb7688b593baeba0d89f253b4dd6c5f06992ed609cc9cdd98c2ef396d7681437b9fcdfbe98c740f48ee
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# metadata-json-deps
|
2
|
+
|
3
|
+
The metadata-json-deps tool validates dependencies in `metadata.json` files in Puppet modules against the latest published versions on the [Puppet Forge](https://forge.puppet.com/).
|
4
|
+
|
5
|
+
## Compatibility
|
6
|
+
|
7
|
+
metadata-json-deps is compatible with Ruby versions 2.0.0 and newer.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
via `gem` command:
|
12
|
+
``` shell
|
13
|
+
gem install metadata-json-deps
|
14
|
+
```
|
15
|
+
|
16
|
+
via Gemfile:
|
17
|
+
``` ruby
|
18
|
+
gem 'metadata-json-deps'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Testing with metadata-json-deps
|
24
|
+
|
25
|
+
On the command line, run `metadata-json-deps` with the path(s) of your `metadata.json` file(s):
|
26
|
+
|
27
|
+
```shell
|
28
|
+
metadata-json-deps /path/to/metadata.json
|
29
|
+
```
|
30
|
+
|
31
|
+
It can also be run verbosely to show valid dependencies:
|
32
|
+
|
33
|
+
```shell
|
34
|
+
metadata-json-deps -v modules/*/metadata.json
|
35
|
+
```
|
36
|
+
|
37
|
+
### Testing with metadata-json-deps as a Rake task
|
38
|
+
|
39
|
+
You can also integrate `metadata-json-deps` checks into your tests using a Rake task:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'metadata_json_deps'
|
43
|
+
task :metadata_deps do
|
44
|
+
files = FileList['modules/*/metadata.json']
|
45
|
+
PuppetMetadataChecker::Runner.run(files)
|
46
|
+
end
|
47
|
+
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'metadata_json_deps'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
9
|
+
options[:verbose] = v
|
10
|
+
end
|
11
|
+
end.parse!
|
12
|
+
|
13
|
+
MetadataJsonDeps::Runner.run(ARGV, options[:verbose])
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'puppet_forge'
|
2
|
+
require 'semantic_puppet'
|
3
|
+
|
4
|
+
module MetadataJsonDeps
|
5
|
+
class ForgeVersions
|
6
|
+
def initialize(cache = {})
|
7
|
+
@cache = cache
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_current_version(name)
|
11
|
+
name = name.sub('/', '-')
|
12
|
+
version = @cache[name]
|
13
|
+
|
14
|
+
unless version
|
15
|
+
@cache[name] = version = get_version(get_mod(name))
|
16
|
+
end
|
17
|
+
|
18
|
+
version
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def get_mod(name)
|
24
|
+
PuppetForge::Module.find(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_version(mod)
|
28
|
+
SemanticPuppet::Version.parse(mod.current_release.version)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'semantic_puppet'
|
2
|
+
|
3
|
+
module MetadataJsonDeps
|
4
|
+
class MetadataChecker
|
5
|
+
def initialize(metadata, forge)
|
6
|
+
@metadata = metadata
|
7
|
+
@forge = forge
|
8
|
+
end
|
9
|
+
|
10
|
+
def module_dependencies
|
11
|
+
return [] unless @metadata['dependencies']
|
12
|
+
|
13
|
+
@metadata['dependencies'].map do |dep|
|
14
|
+
constraint = dep['version_requirement'] || '>= 0'
|
15
|
+
[dep['name'], SemanticPuppet::VersionRange.parse(constraint)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def dependencies
|
20
|
+
module_dependencies.map do |dependency, constraint|
|
21
|
+
current = @forge.get_current_version(dependency)
|
22
|
+
[dependency, constraint, current, constraint.include?(current)]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MetadataJsonDeps
|
4
|
+
class Runner
|
5
|
+
def initialize(filenames, verbose)
|
6
|
+
@filenames = filenames
|
7
|
+
@verbose = verbose
|
8
|
+
@forge = MetadataJsonDeps::ForgeVersions.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
@filenames.each do |filename|
|
13
|
+
puts "Checking #{filename}"
|
14
|
+
checker = MetadataJsonDeps::MetadataChecker.new(JSON.parse(File.read(filename)), @forge)
|
15
|
+
checker.dependencies.each do |dependency, constraint, current, satisfied|
|
16
|
+
if satisfied
|
17
|
+
if @verbose
|
18
|
+
puts " #{dependency} (#{constraint}) matches #{current}"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
puts " #{dependency} (#{constraint}) doesn't match #{current}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue Interrupt
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.run(filenames, verbose = false)
|
29
|
+
self.new(filenames, verbose).run
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metadata_json_deps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ewoud Kohl van Wijngaarden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puppet_forge
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: semantic_puppet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: Verify all your dependencies allow the latest versions on Puppet Forge
|
42
|
+
email: ewoud+rubygems@kohlvanwijngaarden.nl
|
43
|
+
executables:
|
44
|
+
- metadata-json-deps
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- bin/metadata-json-deps
|
51
|
+
- lib/metadata_json_deps.rb
|
52
|
+
- lib/metadata_json_deps/forge_versions.rb
|
53
|
+
- lib/metadata_json_deps/metadata_checker.rb
|
54
|
+
- lib/metadata_json_deps/runner.rb
|
55
|
+
homepage: https://github.com/ekohl/metadata_json_deps
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
source_code_uri: https://github.com/ekohl/metadata_json_deps
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.0
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.7.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Check your Puppet metadata dependencies
|
80
|
+
test_files: []
|