poise 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.kitchen.travis.yml +9 -0
- data/.kitchen.yml +18 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +25 -0
- data/.yardopts +5 -0
- data/Berksfile +26 -0
- data/Berksfile.lock +10 -0
- data/CHANGELOG.md +58 -0
- data/Gemfile +32 -0
- data/LICENSE +202 -0
- data/README.md +198 -0
- data/Rakefile +17 -0
- data/lib/poise.rb +71 -0
- data/lib/poise/error.rb +24 -0
- data/lib/poise/helpers.rb +33 -0
- data/lib/poise/helpers/chefspec_matchers.rb +92 -0
- data/lib/poise/helpers/defined_in.rb +111 -0
- data/lib/poise/helpers/fused.rb +127 -0
- data/lib/poise/helpers/include_recipe.rb +62 -0
- data/lib/poise/helpers/inversion.rb +374 -0
- data/lib/poise/helpers/inversion/options_provider.rb +41 -0
- data/lib/poise/helpers/inversion/options_resource.rb +101 -0
- data/lib/poise/helpers/lazy_default.rb +62 -0
- data/lib/poise/helpers/lwrp_polyfill.rb +96 -0
- data/lib/poise/helpers/notifying_block.rb +78 -0
- data/lib/poise/helpers/option_collector.rb +117 -0
- data/lib/poise/helpers/resource_name.rb +99 -0
- data/lib/poise/helpers/subcontext_block.rb +58 -0
- data/lib/poise/helpers/subresources.rb +29 -0
- data/lib/poise/helpers/subresources/child.rb +217 -0
- data/lib/poise/helpers/subresources/container.rb +165 -0
- data/lib/poise/helpers/subresources/default_containers.rb +73 -0
- data/lib/poise/helpers/template_content.rb +165 -0
- data/lib/poise/provider.rb +55 -0
- data/lib/poise/resource.rb +75 -0
- data/lib/poise/subcontext.rb +27 -0
- data/lib/poise/subcontext/resource_collection.rb +56 -0
- data/lib/poise/subcontext/runner.rb +50 -0
- data/lib/poise/utils.rb +60 -0
- data/lib/poise/utils/resource_provider_mixin.rb +53 -0
- data/lib/poise/version.rb +20 -0
- data/poise.gemspec +38 -0
- data/test/cookbooks/poise_test/attributes/default.rb +17 -0
- data/test/cookbooks/poise_test/libraries/app.rb +43 -0
- data/test/cookbooks/poise_test/libraries/app_config.rb +46 -0
- data/test/cookbooks/poise_test/libraries/inversion.rb +67 -0
- data/test/cookbooks/poise_test/metadata.rb +18 -0
- data/test/cookbooks/poise_test/recipes/default.rb +25 -0
- data/test/cookbooks/poise_test/recipes/inversion.rb +42 -0
- data/test/gemfiles/chef-12.0.gemfile +18 -0
- data/test/gemfiles/chef-12.1.gemfile +18 -0
- data/test/gemfiles/chef-12.2.gemfile +18 -0
- data/test/gemfiles/chef-12.gemfile +18 -0
- data/test/gemfiles/master.gemfile +20 -0
- data/test/integration/default/serverspec/default_spec.rb +35 -0
- data/test/integration/default/serverspec/inversion_spec.rb +43 -0
- data/test/spec/helpers/chefspec_matchers_spec.rb +45 -0
- data/test/spec/helpers/defined_in_spec.rb +62 -0
- data/test/spec/helpers/fused_spec.rb +92 -0
- data/test/spec/helpers/include_recipe_spec.rb +34 -0
- data/test/spec/helpers/inversion/options_resource_spec.rb +212 -0
- data/test/spec/helpers/inversion_spec.rb +273 -0
- data/test/spec/helpers/lazy_default_spec.rb +74 -0
- data/test/spec/helpers/lwrp_polyfill_spec.rb +128 -0
- data/test/spec/helpers/notifying_block_spec.rb +87 -0
- data/test/spec/helpers/option_collector_spec.rb +82 -0
- data/test/spec/helpers/resource_name_spec.rb +39 -0
- data/test/spec/helpers/subcontext_block_spec.rb +94 -0
- data/test/spec/helpers/subresources/child_spec.rb +339 -0
- data/test/spec/helpers/subresources/container_spec.rb +175 -0
- data/test/spec/helpers/template_context_spec.rb +147 -0
- data/test/spec/poise_spec.rb +185 -0
- data/test/spec/provider_spec.rb +28 -0
- data/test/spec/resource_spec.rb +85 -0
- data/test/spec/spec_helper.rb +18 -0
- data/test/spec/utils/resource_provider_mixin_spec.rb +52 -0
- data/test/spec/utils_spec.rb +110 -0
- metadata +190 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ace7c3aba6dbd072ffe99718c8599290df36ff80
|
4
|
+
data.tar.gz: 4822dff3762b4c319010e93102defab184a7dd2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71d3c8d0288dcad6916084eccbd21e8a25f5caae239269aecf838930ba96df15b069d08b97475930608d415eec6f38ba8991c18812c364d805d8be793ea04691
|
7
|
+
data.tar.gz: 0455db8c92eb97d8760dce620865ae74497fb3ba645b12aeb9890238d8ec832cdf7d836508dbfe814c0b2da68ff5c4f9eac478a692c345891713ac1dd71d048d
|
data/.gitignore
ADDED
data/.kitchen.travis.yml
ADDED
data/.kitchen.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
#<% require 'poise_boiler' %>
|
3
|
+
<%= PoiseBoiler.kitchen %>
|
4
|
+
|
5
|
+
chef_versions:
|
6
|
+
- '12.0'
|
7
|
+
- '12.1'
|
8
|
+
- '12.2'
|
9
|
+
- '12'
|
10
|
+
|
11
|
+
platforms:
|
12
|
+
- name: ubuntu-12.04
|
13
|
+
|
14
|
+
suites:
|
15
|
+
- name: default
|
16
|
+
run_list:
|
17
|
+
- recipe[poise_test]
|
18
|
+
- recipe[poise_test::inversion]
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
sudo: false
|
2
|
+
cache: bundler
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- '2.2'
|
6
|
+
addons:
|
7
|
+
apt:
|
8
|
+
packages:
|
9
|
+
- libgecode-dev
|
10
|
+
env:
|
11
|
+
global:
|
12
|
+
- USE_SYSTEM_GECODE=true
|
13
|
+
- KITCHEN_LOCAL_YAML=.kitchen.travis.yml
|
14
|
+
- secure: ax5czUwK8PVHXu/B3qbRZ8AACqXW4scIElQbn4sBuLp+VyTeutGax1uO6yTi7yv3xJUbEL3Z6gdZD/sOZpSKm8SL0YhkijoSs68HJCsau8cl7fvPJ0+JIlKqWazKEA1PaCmJHQv5J9TEyPyeSxZaIyacqOwOcUTyOkRDGyC+im8=
|
15
|
+
- secure: jEiZqcy6E5WC1nBmfJBSLPpYOUBFdpoo7DsLrvIpKVRpOw7slb+VgIru5AzbONvVD/8CYstgqiVVoGaCP/ywWWqakOQ2thp0BqWN/OVlsuPiemAdLRMMsmekkaFUdAa5l8QUUI0YiTSpSLUXQFWZrXbiARCALGAvDBbsqF1JhgA=
|
16
|
+
- secure: e3TH/N8tcx54wShV7s96OXDXuDbo9YnekLK3L3WrYrCK12gHVcW7xlMxPctGy14h6VaP1PBXJfUjd7cdzmHgudTo8HlR4Ui0kpjp85XrohPsLmVaFDxjAstLFm4VKMpsoKUZoPZY5J8bO9b606p872M5yO4rwKy3bVK/CP6mTBY=
|
17
|
+
bundler_args: "--binstubs=$PWD/bin --jobs 3 --retry 3"
|
18
|
+
script:
|
19
|
+
- "./bin/rake travis"
|
20
|
+
gemfile:
|
21
|
+
- test/gemfiles/chef-12.gemfile
|
22
|
+
- test/gemfiles/chef-12.0.gemfile
|
23
|
+
- test/gemfiles/chef-12.1.gemfile
|
24
|
+
- test/gemfiles/chef-12.2.gemfile
|
25
|
+
- test/gemfiles/master.gemfile
|
data/.yardopts
ADDED
data/Berksfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Noah Kantrowitz <noah@coderanger.net>
|
3
|
+
#
|
4
|
+
# Copyright 2013, Balanced, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
source 'https://supermarket.chef.io/'
|
20
|
+
extension 'halite'
|
21
|
+
|
22
|
+
cookbook 'poise', gem: 'poise'
|
23
|
+
|
24
|
+
group :test do
|
25
|
+
cookbook 'poise_test', path: 'test/cookbooks/poise_test'
|
26
|
+
end
|
data/Berksfile.lock
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## v2.0.0
|
4
|
+
|
5
|
+
Major overhaul! Poise is now a Halite gem/cookbook. New helpers:
|
6
|
+
|
7
|
+
* ChefspecMatchers – Automatically create Chefspec matchers for Poise resources.
|
8
|
+
* DefinedIn – Track which file (and cookbook) a resource or provider is defined in.
|
9
|
+
* Fused – Experimental support for defining provider actions in the resource class.
|
10
|
+
* Inversion – Support for end-user dependency inversion with providers.
|
11
|
+
|
12
|
+
All helpers are compatible with Chef >= 12.0. Chef 11 is now deprecated, if you
|
13
|
+
need to support Chef 11 please continue to use Poise 1.
|
14
|
+
|
15
|
+
## v1.0.12
|
16
|
+
|
17
|
+
* Correctly propagate errors from inside notifying_block.
|
18
|
+
|
19
|
+
## v1.0.10
|
20
|
+
|
21
|
+
* Fixes an issue with the LWRPPolyfill helper and false values.
|
22
|
+
|
23
|
+
|
24
|
+
## v1.0.8
|
25
|
+
|
26
|
+
* Delayed notifications from nested converges will still only run at the end of
|
27
|
+
the main converge.
|
28
|
+
|
29
|
+
## v1.0.6
|
30
|
+
|
31
|
+
* The include_recipe helper now works correctly when used at compile time.
|
32
|
+
|
33
|
+
## v1.0.4
|
34
|
+
|
35
|
+
* Redeclaring a template attribute with the same name as a parent class will
|
36
|
+
inherit its options.
|
37
|
+
|
38
|
+
## v1.0.2
|
39
|
+
|
40
|
+
* New template attribute pattern.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
attribute(:config, template: true)
|
44
|
+
|
45
|
+
...
|
46
|
+
|
47
|
+
resource 'name' do
|
48
|
+
config_source 'template.erb'
|
49
|
+
end
|
50
|
+
|
51
|
+
...
|
52
|
+
|
53
|
+
new_resource.config_content
|
54
|
+
```
|
55
|
+
|
56
|
+
## v1.0.0
|
57
|
+
|
58
|
+
* Initial release!
|
data/Gemfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013-2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
source 'https://rubygems.org/'
|
18
|
+
|
19
|
+
gemspec path: File.expand_path('..', __FILE__)
|
20
|
+
|
21
|
+
def dev_gem(name, path: File.join('..', name), github: "poise/#{name}")
|
22
|
+
github = "#{github}/#{name}" unless github.include?('/')
|
23
|
+
path = File.expand_path(File.join('..', path), __FILE__)
|
24
|
+
if File.exist?(path)
|
25
|
+
gem name, path: path
|
26
|
+
else
|
27
|
+
gem name, github: github
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
dev_gem 'halite'
|
32
|
+
dev_gem 'poise-boiler'
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
# Poise
|
2
|
+
|
3
|
+
[![Build Status](https://img.shields.io/travis/poise/poise.svg)](https://travis-ci.org/poise/poise)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/poise.svg)](https://rubygems.org/gems/poise)
|
5
|
+
[![Cookbook Version](https://img.shields.io/cookbook/v/poise.svg)](https://supermarket.chef.io/cookbooks/poise)
|
6
|
+
[![Coverage](https://img.shields.io/codecov/c/github/poise/poise.svg)](https://codecov.io/github/poise/poise)
|
7
|
+
[![Gemnasium](https://img.shields.io/gemnasium/poise/poise.svg)](https://gemnasium.com/poise/poise)
|
8
|
+
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
9
|
+
|
10
|
+
## What is Poise?
|
11
|
+
|
12
|
+
The poise cookbook is a set of libraries for writing reusable cookbooks. It
|
13
|
+
providers helpers for common patterns and a standard structure to make it easier to create flexible cookbooks.
|
14
|
+
|
15
|
+
## Writing your first resource
|
16
|
+
|
17
|
+
Rather than LWRPs, Poise promotes the idea of using normal, or "heavy weight"
|
18
|
+
resources, while including helpers to reduce much of boilerplate needed for this. Each resource goes in its own file under `libraries/` named to match
|
19
|
+
the resource, which is in turn based on the class name. This means that the file `libraries/my_app.rb` would contain `Chef::Resource::MyApp` which maps to the resource `my_app`.
|
20
|
+
|
21
|
+
An example of a simple shell to start from:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Chef
|
25
|
+
class Resource::MyApp < Resource
|
26
|
+
include Poise
|
27
|
+
|
28
|
+
actions(:enable)
|
29
|
+
|
30
|
+
attribute(:path, kind_of: String)
|
31
|
+
... # Other attribute definitions
|
32
|
+
end
|
33
|
+
|
34
|
+
class Provider::MyApp < Provider
|
35
|
+
include Poise
|
36
|
+
|
37
|
+
def action_enable
|
38
|
+
converge_by("enable resource #{new_resource.name}") do
|
39
|
+
notifying_block do
|
40
|
+
... # Normal Chef recipe code goes here
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Starting from the top, first we declare the resource class, which inherits from
|
49
|
+
`Chef::Resource`. This is similar to the `resources/` file in an LWRP, and a similar DSL can be used. In order to load the helpers into the class, we
|
50
|
+
include the `Poise` mixin. Then we use the familiar DSL, though with a few additions we'll cover later.
|
51
|
+
|
52
|
+
Then we declare the provider class, again similar to the `providers/` file in an LWRP. We include the `Poise` mixin again to get access to all the helpers. Rather than use the `action :enable do ... end` DSL from LWRPs, we just define the action method directly, and use the `converge_by` method to provide a description of what the action does. The implementation of action comes from a block of recipe code wrapped with `notifying_block` to capture changes in much the same way as `use_inline_resources`, see below for more information about all the features of `notifying_block`.
|
53
|
+
|
54
|
+
We can then use this resource like any other Chef resource:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
my_app 'one' do
|
58
|
+
path '/tmp'
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Helpers
|
63
|
+
|
64
|
+
While not exposed as a specific method, Poise will automatically set the
|
65
|
+
`resource_name` based on the class name.
|
66
|
+
|
67
|
+
### Notifying Block
|
68
|
+
|
69
|
+
As mentioned above, `notifying_block` is similar to `use_inline_resources` in LWRPs. Any Chef resource created inside the block will be converged in a sub-context and if any have updated it will trigger notifications on the current resource. Unlike `use_inline_resources`, resources inside the sub-context can still see resources outside of it, with lookups propagating up sub-contexts until a match is found. Also any delayed notifications are scheduled to run at the end of the main converge cycle, instead of the end of this inner converge.
|
70
|
+
|
71
|
+
This can be used to write action methods using the normal Chef recipe DSL, while still offering more flexibility through subclassing and other forms of code reuse.
|
72
|
+
|
73
|
+
### Include Recipe
|
74
|
+
|
75
|
+
In keeping with `notifying_block` to implement action methods using the Chef DSL, Poise adds an `include_recipe` helper to match the method of the same name in recipes. This will load and converge the requested recipe.
|
76
|
+
|
77
|
+
### Resource DSL
|
78
|
+
|
79
|
+
To make writing resource classes easier, Poise exposes a DSL similar to LWRPs for defining actions and attributes. Both `actions` and
|
80
|
+
`default_action` are just like in LWRPs, though `default_action` is rarely needed as the first action becomes the default. `attribute` is also available just like in LWRPs, but with some enhancements noted below.
|
81
|
+
|
82
|
+
One notable difference over the standard DSL method is that Poise attributes
|
83
|
+
can take a block argument.
|
84
|
+
|
85
|
+
#### Template Content
|
86
|
+
|
87
|
+
A common pattern with resources is to allow passing either a template filename or raw file content to be used in a configuration file. Poise exposes a new attribute flag to help with this behavior:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
attribute(:name, template: true)
|
91
|
+
```
|
92
|
+
|
93
|
+
This creates four methods on the class, `name_source`, `name_cookbook`,
|
94
|
+
`name_content`, and `name_options`. If the name is set to `''`, no prefix is applied to the function names. The content method can be set directly, but if not set and source is set, then it will render the template and return it as a string. Default values can also be set for any of these:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
attribute(:name, template: true, default_source: 'app.cfg.erb',
|
98
|
+
default_options: {host: 'localhost'})
|
99
|
+
```
|
100
|
+
|
101
|
+
As an example, you can replace this:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
if new_resource.source
|
105
|
+
template new_resource.path do
|
106
|
+
source new_resource.source
|
107
|
+
owner 'app'
|
108
|
+
group 'app'
|
109
|
+
variables new_resource.options
|
110
|
+
end
|
111
|
+
else
|
112
|
+
file new_resource.path do
|
113
|
+
content new_resource.content
|
114
|
+
owner 'app'
|
115
|
+
group 'app'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
with simply:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
file new_resource.path do
|
124
|
+
content new_resource.content
|
125
|
+
owner 'app'
|
126
|
+
group 'app'
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
As the content method returns the rendered template as a string, this can also
|
131
|
+
be useful within other templates to build from partials.
|
132
|
+
|
133
|
+
#### Lazy Initializers
|
134
|
+
|
135
|
+
One issue with Poise-style resources is that when the class definition is executed, Chef hasn't loaded very far so things like the node object are not
|
136
|
+
yet available. This means setting defaults based on node attributes does not work directly:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
attribute(:path, default: node['myapp']['path'])
|
140
|
+
...
|
141
|
+
NameError: undefined local variable or method 'node'
|
142
|
+
```
|
143
|
+
|
144
|
+
To work around this, Poise extends the idea of lazy initializers from Chef recipes to work with resource definitions as well:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
attribute(:path, default: lazy { node['myapp']['path'] })
|
148
|
+
```
|
149
|
+
|
150
|
+
These initializers are run in the context of the resource object, allowing
|
151
|
+
complex default logic to be moved to a method if desired:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
attribute(:path, default: lazy { my_default_path })
|
155
|
+
|
156
|
+
def my_default_path
|
157
|
+
...
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
#### Option Collector
|
162
|
+
|
163
|
+
Another common pattern with resources is to need a set of key/value pairs for
|
164
|
+
configuration data or options. This can done with a simple Hash, but an option collector attribute can offer a nicer syntax:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
attribute(:mydata, option_collector: true)
|
168
|
+
...
|
169
|
+
|
170
|
+
my_app 'name' do
|
171
|
+
mydata do
|
172
|
+
key1 'value1'
|
173
|
+
key2 'value2'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
This will be converted to `{key1: 'value1', key2: 'value2'}`. You can also pass a Hash to an option collector attribute just as you would with a normal attribute.
|
179
|
+
|
180
|
+
## Sponsors
|
181
|
+
|
182
|
+
The Poise test server infrastructure is generously sponsored by [Rackspace](https://rackspace.com/). Thanks Rackspace!
|
183
|
+
|
184
|
+
## License
|
185
|
+
|
186
|
+
Copyright 2013-2015, Noah Kantrowitz
|
187
|
+
|
188
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
189
|
+
you may not use this file except in compliance with the License.
|
190
|
+
You may obtain a copy of the License at
|
191
|
+
|
192
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
193
|
+
|
194
|
+
Unless required by applicable law or agreed to in writing, software
|
195
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
196
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
197
|
+
See the License for the specific language governing permissions and
|
198
|
+
limitations under the License.
|