puppetfile-resolver 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/LICENSE +201 -0
- data/README.md +169 -0
- data/lib/puppetfile-resolver.rb +7 -0
- data/lib/puppetfile-resolver/cache/base.rb +28 -0
- data/lib/puppetfile-resolver/cache/persistent.rb +50 -0
- data/lib/puppetfile-resolver/data/ruby_ca_certs.pem +3432 -0
- data/lib/puppetfile-resolver/models.rb +8 -0
- data/lib/puppetfile-resolver/models/missing_module_specification.rb +27 -0
- data/lib/puppetfile-resolver/models/module_dependency.rb +55 -0
- data/lib/puppetfile-resolver/models/module_specification.rb +114 -0
- data/lib/puppetfile-resolver/models/puppet_dependency.rb +34 -0
- data/lib/puppetfile-resolver/models/puppet_specification.rb +25 -0
- data/lib/puppetfile-resolver/models/puppetfile_dependency.rb +14 -0
- data/lib/puppetfile-resolver/puppetfile.rb +22 -0
- data/lib/puppetfile-resolver/puppetfile/base_module.rb +62 -0
- data/lib/puppetfile-resolver/puppetfile/document.rb +125 -0
- data/lib/puppetfile-resolver/puppetfile/forge_module.rb +14 -0
- data/lib/puppetfile-resolver/puppetfile/git_module.rb +19 -0
- data/lib/puppetfile-resolver/puppetfile/invalid_module.rb +16 -0
- data/lib/puppetfile-resolver/puppetfile/local_module.rb +14 -0
- data/lib/puppetfile-resolver/puppetfile/parser/errors.rb +19 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb +133 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb +51 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb +50 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/git.rb +32 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/invalid.rb +27 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.rb +26 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/svn.rb +30 -0
- data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/puppet_module.rb +36 -0
- data/lib/puppetfile-resolver/puppetfile/svn_module.rb +16 -0
- data/lib/puppetfile-resolver/puppetfile/validation_errors.rb +106 -0
- data/lib/puppetfile-resolver/resolution_provider.rb +182 -0
- data/lib/puppetfile-resolver/resolution_result.rb +30 -0
- data/lib/puppetfile-resolver/resolver.rb +77 -0
- data/lib/puppetfile-resolver/spec_searchers/common.rb +15 -0
- data/lib/puppetfile-resolver/spec_searchers/forge.rb +75 -0
- data/lib/puppetfile-resolver/spec_searchers/git.rb +64 -0
- data/lib/puppetfile-resolver/spec_searchers/local.rb +45 -0
- data/lib/puppetfile-resolver/ui/debug_ui.rb +15 -0
- data/lib/puppetfile-resolver/ui/null_ui.rb +20 -0
- data/lib/puppetfile-resolver/util.rb +23 -0
- data/lib/puppetfile-resolver/version.rb +5 -0
- data/puppetfile-cli.rb +101 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/unit/puppetfile-resolver/puppetfile/document_spec.rb +316 -0
- data/spec/unit/puppetfile-resolver/puppetfile/parser/r10k_eval_spec.rb +460 -0
- data/spec/unit/puppetfile-resolver/resolver_spec.rb +421 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7369652a185b5b8cbd2cbcbf4c0a728303a03779e8c5fc363430855de1f90f31
|
4
|
+
data.tar.gz: 7b9457a73ad065fed6edefd3c756ed4b90a1c660548a88ba2b1411d07668e8fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7af088bf31a4c96bd1fe3cf2a3853297d079c2fdd15d7c49a4aeb3f1e1290c88c58298ab7a63c326420e67fc74c86051f6858ed98b9337ddcf0e73a25603c15
|
7
|
+
data.tar.gz: 0d32efc05cd6a1ffcb6825ce4a78fd919aa8705a5b45cd930912ac723d9271988e912a2985c91b4603a2610be4edc9fb687d644e4ac8df0cb53197fc776a1ad1
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2020 Glenn Sarti
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
[![Build Status](https://travis-ci.com/lingua-pupuli/puppetfile-resolver.svg?branch=master)](https://travis-ci.com/lingua-pupuli/puppetfile-resolver)
|
2
|
+
|
3
|
+
# Puppetfile Resolver
|
4
|
+
|
5
|
+
The [Puppetfile](https://puppet.com/docs/pe/latest/puppetfile.html) is used by Puppet to manage the collection of modules used by a Puppet master. The Puppetfile is then used by tools like [R10K](https://github.com/puppetlabs/r10k) and [Code Manager](https://puppet.com/docs/pe/latest/code_mgr_how_it_works.html#how-code-manager-works) to download and install the required modules.
|
6
|
+
|
7
|
+
However, the Puppetfile is designed to have explicit dependencies, that is, **all** modules and **all** of the dependencies must be specified in Puppetfile. This is very different to formats like `Gemfile` (Ruby) or `package.json` (NodeJS) where dependencies are brought in as needed.
|
8
|
+
|
9
|
+
Using explicit dependencies is great in a configuration management system like Puppet, but it puts the burden on updates onto the user.
|
10
|
+
|
11
|
+
This library includes all of the code to parse a Puppetfile and then calculate a dependency graph to try and resolve all of the module dependencies and versions. The resolver can also restrict on Puppet version, for example, only Modules which support Puppet 6.
|
12
|
+
|
13
|
+
**Note** This is still in active development. Git history may be re-written until an initial version is released
|
14
|
+
|
15
|
+
## To Do
|
16
|
+
|
17
|
+
- Could do with more tests
|
18
|
+
- Add YARD documentation
|
19
|
+
|
20
|
+
## Why a library and not a CLI tool?
|
21
|
+
|
22
|
+
Due to all of the different needs of tool developers, this is offered as a library instead of full blown CLI tool. For example, the needs of a VSCode Extensions developer are very different than that of the Puppet Developer Kit developer.
|
23
|
+
|
24
|
+
Therefore this is a library which is intended to be used by tool developers to create useful tools for users, and not really for direct use by users.
|
25
|
+
|
26
|
+
Note that a CLI is included (`puppetfile-cli.rb`) only as an example of how to create a tool using this library.
|
27
|
+
|
28
|
+
## Architecture
|
29
|
+
|
30
|
+
``` text
|
31
|
+
+-----------------+ +-----------------+ +-----------------+
|
32
|
+
| Forge Searcher | | Github Searcher | | Local Searcher |
|
33
|
+
+-------+---------+ +--------+--------+ +-------+---------+
|
34
|
+
| | |
|
35
|
+
+----------------------+--------------------+
|
36
|
+
|
|
37
|
+
|
|
38
|
+
V
|
39
|
+
+--------+ +----------+ +-------------------+
|
40
|
+
-- Text --> | Parser | -- Document Model -+-> | Resolver | -- Dependency Graph -+-> | Resolution Result |
|
41
|
+
+--------+ | +----------+ | +-------------------+
|
42
|
+
| |
|
43
|
+
| |
|
44
|
+
V V
|
45
|
+
+-----------+ +------------+
|
46
|
+
| Document | | Resolution |
|
47
|
+
| Validator | | Validator |
|
48
|
+
+-----------+ +------------+
|
49
|
+
```
|
50
|
+
|
51
|
+
### Puppetfile Parser
|
52
|
+
|
53
|
+
The parser converts the content of a Puppetfile into a document model (`PuppetfileResolver::Puppetfile`).
|
54
|
+
|
55
|
+
Currently only one Parser is available, `R10KEval`, which uses the same parsing logic as the [R10K Parser](https://github.com/puppetlabs/r10k/blob/master/lib/r10k/puppetfile.rb). In the future other parsers may be added, such as a [Ruby AST based parser](https://github.com/puppetlabs/r10k/pull/885).
|
56
|
+
|
57
|
+
#### R10KEval Parser
|
58
|
+
|
59
|
+
Sometimes it necessary to instruct the Resolver to ignore certain rules, for example ignoring the Puppet restrictions on a module because it has old metadata. The R10KEval Parser can read ruby comments which have special meanings, similar to how [rubocop](https://docs.rubocop.org/en/stable/) uses [magic comments](https://docs.rubocop.org/en/stable/configuration/#disabling-cops-within-source-code).
|
60
|
+
|
61
|
+
The R10KEval Parser uses the magic comment of `# resolver:disable` to disable tasks. For example;
|
62
|
+
|
63
|
+
You can set a comment for one module like this:
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
mod 'puppetlabs-stdlib', :latest # resolver:disable Dependency/All
|
67
|
+
```
|
68
|
+
|
69
|
+
or for many modules by wrapping the modules like this:
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
# resolver:disable Dependency/All
|
73
|
+
mod 'puppetlabs-stdlib', :latest
|
74
|
+
mod 'puppetlabs-apache', '1.0.0'
|
75
|
+
# resolver:ensable Dependency/All
|
76
|
+
```
|
77
|
+
|
78
|
+
You can also set multiple items by using a comma like this:
|
79
|
+
|
80
|
+
``` ruby
|
81
|
+
mod 'puppetlabs-stdlib', :latest # resolver:disable Dependency/All,Dependency/Puppet
|
82
|
+
```
|
83
|
+
|
84
|
+
Note there is no space between items.
|
85
|
+
|
86
|
+
The available settings are:
|
87
|
+
|
88
|
+
| Setting Name | Description |
|
89
|
+
| --------------------| ----------- |
|
90
|
+
| `Dependency/Puppet` | Instructs the resolver to ignore any Puppet version in its dependency traversal for the specified modules. Useful for modules with outdated metadata.json information |
|
91
|
+
| `Dependency/All` | Instructs the resolver to ignore any, and all, dependencies in its dependency traversal of the specified module. Useful for modules with outdated metadata.json information. |
|
92
|
+
|
93
|
+
### Puppetfile Document Validation
|
94
|
+
|
95
|
+
Even though a Puppetfile can be parsed, doesn't mean it's valid. For example, defining a module twice.
|
96
|
+
|
97
|
+
### Puppetfile Resolution
|
98
|
+
|
99
|
+
Given a Puppetfile document model, the library can attempt to recursively resolve all of the modules and their dependencies. The resolver be default will not be strict, that is, missing dependencies will not throw an error, and will attempt to also be resolved. When in strict mode, any missing dependencies will throw errors.
|
100
|
+
|
101
|
+
### Module Searchers
|
102
|
+
|
103
|
+
The Puppetfile resolution needs information about all of the available modules and versions, and does this through calling various Specification Searchers. Currently Puppet Forge, Github and Local FileSystem searchers are implemented. Additional searchers could be added, for example GitLab or SVN.
|
104
|
+
|
105
|
+
The result is a dependency graph listing all of the modules, dependencies and version information.
|
106
|
+
|
107
|
+
### Resolution validation
|
108
|
+
|
109
|
+
Even though a Puppetfile can be resolved, doesn't mean it is valid. For example, missing module dependencies are not considered valid.
|
110
|
+
|
111
|
+
### Dependency Graph
|
112
|
+
|
113
|
+
The resolver uses the [Molinillo](https://github.com/CocoaPods/Molinillo) ruby gem for dependency resolution. Molinillo is used in Bundler, among other gems, so it's well used and maintained project.
|
114
|
+
|
115
|
+
### Example workflow
|
116
|
+
|
117
|
+
1. Load the contents of a Puppetfile from disk
|
118
|
+
|
119
|
+
2. Parse the Puppetfile into a document model
|
120
|
+
|
121
|
+
3. Verify that the document model is valid
|
122
|
+
|
123
|
+
4. Create a resolver object with the document model, and the required Puppet version (optional)
|
124
|
+
|
125
|
+
5. Start the resolution
|
126
|
+
|
127
|
+
6. Validate the resolution against the document model
|
128
|
+
|
129
|
+
### Example usage
|
130
|
+
|
131
|
+
``` ruby
|
132
|
+
puppetfile_path = '/path/to/Puppetfile'
|
133
|
+
|
134
|
+
# Parse the Puppetfile into an object model
|
135
|
+
content = File.open(puppetfile_path, 'rb') { |f| f.read }
|
136
|
+
require 'puppetfile-resolver/puppetfile/parser/r10k_eval'
|
137
|
+
puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
|
138
|
+
|
139
|
+
# Make sure the Puppetfile is valid
|
140
|
+
unless puppetfile.valid?
|
141
|
+
puts 'Puppetfile is not valid'
|
142
|
+
puppetfile.validation_errors.each { |err| puts err }
|
143
|
+
exit 1
|
144
|
+
end
|
145
|
+
|
146
|
+
# Create the resolver
|
147
|
+
# - Use the document we just parsed (puppetfile)
|
148
|
+
# - Don't restrict by Puppet version (nil)
|
149
|
+
resolver = PuppetfileResolver::Resolver.new(puppetfile, nil)
|
150
|
+
|
151
|
+
# Configure the resolver
|
152
|
+
cache = nil # Use the default inmemory cache
|
153
|
+
ui = nil # Don't output any information
|
154
|
+
module_paths = [] # List of paths to search for modules on the local filesystem
|
155
|
+
allow_missing_modules = true # Allow missing dependencies to be resolved
|
156
|
+
opts = { cache: cache, ui: ui, module_paths: module_paths, allow_missing_modules: allow_missing_modules }
|
157
|
+
|
158
|
+
# Resolve
|
159
|
+
result = resolver.resolve(opts)
|
160
|
+
|
161
|
+
# Output resolution validation errors
|
162
|
+
result.validation_errors.each { |err| puts "Resolution Validation Error: #{err}\n"}
|
163
|
+
```
|
164
|
+
|
165
|
+
## Known issues
|
166
|
+
|
167
|
+
- The Forge module searcher will only use the internet facing forge ([https://forge.puppet.com](https://forge.puppet.com/)). Self-hosted forges are not supported
|
168
|
+
|
169
|
+
- The Git module searcher will only search public Github based modules. Private repositories or other VCS systems are not supported
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PuppetfileResolver
|
4
|
+
module Cache
|
5
|
+
class Base
|
6
|
+
def initialize(*_)
|
7
|
+
@inmemory = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def exist?(name)
|
11
|
+
@inmemory.key?(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def load(name)
|
15
|
+
@inmemory[name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def save(name, value, persist = false)
|
19
|
+
@inmemory[name] = value
|
20
|
+
persist(name, value) if persist
|
21
|
+
end
|
22
|
+
|
23
|
+
def persist(_name, content_string)
|
24
|
+
raise 'Can only persist String data types' unless content_string.is_a?(String)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'puppetfile-resolver/cache/base'
|
4
|
+
|
5
|
+
# TODO: This is currently redundant as there are no calls to persist the data
|
6
|
+
|
7
|
+
module PuppetfileResolver
|
8
|
+
module Cache
|
9
|
+
class Persistent < Base
|
10
|
+
def initialize(cache_directory)
|
11
|
+
super
|
12
|
+
|
13
|
+
require 'digest'
|
14
|
+
require 'json'
|
15
|
+
@cache_directory = cache_directory
|
16
|
+
Dir.mkdir(@cache_directory) unless Dir.exist?(@cache_directory)
|
17
|
+
end
|
18
|
+
|
19
|
+
def exist?(name)
|
20
|
+
result = super
|
21
|
+
return result if result
|
22
|
+
filename = File.join(@cache_directory, to_cache_name(name))
|
23
|
+
File.exist?(filename)
|
24
|
+
end
|
25
|
+
|
26
|
+
def load(name)
|
27
|
+
result = super
|
28
|
+
return result unless result.nil?
|
29
|
+
|
30
|
+
filename = File.join(@cache_directory, to_cache_name(name))
|
31
|
+
return nil unless File.exist?(filename)
|
32
|
+
|
33
|
+
::JSON.parse(File.open(filename, 'rb:utf-8') { |f| f.read })
|
34
|
+
end
|
35
|
+
|
36
|
+
def persist(name, content_string)
|
37
|
+
super
|
38
|
+
|
39
|
+
filename = File.join(@cache_directory, to_cache_name(name))
|
40
|
+
File.open(filename, 'wb:utf-8') { |f| f.write(content_string) }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def to_cache_name(name)
|
46
|
+
::Digest::SHA256.hexdigest(name) + '.txt'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|