poise-languages 1.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/.travis.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +32 -0
- data/LICENSE +202 -0
- data/README.md +27 -0
- data/Rakefile +17 -0
- data/lib/poise_languages.rb +25 -0
- data/lib/poise_languages/command.rb +25 -0
- data/lib/poise_languages/command/mixin.rb +231 -0
- data/lib/poise_languages/error.rb +21 -0
- data/lib/poise_languages/scl.rb +24 -0
- data/lib/poise_languages/scl/mixin.rb +110 -0
- data/lib/poise_languages/scl/resource.rb +124 -0
- data/lib/poise_languages/system.rb +24 -0
- data/lib/poise_languages/system/mixin.rb +165 -0
- data/lib/poise_languages/system/resource.rb +202 -0
- data/lib/poise_languages/utils.rb +49 -0
- data/lib/poise_languages/utils/which.rb +49 -0
- data/lib/poise_languages/version.rb +20 -0
- data/poise-languages.gemspec +40 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +22 -0
- data/test/spec/command/mixin_spec.rb +328 -0
- data/test/spec/scl/mixin_spec.rb +209 -0
- data/test/spec/scl/resource_spec.rb +51 -0
- data/test/spec/spec_helper.rb +18 -0
- data/test/spec/system/mixin_spec.rb +172 -0
- data/test/spec/system/resource_spec.rb +123 -0
- data/test/spec/utils/which_spec.rb +69 -0
- data/test/spec/utils_spec.rb +55 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad308d33e1c5f914ba25e08c39e5ec4b3a4152ca
|
4
|
+
data.tar.gz: d9292ac4e82099d6f42eac5acc72ab410950d730
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d177aea38775e213426383c6ddfd5146fa758def391611ed186d8b32a4a23ec403ff50483bb513aa34e76165b0c105aa8ecb7dcfe9ddb25c826ca37baa10f9d
|
7
|
+
data.tar.gz: cc9f000b3d5a1e2643ac3c2ea36fc069448d8f1a2ca1acdde14add845c388f8ea9a065186d8250d78bf5912f1a99c3b9e0dbe28410132c169235dff55706d72d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
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: hBSCgjWddgLHgzkhAx1ItgA0joNdevIwYgo6B34fJ9meGVuntP1zbHgEJ/H4wzCnxumU7cvGo0DOy93nctrpy/El9YeQ8pqfqwt0vywDBY7FhNoRV2oW59+TsvOyUvdmO6YThv17qjzWf19Ag15A5X5LgfbCrFdubXpueOSMfgSsHzny3cjF+GTuh8Ykvs8U8914JlhLNc7k7Z/cyXog7i3sO83vaHEWUBytEsnBIc1YXbbp3d1B+7YiF2EDrFxMbyN2BjmjrWpkpl31SgiyneCmw8Vj8Q4T3seK9qRrLeX5HvIdtSa0YLTvxO4kfrsNlgcJgLOmVqqMo2EStT2LRDR1DdeP9Nj8RinqkNQ7lOl4InNK7IM6Kl56dgGmnt7ZVs2kVt1xhzqWQEcRYbP14kUocCzt6A9p4gLy9trQTkBGqgCIcxFqiyfXPLJv3yAYQovGemkv6WfPAViPum7GL+98pBj0TFbiRLLcOljijbAQOi7R2VTdgaHJVBDQ5u8R9mtcecTyiBJwgYn0INY7IjpGoL1mepRNBfG9gW1+awyfvGLeYXe3dISuaPUDKZHaRSKIvJIo2Pi/OxYUPsBLiF4cL8fg6DiB9Ly/AHmI2fgct+lvkByq6ec4NlSWpSyBRtBYF7uCEkXSeSo2MPCEmPxoY/S4pO6Jz6LPtzWRdRk=
|
15
|
+
bundler_args: "--binstubs=$PWD/bin --jobs 3 --retry 3"
|
16
|
+
script:
|
17
|
+
- "./bin/rake travis"
|
18
|
+
gemfile:
|
19
|
+
- test/gemfiles/chef-12.gemfile
|
20
|
+
- test/gemfiles/master.gemfile
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 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: nil)
|
22
|
+
path = File.expand_path(File.join('..', path), __FILE__)
|
23
|
+
if File.exist?(path)
|
24
|
+
gem name, path: path
|
25
|
+
elsif github
|
26
|
+
gem name, github: github
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
dev_gem 'halite'
|
31
|
+
dev_gem 'poise'
|
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,27 @@
|
|
1
|
+
# Poise-Languages Cookbook
|
2
|
+
|
3
|
+
[![Build Status](https://img.shields.io/travis/poise/poise-languages.svg)](https://travis-ci.org/poise/poise-languages)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/poise-languages.svg)](https://rubygems.org/gems/poise-languages)
|
5
|
+
[![Cookbook Version](https://img.shields.io/cookbook/v/poise-languages.svg)](https://supermarket.chef.io/cookbooks/poise-languages)
|
6
|
+
[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-languages.svg)](https://codecov.io/github/poise/poise-languages)
|
7
|
+
[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-languages.svg)](https://gemnasium.com/poise/poise-languages)
|
8
|
+
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
9
|
+
|
10
|
+
Shared support code for Poise's language cookbooks like poise-ruby and
|
11
|
+
poise-python.
|
12
|
+
|
13
|
+
## License
|
14
|
+
|
15
|
+
Copyright 2015, Noah Kantrowitz
|
16
|
+
|
17
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
18
|
+
you may not use this file except in compliance with the License.
|
19
|
+
You may obtain a copy of the License at
|
20
|
+
|
21
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
22
|
+
|
23
|
+
Unless required by applicable law or agreed to in writing, software
|
24
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
25
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
26
|
+
See the License for the specific language governing permissions and
|
27
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 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
|
+
require 'poise_boiler/rakefile'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 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
|
+
|
18
|
+
module PoiseLanguages
|
19
|
+
autoload :Command, 'poise_languages/command'
|
20
|
+
autoload :Error, 'poise_languages/error'
|
21
|
+
autoload :Scl, 'poise_languages/scl'
|
22
|
+
autoload :System, 'poise_languages/system'
|
23
|
+
autoload :Utils, 'poise_languages/utils'
|
24
|
+
autoload :VERSION, 'poise_languages/version'
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 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
|
+
|
18
|
+
module PoiseLanguages
|
19
|
+
# A namespace for language-command-related stuff.
|
20
|
+
#
|
21
|
+
# @since 1.0.0
|
22
|
+
module Command
|
23
|
+
autoload :Mixin, 'poise_languages/command/mixin'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 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
|
+
require 'shellwords'
|
18
|
+
|
19
|
+
require 'chef/mixin/shell_out'
|
20
|
+
require 'chef/mixin/which'
|
21
|
+
require 'poise'
|
22
|
+
|
23
|
+
|
24
|
+
module PoiseLanguages
|
25
|
+
module Command
|
26
|
+
# A mixin for resources and providers that run language commands.
|
27
|
+
#
|
28
|
+
# @since 1.0.0
|
29
|
+
module Mixin
|
30
|
+
include Poise::Utils::ResourceProviderMixin
|
31
|
+
|
32
|
+
# A mixin for resources that run language commands. Also available as a
|
33
|
+
# parameterized mixin via `include PoiseLanguages::Command::Mixin::Resource(name)`.
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# class MyLangThing
|
37
|
+
# include PoiseLanguages::Command::Mixin::Resource(:mylang)
|
38
|
+
# # ...
|
39
|
+
# end
|
40
|
+
module Resource
|
41
|
+
include Poise::Resource
|
42
|
+
include Chef::Mixin::Which
|
43
|
+
poise_subresource(true)
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Implementation of the $name accessor.
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
# @param name [Symbol] Language name.
|
51
|
+
# @param runtime [Symbol] Language runtime resource name.
|
52
|
+
# @param val [String, Chef::Resource, Poise::NOT_PASSED, nil] Accessor value.
|
53
|
+
# @return [String]
|
54
|
+
def language_command_runtime(name, runtime, val=Poise::NOT_PASSED)
|
55
|
+
unless val == Poise::NOT_PASSED
|
56
|
+
path_arg = parent_arg = nil
|
57
|
+
# Figure out which property we are setting.
|
58
|
+
if val.is_a?(String)
|
59
|
+
# Check if it is a runtime resource.
|
60
|
+
begin
|
61
|
+
parent_arg = run_context.resource_collection.find("#{runtime}[#{val}]")
|
62
|
+
rescue Chef::Exceptions::ResourceNotFound
|
63
|
+
# Check if something looks like a path, defined as containing
|
64
|
+
# either / or \. While a single word could be a path, I think the
|
65
|
+
# UX win of better error messages should take priority.
|
66
|
+
might_be_path = val =~ %r{/|\\}
|
67
|
+
if might_be_path
|
68
|
+
Chef::Log.debug("[#{self}] #{runtime}[#{val}] not found, treating it as a path")
|
69
|
+
path_arg = val
|
70
|
+
else
|
71
|
+
# Surface the error up to the user.
|
72
|
+
raise
|
73
|
+
end
|
74
|
+
end
|
75
|
+
else
|
76
|
+
parent_arg = val
|
77
|
+
end
|
78
|
+
# Set both attributes.
|
79
|
+
send(:"parent_#{name}", parent_arg)
|
80
|
+
set_or_return(name, path_arg, kind_of: [String, NilClass])
|
81
|
+
else
|
82
|
+
# Getter behavior. Using the ivar directly is kind of gross but oh well.
|
83
|
+
instance_variable_get(:"@#{name}") || default_language_command_runtime(name)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Compute the path to the default runtime binary.
|
88
|
+
#
|
89
|
+
# @api private
|
90
|
+
# @param name [Symbol] Language name.
|
91
|
+
# @return [String]
|
92
|
+
def default_language_command_runtime(name)
|
93
|
+
parent = send(:"parent_#{name}")
|
94
|
+
if parent
|
95
|
+
parent.send(:"#{name}_binary")
|
96
|
+
else
|
97
|
+
which(name.to_s)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Inherit language parent from another resource.
|
102
|
+
#
|
103
|
+
# @api private
|
104
|
+
# @param name [Symbol] Language name.
|
105
|
+
# @param resource [Chef::Resource] Resource to inherit from.
|
106
|
+
# @return [void]
|
107
|
+
def language_command_runtime_from_parent(name, resource)
|
108
|
+
parent = resource.send(:"parent_#{name}")
|
109
|
+
if parent
|
110
|
+
send(:"parent_#{name}", parent)
|
111
|
+
else
|
112
|
+
path = resource.send(name)
|
113
|
+
if path
|
114
|
+
send(name, path)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
module ClassMethods
|
120
|
+
# Configure this module or class for a specific language.
|
121
|
+
#
|
122
|
+
# @param name [Symbol] Language name.
|
123
|
+
# @param runtime [Symbol] Language runtime resource name.
|
124
|
+
# @param timeout [Boolean] Enable the timeout attribute.
|
125
|
+
# @return [void]
|
126
|
+
def language_command_mixin(name, runtime: :"#{name}_runtime", timeout: true)
|
127
|
+
# Create the parent attribute.
|
128
|
+
parent_attribute(name, type: runtime, optional: true)
|
129
|
+
|
130
|
+
# Timeout attribute for the shell_out wrappers in the provider.
|
131
|
+
attribute(:timeout, kind_of: Integer, default: 900) if timeout
|
132
|
+
|
133
|
+
# Create the main accessor for the parent/path.
|
134
|
+
define_method(name) do |val=Poise::NOT_PASSED|
|
135
|
+
language_command_runtime(name, runtime, val)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Create the method to inherit settings from another resource.
|
139
|
+
private define_method(:"#{name}_from_parent") { |resource|
|
140
|
+
language_command_runtime_from_parent(name, resource)
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
# @api private
|
145
|
+
def included(klass)
|
146
|
+
super
|
147
|
+
klass.extend(ClassMethods)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
extend ClassMethods
|
152
|
+
Poise::Utils.parameterized_module(self) {|*args| language_command_mixin(*args) }
|
153
|
+
end # /module Resource
|
154
|
+
|
155
|
+
# A mixin for providers that run language commands.
|
156
|
+
module Provider
|
157
|
+
include Chef::Mixin::ShellOut
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
# Run a command using the configured language via `shell_out`.
|
162
|
+
#
|
163
|
+
# @api private
|
164
|
+
# @param name [Symbol] Language name.
|
165
|
+
# @param command_args [Array] Arguments to `shell_out`.
|
166
|
+
# @return [Mixlib::ShellOut]
|
167
|
+
def language_command_shell_out(name, *command_args)
|
168
|
+
options = if command_args.last.is_a?(Hash)
|
169
|
+
command_args.pop.dup
|
170
|
+
else
|
171
|
+
{}
|
172
|
+
end
|
173
|
+
# Inject our environment variables if needed.
|
174
|
+
parent = new_resource.send(:"parent_#{name}")
|
175
|
+
if parent
|
176
|
+
options[:environment] = parent.send(:"#{name}_environment").merge(options[:environment] || {})
|
177
|
+
end
|
178
|
+
# Inject other options.
|
179
|
+
options[:timeout] ||= new_resource.timeout
|
180
|
+
command = if command_args.length == 1 && command_args.first.is_a?(String)
|
181
|
+
# String mode, sigh.
|
182
|
+
"#{Shellwords.escape(new_resource.send(name))} #{command_args.first}"
|
183
|
+
else
|
184
|
+
# Array mode. Handle both ('one', 'two') and (['one', 'two']).
|
185
|
+
[new_resource.send(name)] + command_args.flatten
|
186
|
+
end
|
187
|
+
Chef::Log.debug("[#{new_resource}] Running #{name} command: #{command.is_a?(Array) ? Shellwords.shelljoin(command) : command}")
|
188
|
+
# Run the command
|
189
|
+
shell_out(command, options)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Run a command using the configured language via `shell_out!`.
|
193
|
+
#
|
194
|
+
# @api private
|
195
|
+
# @param name [Symbol] Language name.
|
196
|
+
# @param command_args [Array] Arguments to `shell_out!`.
|
197
|
+
# @return [Mixlib::ShellOut]
|
198
|
+
def language_command_shell_out!(name, *command_args)
|
199
|
+
send(:"#{name}_shell_out", *command_args).tap(&:error!)
|
200
|
+
end
|
201
|
+
|
202
|
+
module ClassMethods
|
203
|
+
# Configure this module or class for a specific language.
|
204
|
+
#
|
205
|
+
# @param name [Symbol] Language name.
|
206
|
+
# @return [void]
|
207
|
+
def language_command_mixin(name)
|
208
|
+
private define_method(:"#{name}_shell_out") { |*command_args|
|
209
|
+
language_command_shell_out(name, *command_args)
|
210
|
+
}
|
211
|
+
|
212
|
+
private define_method(:"#{name}_shell_out!") { |*command_args|
|
213
|
+
language_command_shell_out!(name, *command_args)
|
214
|
+
}
|
215
|
+
end
|
216
|
+
|
217
|
+
# @api private
|
218
|
+
def included(klass)
|
219
|
+
super
|
220
|
+
klass.extend(ClassMethods)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
extend ClassMethods
|
225
|
+
Poise::Utils.parameterized_module(self) {|*args| language_command_mixin(*args) }
|
226
|
+
end # /module Provider
|
227
|
+
|
228
|
+
Poise::Utils.parameterized_module(self) {|*args| language_command_mixin(*args) }
|
229
|
+
end # /module Mixin
|
230
|
+
end
|
231
|
+
end
|