onceover-lookup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 338db64a91beffef6d50d429661d801d1f9f0faa576c5237ebf393e25a9698c2
4
+ data.tar.gz: ec7bdfbbc369929e9866769cf9bee4fc167b4db6255f0348bc49dc6faeece441
5
+ SHA512:
6
+ metadata.gz: 2223de384ef4df55d59bd130b9f208b3329b8b449c5f7f43324460429243a75de015af131e1b0588edf3d5fc3947432c745a11d3b656f12a0d75581fbc286873
7
+ data.tar.gz: '08d7163321d03f761ffee1651d7b6ced916bab05aefadd0fdcab8cba92e205a6a169c1d11780a36fb8a23bd811ed2d637a9c8ae3b2f9336f0fb07eaa6eb97cdf'
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /.idea
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in onceover-lookup.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,139 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onceover-lookup (0.1.0)
5
+ onceover (~> 3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ blockenspiel (0.5.0)
11
+ colored (1.2)
12
+ cri (2.15.2)
13
+ colored (~> 1.2)
14
+ deep_merge (1.2.1)
15
+ diff-lcs (1.3)
16
+ facter (2.5.1)
17
+ faraday (0.13.1)
18
+ multipart-post (>= 1.2, < 3)
19
+ faraday_middleware (0.12.2)
20
+ faraday (>= 0.7.4, < 1.0)
21
+ fast_gettext (1.1.2)
22
+ gettext (3.2.9)
23
+ locale (>= 2.0.5)
24
+ text (>= 1.3.0)
25
+ gettext-setup (0.30)
26
+ fast_gettext (~> 1.1.0)
27
+ gettext (>= 3.0.2)
28
+ locale
29
+ git (1.5.0)
30
+ hiera (3.4.5)
31
+ hocon (1.2.5)
32
+ httpclient (2.8.3)
33
+ json (2.1.0)
34
+ little-plugger (1.1.4)
35
+ locale (2.1.2)
36
+ log4r (1.1.10)
37
+ logging (2.2.2)
38
+ little-plugger (~> 1.1)
39
+ multi_json (~> 1.10)
40
+ metaclass (0.0.4)
41
+ minitar (0.7)
42
+ mocha (1.7.0)
43
+ metaclass (~> 0.0.1)
44
+ multi_json (1.13.1)
45
+ multipart-post (2.0.0)
46
+ onceover (3.8.0)
47
+ colored (~> 1.2)
48
+ cri (>= 2.6)
49
+ deep_merge (>= 1.0.0)
50
+ git
51
+ json (>= 1.8.2)
52
+ logging (>= 2.0.0)
53
+ parallel_tests (>= 2.0.0)
54
+ puppet (>= 3.4.0)
55
+ puppetlabs_spec_helper (>= 0.4.0)
56
+ r10k (>= 2.1.0)
57
+ rake (>= 10.0.0)
58
+ rspec (>= 3.0.0)
59
+ rspec-puppet (>= 2.4.0)
60
+ rspec-puppet-utils (>= 2.0.0)
61
+ rspec_junit_formatter (>= 0.2.0)
62
+ table_print (>= 1.0.0)
63
+ versionomy (>= 0.5.0)
64
+ parallel (1.12.1)
65
+ parallel_tests (2.27.0)
66
+ parallel
67
+ puppet (6.0.4)
68
+ facter (> 2.0.1, < 4)
69
+ fast_gettext (~> 1.1.2)
70
+ hiera (>= 3.2.1, < 4)
71
+ httpclient (~> 2.8)
72
+ locale (~> 2.1)
73
+ multi_json (~> 1.10)
74
+ puppet-resource_api (~> 1.5)
75
+ semantic_puppet (~> 1.0)
76
+ puppet-lint (2.3.6)
77
+ puppet-resource_api (1.6.2)
78
+ hocon (>= 1.0)
79
+ puppet-syntax (2.4.1)
80
+ rake
81
+ puppet_forge (2.2.9)
82
+ faraday (>= 0.9.0, < 0.14.0)
83
+ faraday_middleware (>= 0.9.0, < 0.13.0)
84
+ gettext-setup (~> 0.11)
85
+ minitar
86
+ semantic_puppet (~> 1.0)
87
+ puppetlabs_spec_helper (2.12.0)
88
+ mocha (~> 1.0)
89
+ puppet-lint (~> 2.0)
90
+ puppet-syntax (~> 2.0)
91
+ rspec-puppet (~> 2.0)
92
+ r10k (3.0.3)
93
+ colored (= 1.2)
94
+ cri (~> 2.15.1)
95
+ gettext-setup (~> 0.24)
96
+ log4r (= 1.1.10)
97
+ multi_json (~> 1.10)
98
+ puppet_forge (~> 2.2.8)
99
+ rake (10.5.0)
100
+ rspec (3.8.0)
101
+ rspec-core (~> 3.8.0)
102
+ rspec-expectations (~> 3.8.0)
103
+ rspec-mocks (~> 3.8.0)
104
+ rspec-core (3.8.0)
105
+ rspec-support (~> 3.8.0)
106
+ rspec-expectations (3.8.2)
107
+ diff-lcs (>= 1.2.0, < 2.0)
108
+ rspec-support (~> 3.8.0)
109
+ rspec-mocks (3.8.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.8.0)
112
+ rspec-puppet (2.7.1)
113
+ rspec
114
+ rspec-puppet-utils (3.4.0)
115
+ mocha
116
+ puppet
117
+ puppetlabs_spec_helper
118
+ rspec
119
+ rspec-puppet
120
+ rspec-support (3.8.0)
121
+ rspec_junit_formatter (0.4.1)
122
+ rspec-core (>= 2, < 4, != 2.12.0)
123
+ semantic_puppet (1.0.2)
124
+ table_print (1.5.6)
125
+ text (1.3.1)
126
+ versionomy (0.5.0)
127
+ blockenspiel (~> 0.5)
128
+
129
+ PLATFORMS
130
+ ruby
131
+
132
+ DEPENDENCIES
133
+ bundler (~> 1.15)
134
+ onceover-lookup!
135
+ rake (~> 10.0)
136
+ rspec (~> 3.0)
137
+
138
+ BUNDLED WITH
139
+ 1.16.6
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 {yyyy} {name of copyright owner}
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,197 @@
1
+ # Onceover-Lookup
2
+
3
+ Lookup (hiera) support for
4
+ [Onceover](https://github.com/dylanratcliffe/onceover) - _The gateway drug to
5
+ automated infrastructure testing with Puppet_.
6
+
7
+ Debugging failed or unexpected lookups usually requires access to the Puppet
8
+ Master. This plugin aims to enable onceover users to perform _basic_ lookups
9
+ from the comfort of their workstation.
10
+
11
+ ## How it works
12
+ The plugin configures and wraps the `puppet lookup` command to work with a onceover enabled control
13
+ repository.
14
+
15
+ Users may then use the `--passthru` argument to pass arguments through to the
16
+ raw `puppet lookup` command and the plugin also provides a means to re-write
17
+ factsets to work with the the `puppet lookup` command.
18
+
19
+ ## Installation
20
+ Add `onceover-lookup` to your `Gemfile` and run `bundle install`:
21
+
22
+ **Gemfile**
23
+ ```ruby
24
+ gem 'onceover-lookup'
25
+ ```
26
+
27
+ ## Configuration
28
+ Onceover-lookup requires a valid puppet configuration file at
29
+ `.puppet.conf.onceover` which must exist before you can perform lookups.
30
+
31
+ To create this file initially or to reset to defaults:
32
+
33
+ ```shell
34
+ bundle exec onceover run lookup setup
35
+ ```
36
+
37
+ Once the file is created, you can edit/maintain it yourself.
38
+
39
+ This command also creates a skeleton directory structure for a mock puppet CA at
40
+ `spec/ssl` and includes instructions on how to create one, should you wish to.
41
+
42
+ ### /spec/hiera.yaml
43
+ If your project contains `spec/hiera.yaml` then we will automatically configure
44
+ onceover-lookup to use it via `.puppet.conf.onceover`
45
+
46
+ Using this file lets you have a specific hierarchy for testing or lets you
47
+ place a _test_ hierarchy above the regular one.
48
+
49
+ **Example**
50
+
51
+ ```yaml
52
+ # /hiera.yaml
53
+ #
54
+ # Configure hiera to mirror real customer data, inserting mock data for testing
55
+ # at the top level of the hierarchy
56
+ ---
57
+ version: 5
58
+
59
+ hierarchy:
60
+ - name: 'mock hiera data for testing'
61
+ data_hash: yaml_data
62
+ datadir: "mockdata"
63
+ paths:
64
+ - "os/%{facts.safe_os.family}_%{facts.safe_os.release.major}.yaml"
65
+
66
+ - name: "live customer data"
67
+ data_hash: yaml_data
68
+ datadir: "../data"
69
+ paths:
70
+ - "node/%{trusted.certname}.yaml"
71
+ - "customer_env/%{trusted.extensions.pp_environment}.yaml"
72
+ - "os/%{facts.safe_os.family}_%{facts.safe_os.release.major}.yaml"
73
+ - 'common.yaml'
74
+ ```
75
+
76
+ * In this example we have used the
77
+ [safe_roles](https://forge.puppet.com/geoffwilliams/safe_roles/readme) puppet
78
+ module to normalise OS names and versions
79
+ * You can use a custom factset to mock these as required
80
+
81
+ ### /hiera.yaml
82
+ If you have a `hiera.yaml` at the top of your control repository and do not have
83
+ a `spec/hiera.yaml` file, we will use this to configure a test hierarchy.
84
+
85
+ You must create this file yourself if missing.
86
+
87
+ ### Factsets
88
+ Onceover can be configured to use
89
+ [factsets](https://github.com/dylanratcliffe/onceover#factsets) and
90
+ `puppet lookup` can use the `--facts` argument to specify a list of facts to use
91
+ during the lookup, overriding those obtained from PuppetDB which we do not use.
92
+
93
+ The format of these two files is incompatible:
94
+ * Factsets are obtained from the `puppet facts` command, fact output is stored
95
+ in the `values` key
96
+ * Fact files for `puppet lookup` are created manually and are simple key-value
97
+ pairs
98
+
99
+ Attempting to use Onceover factsets with `puppet lookup` will result in an error
100
+ from Puppet:
101
+
102
+ ```shell
103
+ Error: Could not run: Cannot reassign variable '$name'
104
+ ```
105
+
106
+ To workaround this, use the `--factset` argument to onceover-lookup (not inside
107
+ `--passthru`) and we will rewrite the factset to a format that `puppet lookup`
108
+ can use.
109
+
110
+ ### Limitation
111
+ It is an error have _neither_ `/hiera.yaml` or `/spec/hiera.yaml`.
112
+
113
+ ## Usage
114
+
115
+ ### Help on onceover-lookup
116
+
117
+ ```shell
118
+ bundle exec onceover bundle exec onceover run lookup --help
119
+ ```
120
+
121
+ ### Help on puppet lookup
122
+ ```shell
123
+ bundle exec onceover run lookup --passthru="--help"
124
+ ```
125
+
126
+ ### Lookup a value and explain
127
+ ```shell
128
+ bundle exec onceover run lookup --passthru="profile::foo::bar --explain"
129
+ ```
130
+
131
+ ### Lookup a value using a named factset from onceover
132
+
133
+ ```shell
134
+ bundle exec onceover run lookup --passthru="profile::foo::bar --explain" --factset CentOS-7.0-64
135
+ ```
136
+
137
+ * Since factsets are files, names are case-sensitive
138
+
139
+ ### Lookup a value using your own custom factset
140
+
141
+ ```shell
142
+ bundle exec onceover run lookup --passthru="profile::foo::bar --explain" --factset spec/factsets/Windows_Server-2012r2-64-choco.json
143
+ ```
144
+
145
+ * Since factsets are files, names are case-sensitive
146
+
147
+ ### Debug Puppet during a lookup/provide trace information
148
+
149
+ ```shell
150
+ bundle exec onceover run lookup --passthru="profile::foo::bar --explain --trace --evaltrace --debug"
151
+ ```
152
+
153
+ * Parameters in `--passthru` are sent straight through to the `puppet lookup`
154
+ command so you can use any supported option
155
+
156
+ ## FAQ/Gotchas
157
+
158
+ **Command Ordering**
159
+
160
+ To avoid the shell misinterpreting your `--passthru` argument, use the form:
161
+
162
+ ```shell
163
+ --passthru="xxx"
164
+ ```
165
+
166
+ **Confusing --facts and --factset**
167
+
168
+ You can run with `--passthru="blah blah --facts /path/to/facts/file.json"` and
169
+ `puppet lookup` itself will attempt to resolve facts from the named file (which
170
+ must not be a _factset_!)
171
+
172
+ Alternatively, specify `--factset` outside the `--passthru` argument and
173
+ onceover-lookup will rewrite the named factset for you and use it for the
174
+ lookup.
175
+
176
+ It is an error to use both `--facts` and `--factset`.
177
+
178
+ **I see strange access denied errors when I do lookups - what gives? Are you trying to hack my system?**
179
+
180
+ When the `puppet lookup` command is run, any facts in your `Puppetfile` and
181
+ claimed by the current operating will also run. Since many of these facts expect
182
+ to run as `root` this can cause permission denied errors.
183
+
184
+ If the output of these facts is required, it can be added to a custom factset
185
+ and used at runtime with the `--factset` argument. The errors can otherwise be
186
+ ignored.
187
+
188
+ Full source code is available and you are welcome and encouraged to read and
189
+ understand what it does.
190
+
191
+ ## Development
192
+
193
+ PRs welcome :)
194
+
195
+ ## Contributing
196
+
197
+ Bug reports and pull requests are welcome on GitHub at https://github.com/declarativesystems/onceover-lookup
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "onceover/lookup"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,50 @@
1
+ # Create a class to hold the new command definition. The class defined should
2
+ # match the file we are contained in.
3
+ require "onceover/lookup/lookup"
4
+ class Onceover
5
+ class CLI
6
+ class Lookup
7
+
8
+ def self.command
9
+ @cmd ||= Cri::Command.define do
10
+ name 'lookup'
11
+ usage 'lookup [--name NAME]'
12
+ summary "Hello, World! plugin for Onceover"
13
+ description <<-DESCRIPTION
14
+ Run the `puppet lookup` command to use onceover configuration
15
+ DESCRIPTION
16
+
17
+ option nil, :passthru, 'Arguments to passthrough to puppet lookup', argument: :required
18
+ option nil, :factset, 'Extract and use this factset with `puppet lookup`', argument: :optional
19
+
20
+ run do |opts, args, cmd|
21
+ Onceover::Lookup::Lookup.run(opts[:passthru], opts[:factset])
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class Setup
28
+
29
+ def self.command
30
+ @cmd ||= Cri::Command.define do
31
+ name 'setup'
32
+ usage 'setup'
33
+ summary "Setup the onceover to work with `puppet lookup`"
34
+ description <<-DESCRIPTION
35
+ Setup onceover-lookup by creating .puppet.conf.onceover
36
+ DESCRIPTION
37
+
38
+ run do |opts, args, cmd|
39
+ Onceover::Lookup::Lookup.setup
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Onceover::CLI::Run.command.add_command(Onceover::CLI::Lookup.command)
48
+ # sub-sub command
49
+ Onceover::CLI::Lookup.command.add_command(Onceover::CLI::Setup.command)
50
+
@@ -0,0 +1,98 @@
1
+ require "erb"
2
+ require "tempfile"
3
+ require "json"
4
+
5
+ class Onceover
6
+ module Lookup
7
+ module Lookup
8
+ PUPPET_CONF = ".puppet.conf.onceover"
9
+ LOOKUP_TMP_DIR = ".onceover/tmp"
10
+
11
+ # Figure out what hiera.yaml we should be using. If there isn't a custom
12
+ # one, then fallback to the per-environment one. We don't care if this
13
+ # exists or not because it really should...
14
+ def self.resolve_hiera_yaml
15
+ hiera_yaml = File.exist?("spec/hiera.yaml") ? "spec/hiera.yaml" : "hiera.yaml"
16
+ end
17
+
18
+ def self.setup
19
+ puppet_conf_template = File.join(File.dirname(File.expand_path(__FILE__)), "../../../res/puppet.conf.erb")
20
+ ssl_readme = File.join(File.dirname(File.expand_path(__FILE__)), "../../../res/ssl_readme.md")
21
+
22
+ template = File.read(puppet_conf_template)
23
+
24
+ # used by the template
25
+ hiera_yaml = resolve_hiera_yaml
26
+ lookup_tmp_dir = LOOKUP_TMP_DIR
27
+
28
+ content = ERB.new(template, nil, '-').result(binding)
29
+
30
+ # We can't use a ruby block here - file handle needs to be synced and
31
+ # closed before puppet runs or it will read and empty file and not tell
32
+ # us
33
+ f = File.open(PUPPET_CONF, "w")
34
+ f.puts content
35
+ f.close
36
+
37
+ logger.info "wrote #{PUPPET_CONF}"
38
+ logger.info "puppet will store state in #{lookup_tmp_dir}, we suggest you add this to .gitignore"
39
+
40
+ if ! Dir.exist? "spec/ssl"
41
+ Dir.mkdir "spec/ssl"
42
+ end
43
+
44
+ if ! File.exist? "spec/ssl/README.md"
45
+ FileUtils.cp(ssl_readme, "spec/ssl/README.md")
46
+ end
47
+ end
48
+
49
+ def self.run(passthru, factset)
50
+ if factset
51
+ if factset.include? "/"
52
+ # relative path - use this
53
+ input_factset = factset
54
+ else
55
+ # resolve factset from Onceover's built-in facts
56
+ # https://stackoverflow.com/a/10083594/3441106
57
+ spec = Gem::Specification.find_by_name("onceover")
58
+ gem_root = spec.gem_dir
59
+
60
+ input_factset = File.join(gem_root, "factsets", "#{factset}.json")
61
+ end
62
+
63
+ logger.info "Extracting factset #{factset}..."
64
+ begin
65
+ data_hash = JSON.parse(File.read(input_factset))
66
+
67
+ # must give file extension or puppet will:
68
+ # Error: Could not parse application options: undefined method `[]' for nil:NilClass
69
+ factset_tempfile = Tempfile.new(["facts", ".json"])
70
+ factset_tempfile.write(data_hash["values"].to_json)
71
+ factset_tempfile.close
72
+ rescue Errno::ENOENT => e
73
+ raise("File not found reading: #{input_factset}: #{e.message}")
74
+ end
75
+ else
76
+ input_factset = nil
77
+ end
78
+
79
+ cmd = "bundle exec puppet lookup --config #{PUPPET_CONF} #{passthru}"
80
+ if input_factset
81
+ if passthru =~ /--facts/
82
+ raise "You cannot specify both `--facts` and `--factsets`"
83
+ end
84
+ cmd += " --facts #{factset_tempfile.path}"
85
+ end
86
+
87
+ if ! Dir.exist? LOOKUP_TMP_DIR
88
+ logger.info "creating #{LOOKUP_TMP_DIR}"
89
+ FileUtils.mkdir_p LOOKUP_TMP_DIR
90
+ end
91
+
92
+ logger.info "running command: #{cmd}"
93
+ system(cmd)
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,5 @@
1
+ class Onceover
2
+ module Lookup
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "onceover/lookup/version"
2
+ require "onceover/lookup/cli"
3
+
4
+ class Onceover
5
+ module Lookup
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "onceover/lookup/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "onceover-lookup"
8
+ spec.version = Onceover::Lookup::VERSION
9
+ spec.authors = ["Declarative Systems"]
10
+ spec.email = ["sales@declarativesystems.com"]
11
+ spec.license = "Apache-2.0"
12
+
13
+ spec.summary = %q{lookup plugin for onceover}
14
+ spec.homepage = "https://github.com/declarativesystems/onceover-lookup"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+
27
+ spec.add_runtime_dependency 'onceover', '~> 3'
28
+ end
@@ -0,0 +1,13 @@
1
+ [main]
2
+ hiera_config = <%= hiera_yaml %>
3
+ codedir = .onceover/etc/puppetlabs/code
4
+ ssldir = spec/ssl
5
+ certname = fake.fake
6
+
7
+ # Not strictly required but use separate directories to avoid polluting the host
8
+ vardir = <%= lookup_tmp_dir %>
9
+ logdir = <%= lookup_tmp_dir %>
10
+ statedir = <%= lookup_tmp_dir %>
11
+ rundir = <%= lookup_tmp_dir %>
12
+ libdir = <%= lookup_tmp_dir %>
13
+ environment = "production"
data/res/ssl_readme.md ADDED
@@ -0,0 +1,38 @@
1
+ # spec/ssl
2
+ If you like, you can build an entire mock puppet CA in this directory and puppet
3
+ will use it as part of its run.
4
+
5
+ You can choose to commit the files to git so that you only have to generate them
6
+ once. If you do so, be sure to never use these files for anything other then
7
+ logical testing as uploading to git would of-course compromise the secrecy of
8
+ the key.
9
+
10
+ This can be useful for testing out trusted facts, etc.
11
+
12
+ Puppet CAs are now managed using the puppetserver package which may not be
13
+ installable in your development environment. In this case, you can use `openssl`
14
+ to create the CA and sign the certificates.
15
+
16
+ ## Creating puppet certificates using OpenSSL
17
+
18
+ * All commands should be run from `spec/ssl`
19
+ * Any trusted attributes need to be set at the correct OID manually while
20
+ preparing CSR
21
+
22
+ ### Creating a CA
23
+ ```shell
24
+ openssl req -new -x509 -keyout ca/ca_key.pem -out ca/ca_crt.pem -days 3650 -nodes
25
+ ```
26
+ * Create a CA with 10 year validity
27
+
28
+ ### Creating a node
29
+ ```shell
30
+ openssl genrsa -out private_keys/fake.fake.pem 1024
31
+ openssl req -new -key private_keys/fake.fake.pem -out fake.fake.csr
32
+
33
+ openssl x509 -days 3650 -req -in fake.fake.csr -CA ca/ca_crt.pem -CAkey ca/ca_key.pem -set_serial 1 -out certs/fake.fake.pem
34
+ rm fake.fake.csr
35
+ ```
36
+
37
+ * Creates a node `fake.fake`
38
+ * 10 year validity
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onceover-lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Declarative Systems
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: onceover
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ description:
70
+ email:
71
+ - sales@declarativesystems.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/onceover/lookup.rb
85
+ - lib/onceover/lookup/cli.rb
86
+ - lib/onceover/lookup/lookup.rb
87
+ - lib/onceover/lookup/version.rb
88
+ - onceover-lookup.gemspec
89
+ - res/puppet.conf.erb
90
+ - res/ssl_readme.md
91
+ homepage: https://github.com/declarativesystems/onceover-lookup
92
+ licenses:
93
+ - Apache-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.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: lookup plugin for onceover
115
+ test_files: []