Update upstream cookbooks
This commit is contained in:
parent
bfd2d52ea8
commit
bcfd44b923
8
Batali
8
Batali
@ -19,7 +19,6 @@ Batali.define do
|
||||
ref: 'master'
|
||||
cookbook 'application', '4.1.6'
|
||||
cookbook 'users'
|
||||
cookbook 'chef-solo-search'
|
||||
cookbook 'sudo'
|
||||
cookbook 'hostname'
|
||||
cookbook 'redis',
|
||||
@ -27,16 +26,15 @@ Batali.define do
|
||||
ref: 'v0.5.6'
|
||||
cookbook 'ufw'
|
||||
cookbook 'firewall'
|
||||
cookbook 'ssh_known_hosts'
|
||||
cookbook 'nginx'
|
||||
cookbook 'build-essential', '~> 2.2.4'
|
||||
cookbook 'build-essential'
|
||||
cookbook 'mysql'
|
||||
cookbook 'database'
|
||||
cookbook 'mysql2_chef_gem'
|
||||
cookbook 'omnibus_updater', '~> 1.0.4'
|
||||
cookbook 'omnibus_updater'
|
||||
cookbook 'timezone-ii'
|
||||
cookbook 'nodejs', '~> 3.0.0'
|
||||
cookbook 'ark', '~> 2.2.1'
|
||||
cookbook 'ark'
|
||||
cookbook 'logrotate'
|
||||
end
|
||||
|
||||
|
298
batali.manifest
298
batali.manifest
@ -91,13 +91,77 @@
|
||||
{
|
||||
"name": "build-essential",
|
||||
"dependencies": [
|
||||
|
||||
[
|
||||
"seven_zip",
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"mingw",
|
||||
">= 1.1"
|
||||
]
|
||||
],
|
||||
"version": "2.2.4",
|
||||
"version": "8.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/build-essential/versions/2.2.4/download",
|
||||
"version": "2.2.4"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/build-essential/versions/8.0.0/download",
|
||||
"version": "8.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "seven_zip",
|
||||
"dependencies": [
|
||||
[
|
||||
"windows",
|
||||
">= 1.2.2"
|
||||
]
|
||||
],
|
||||
"version": "1.0.4",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/seven_zip/versions/1.0.4/download",
|
||||
"version": "1.0.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "windows",
|
||||
"dependencies": [
|
||||
[
|
||||
"chef_handler",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "1.38.4",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/windows/versions/1.38.4/download",
|
||||
"version": "1.38.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "chef_handler",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "1.3.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/chef_handler/versions/1.3.0/download",
|
||||
"version": "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "mingw",
|
||||
"dependencies": [
|
||||
[
|
||||
"seven_zip",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/mingw/versions/2.0.0/download",
|
||||
"version": "2.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -170,11 +234,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "3.10.0",
|
||||
"version": "5.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/3.10.0/download",
|
||||
"version": "3.10.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/5.0.0/download",
|
||||
"version": "5.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -208,42 +272,27 @@
|
||||
"name": "yum-epel",
|
||||
"dependencies": [
|
||||
[
|
||||
"yum",
|
||||
"~> 3.2"
|
||||
"compat_resource",
|
||||
">= 12.16.3"
|
||||
]
|
||||
],
|
||||
"version": "0.6.5",
|
||||
"version": "2.1.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.6.5/download",
|
||||
"version": "0.6.5"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/2.1.1/download",
|
||||
"version": "2.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "windows",
|
||||
"dependencies": [
|
||||
[
|
||||
"chef_handler",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "1.38.4",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/windows/versions/1.38.4/download",
|
||||
"version": "1.38.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "chef_handler",
|
||||
"name": "compat_resource",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "1.3.0",
|
||||
"version": "12.16.3",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/chef_handler/versions/1.3.0/download",
|
||||
"version": "1.3.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/compat_resource/versions/12.16.3/download",
|
||||
"version": "12.16.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -254,11 +303,11 @@
|
||||
">= 1.34.6"
|
||||
]
|
||||
],
|
||||
"version": "4.1.6",
|
||||
"version": "5.0.8",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/iis/versions/4.1.6/download",
|
||||
"version": "4.1.6"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/iis/versions/5.0.8/download",
|
||||
"version": "5.0.8"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -366,14 +415,14 @@
|
||||
"dependencies": [
|
||||
[
|
||||
"rsyslog",
|
||||
"~> 2.0"
|
||||
">= 2.0"
|
||||
]
|
||||
],
|
||||
"version": "2.4.1",
|
||||
"version": "2.4.3",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/bluepill/versions/2.4.1/download",
|
||||
"version": "2.4.1"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/bluepill/versions/2.4.3/download",
|
||||
"version": "2.4.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -388,6 +437,36 @@
|
||||
"version": "2.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "build-essential",
|
||||
"dependencies": [
|
||||
[
|
||||
"7-zip",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "2.4.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/build-essential/versions/2.4.0/download",
|
||||
"version": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "7-zip",
|
||||
"dependencies": [
|
||||
[
|
||||
"windows",
|
||||
">= 1.2.2"
|
||||
]
|
||||
],
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/7-zip/versions/1.0.2/download",
|
||||
"version": "1.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohai",
|
||||
"dependencies": [
|
||||
@ -427,6 +506,21 @@
|
||||
"version": "0.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "yum-epel",
|
||||
"dependencies": [
|
||||
[
|
||||
"yum",
|
||||
">= 3.6.3"
|
||||
]
|
||||
],
|
||||
"version": "0.7.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.7.1/download",
|
||||
"version": "0.7.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "mysql2_chef_gem",
|
||||
"dependencies": [
|
||||
@ -558,11 +652,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "0.7.0",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/tar/versions/0.7.0/download",
|
||||
"version": "0.7.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/tar/versions/2.0.0/download",
|
||||
"version": "2.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -582,11 +676,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "3.7.0",
|
||||
"version": "5.0.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/postfix/versions/3.7.0/download",
|
||||
"version": "3.7.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/postfix/versions/5.0.1/download",
|
||||
"version": "5.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -656,18 +750,26 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "seven_zip",
|
||||
"name": "ark",
|
||||
"dependencies": [
|
||||
[
|
||||
"build-essential",
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"windows",
|
||||
">= 1.2.2"
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"seven_zip",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "1.0.4",
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/seven_zip/versions/1.0.4/download",
|
||||
"version": "1.0.4"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/2.2.1/download",
|
||||
"version": "2.2.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -702,23 +804,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "2.0.3",
|
||||
"version": "4.0.3",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/users/versions/2.0.3/download",
|
||||
"version": "2.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "chef-solo-search",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "0.5.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/chef-solo-search/versions/0.5.1/download",
|
||||
"version": "0.5.1"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/users/versions/4.0.3/download",
|
||||
"version": "4.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -726,11 +816,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "2.9.0",
|
||||
"version": "3.3.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/sudo/versions/2.9.0/download",
|
||||
"version": "2.9.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/sudo/versions/3.3.1/download",
|
||||
"version": "3.3.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -741,11 +831,11 @@
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/hostname/versions/0.3.0/download",
|
||||
"version": "0.3.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/hostname/versions/0.4.0/download",
|
||||
"version": "0.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -784,11 +874,11 @@
|
||||
">= 2.0"
|
||||
]
|
||||
],
|
||||
"version": "1.0.0",
|
||||
"version": "3.1.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ufw/versions/1.0.0/download",
|
||||
"version": "1.0.0"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ufw/versions/3.1.0/download",
|
||||
"version": "3.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -799,38 +889,11 @@
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "2.5.0",
|
||||
"version": "2.5.4",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/firewall/versions/2.5.0/download",
|
||||
"version": "2.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ssh_known_hosts",
|
||||
"dependencies": [
|
||||
[
|
||||
"partial_search",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ssh_known_hosts/versions/2.0.0/download",
|
||||
"version": "2.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "partial_search",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "1.0.9",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/partial_search/versions/1.0.9/download",
|
||||
"version": "1.0.9"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/firewall/versions/2.5.4/download",
|
||||
"version": "2.5.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -838,11 +901,11 @@
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"version": "1.0.6",
|
||||
"version": "3.0.2",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/omnibus_updater/versions/1.0.6/download",
|
||||
"version": "1.0.6"
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/omnibus_updater/versions/3.0.2/download",
|
||||
"version": "3.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -857,29 +920,6 @@
|
||||
"version": "0.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ark",
|
||||
"dependencies": [
|
||||
[
|
||||
"build-essential",
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"windows",
|
||||
">= 0.0.0"
|
||||
],
|
||||
[
|
||||
"seven_zip",
|
||||
">= 0.0.0"
|
||||
]
|
||||
],
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "Batali::Source::Site",
|
||||
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/2.2.1/download",
|
||||
"version": "2.2.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "logrotate",
|
||||
"dependencies": [
|
||||
|
13
cookbooks/7-zip/CHANGELOG.md
Normal file
13
cookbooks/7-zip/CHANGELOG.md
Normal file
@ -0,0 +1,13 @@
|
||||
7-zip Cookbook CHANGELOG
|
||||
========================
|
||||
This file is used to list changes made in each version of the 7-zip cookbook.
|
||||
|
||||
|
||||
v1.0.2
|
||||
------
|
||||
### Improvement
|
||||
- **[COOK-3476](https://tickets.opscode.com/browse/COOK-3476)** - Upgrade to 7-zip 9.22
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
- initial release
|
50
cookbooks/7-zip/README.md
Normal file
50
cookbooks/7-zip/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
7-zip Cookbook
|
||||
==============
|
||||
[7-Zip](http://www.7-zip.org/) is a file archiver with a high compression ratio. This cookbook installs the full 7-zip suite of tools (GUI and CLI).
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
### Platform
|
||||
- Windows XP
|
||||
- Windows Vista
|
||||
- Windows Server 2003 R2
|
||||
- Windows 7
|
||||
- Windows Server 2008 (R1, R2)
|
||||
- Windows 8
|
||||
- Windows Server 2012
|
||||
|
||||
### Cookbooks
|
||||
- windows
|
||||
|
||||
|
||||
Attributes
|
||||
----------
|
||||
- `node['7-zip']['home']` - location to install 7-zip files to. default is `%SYSTEMDRIVE%\7-zip`
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
### default
|
||||
Downloads and installs 7-zip to the location specified by `node['7-zip']['home']`. Also ensures `node['7-zip']['home']` is in the system path.
|
||||
|
||||
|
||||
License & Authors
|
||||
-----------------
|
||||
- Author:: Seth Chisamore (<schisamo@opscode.com>)
|
||||
|
||||
```text
|
||||
Copyright:: 2011, Opscode, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
31
cookbooks/7-zip/attributes/default.rb
Normal file
31
cookbooks/7-zip/attributes/default.rb
Normal file
@ -0,0 +1,31 @@
|
||||
#
|
||||
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
||||
# Cookbook Name:: 7-zip
|
||||
# Attribute:: default
|
||||
#
|
||||
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if kernel['machine'] =~ /x86_64/
|
||||
default['7-zip']['url'] = "http://downloads.sourceforge.net/sevenzip/7z922-x64.msi"
|
||||
default['7-zip']['checksum'] = "f09bf515289eea45185a4cc673e3bbc18ce608c55b4cf96e77833435c9cdf3dc"
|
||||
default['7-zip']['package_name'] = "7-Zip 9.22 (x64 edition)"
|
||||
else
|
||||
default['7-zip']['url'] = "http://downloads.sourceforge.net/sevenzip/7z922.msi"
|
||||
default['7-zip']['checksum'] = "86df264d22c3dd3ab80cb55a118da2d41bdd95c2db2cd09a6bbdf48f069e3d7a"
|
||||
default['7-zip']['package_name'] = "7-Zip 9.22"
|
||||
end
|
||||
|
||||
default['7-zip']['home'] = "#{ENV['SYSTEMDRIVE']}\\7-zip"
|
31
cookbooks/7-zip/metadata.json
Normal file
31
cookbooks/7-zip/metadata.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "7-zip",
|
||||
"version": "1.0.2",
|
||||
"description": "Installs/Configures the 7-zip file archiver",
|
||||
"long_description": "7-zip Cookbook\n==============\n[7-Zip](http://www.7-zip.org/) is a file archiver with a high compression ratio. This cookbook installs the full 7-zip suite of tools (GUI and CLI).\n\n\nRequirements\n------------\n### Platform\n- Windows XP\n- Windows Vista\n- Windows Server 2003 R2\n- Windows 7\n- Windows Server 2008 (R1, R2)\n- Windows 8\n- Windows Server 2012\n\n### Cookbooks\n- windows\n\n\nAttributes\n----------\n- `node['7-zip']['home']` - location to install 7-zip files to. default is `%SYSTEMDRIVE%\\7-zip`\n\n\nUsage\n-----\n### default\nDownloads and installs 7-zip to the location specified by `node['7-zip']['home']`. Also ensures `node['7-zip']['home']` is in the system path.\n\n\nLicense & Authors\n-----------------\n- Author:: Seth Chisamore (<schisamo@opscode.com>)\n\n```text\nCopyright:: 2011, Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n",
|
||||
"maintainer": "Opscode, Inc.",
|
||||
"maintainer_email": "cookbooks@opscode.com",
|
||||
"license": "Apache 2.0",
|
||||
"platforms": {
|
||||
"windows": ">= 0.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"windows": ">= 1.2.2"
|
||||
},
|
||||
"recommendations": {
|
||||
},
|
||||
"suggestions": {
|
||||
},
|
||||
"conflicting": {
|
||||
},
|
||||
"providing": {
|
||||
},
|
||||
"replacing": {
|
||||
},
|
||||
"attributes": {
|
||||
},
|
||||
"groupings": {
|
||||
},
|
||||
"recipes": {
|
||||
}
|
||||
}
|
10
cookbooks/7-zip/metadata.rb
Normal file
10
cookbooks/7-zip/metadata.rb
Normal file
@ -0,0 +1,10 @@
|
||||
name "7-zip"
|
||||
maintainer "Opscode, Inc."
|
||||
maintainer_email "cookbooks@opscode.com"
|
||||
license "Apache 2.0"
|
||||
description "Installs/Configures the 7-zip file archiver"
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version "1.0.2"
|
||||
supports "windows"
|
||||
|
||||
depends "windows", ">= 1.2.2"
|
@ -1,8 +1,9 @@
|
||||
#
|
||||
# Author:: Seth Vargo (<sethvargo@gmail.com>)
|
||||
# Attributes:: default
|
||||
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
||||
# Cookbook Name:: 7-zip
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2013, Seth Vargo
|
||||
# Copyright 2011, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -17,7 +18,14 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
default['ssh_known_hosts']['file'] = '/etc/ssh/ssh_known_hosts'
|
||||
default['ssh_known_hosts']['key_type'] = 'rsa,dsa'
|
||||
default['ssh_known_hosts']['cacher']['data_bag'] = 'server_data'
|
||||
default['ssh_known_hosts']['cacher']['data_bag_item'] = 'known_hosts'
|
||||
windows_package node['7-zip']['package_name'] do
|
||||
source node['7-zip']['url']
|
||||
checksum node['7-zip']['checksum']
|
||||
options "INSTALLDIR=\"#{node['7-zip']['home']}\""
|
||||
action :install
|
||||
end
|
||||
|
||||
# update path
|
||||
windows_path node['7-zip']['home'] do
|
||||
action :add
|
||||
end
|
1
cookbooks/bluepill/.foodcritic
Normal file
1
cookbooks/bluepill/.foodcritic
Normal file
@ -0,0 +1 @@
|
||||
~FC059
|
@ -1,15 +1,21 @@
|
||||
bluepill Cookbook CHANGELOG
|
||||
===========================
|
||||
# bluepill Cookbook CHANGELOG
|
||||
This file is used to list changes made in each version of the bluepill cookbook.
|
||||
|
||||
2.4.1 (11-10-2015)
|
||||
------
|
||||
## 2.4.3 (04-18-2016)
|
||||
- Added ChefSpec custom matchers and examples
|
||||
|
||||
## 2.4.2 (02-19-2016)
|
||||
- Loosened the dependecy on rsyslog so the latest cookbook can be used
|
||||
- Updated testing dependencies and configurations
|
||||
|
||||
WARNING: It was noted after the release of 2.4.2 that the loosened dependency on rsyslog increased the minimum required Chef release to 12.0 for this cookbook. Chef 11 users will need to use 2.4.1.
|
||||
|
||||
## 2.4.1 (11-10-2015)
|
||||
- Require rsyslog ~> 2.0.0 to preserve Chef 11 compatibility
|
||||
- Fix rsyslog restarting on RHEL
|
||||
- Use platform_family when setting platform specific node attributes and fix bad syntax. This should improve RHEL support
|
||||
|
||||
v2.4.0 (09-17-2015)
|
||||
------
|
||||
## v2.4.0 (09-17-2015)
|
||||
- Updated the LSB Required-Start and Required-Stop comments of the LSB init script template to be valid
|
||||
- Added name to the bluepill_test cookbook metadata for Chef 12
|
||||
- If a defaults file on RHEL or Debian based systems exist for the service source that within the init scripts. Example if /etc/default/bar exists on debian for the bar service then source that
|
||||
@ -27,72 +33,55 @@ v2.4.0 (09-17-2015)
|
||||
- Added a chefignore file and added additional files to the gitignore
|
||||
- Added source_url and issues_url metadata for Supermarket
|
||||
|
||||
v2.3.2
|
||||
------
|
||||
## v2.3.2
|
||||
- Never actually released
|
||||
|
||||
v2.3.1
|
||||
------
|
||||
## v2.3.1
|
||||
### New Feature
|
||||
- **[COOK-3705](https://tickets.chef.io/browse/COOK-3705)** - Add init.d script with LSB style
|
||||
|
||||
|
||||
v2.3.0
|
||||
------
|
||||
## v2.3.0
|
||||
### Improvement
|
||||
- **[COOK-3503](https://tickets.chef.io/browse/COOK-3503)** - Add why-run support
|
||||
|
||||
v2.2.2
|
||||
------
|
||||
## v2.2.2
|
||||
- [COOK-2507] - stringify language attributes
|
||||
|
||||
v2.2.0
|
||||
------
|
||||
## v2.2.0
|
||||
- [COOK-547] - Add `load` action to provider to reload services when template changes.
|
||||
|
||||
v2.1.0
|
||||
------
|
||||
## v2.1.0
|
||||
- [COOK-1295] - The bluepill cookbook does not create the default log file
|
||||
- [COOK-1840] - Enable bluepill to log to rsyslog
|
||||
|
||||
v2.0.0
|
||||
------
|
||||
## v2.0.0
|
||||
This version uses platform_family attribute (in the provider), making the cookbook incompatible with older versions of Chef/Ohai, hence the major version bump.
|
||||
|
||||
- [COOK-1644] - Bluepill cookbook fails on Redhat due to missing default or redhat template directory.
|
||||
- [COOK-1920] - init script should have a template file named after platform_family instead of using file specificity
|
||||
|
||||
v1.1.2
|
||||
------
|
||||
## v1.1.2
|
||||
- [COOK-1730] - Add ability to specify which version of bluepill to install
|
||||
|
||||
v1.1.0
|
||||
------
|
||||
## v1.1.0
|
||||
- [COOK-1592] - use mixlib-shellout instead of execute, add test-kitchen
|
||||
|
||||
v1.0.6
|
||||
------
|
||||
## v1.0.6
|
||||
- [COOK-1304] - support amazon linux
|
||||
- [COOK-1427] - resolve foodcritic warnings
|
||||
|
||||
v1.0.4
|
||||
------
|
||||
## v1.0.4
|
||||
- [COOK-1106] - fix chkconfig loader for CentOS 5
|
||||
- [COOK-1107] - use integer for GID instead of string
|
||||
|
||||
v1.0.2
|
||||
------
|
||||
## v1.0.2
|
||||
- [COOK-1043] - Bluepill cookbook fails on OS X because it tries to use root group
|
||||
|
||||
v1.0.0
|
||||
------
|
||||
## v1.0.0
|
||||
- [COOK-943] - add init script for freebsd
|
||||
|
||||
v0.3.0
|
||||
------
|
||||
## v0.3.0
|
||||
- [COOK-867] - enable bluepill service on RHEL family
|
||||
- [COOK-550] - add freebsd support
|
||||
|
||||
v0.2.2
|
||||
------
|
||||
## v0.2.2
|
||||
- Fixes COOK-524, COOK-632
|
||||
|
2
cookbooks/bluepill/CONTRIBUTING.md
Normal file
2
cookbooks/bluepill/CONTRIBUTING.md
Normal file
@ -0,0 +1,2 @@
|
||||
Please refer to
|
||||
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD
|
18
cookbooks/bluepill/MAINTAINERS.md
Normal file
18
cookbooks/bluepill/MAINTAINERS.md
Normal file
@ -0,0 +1,18 @@
|
||||
<!-- This is a generated file. Please do not edit directly -->
|
||||
|
||||
# Maintainers
|
||||
This file lists how this cookbook project is maintained. When making changes to the system, this
|
||||
file tells you who needs to review your patch - you need a simple majority of maintainers
|
||||
for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need
|
||||
to not receive a veto from a Lieutenant or the Project Lead.
|
||||
|
||||
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD)
|
||||
for details on the process and how to become a maintainer or the project lead.
|
||||
|
||||
# Project Maintainer
|
||||
* [Tim Smith](https://github.com/tas50)
|
||||
|
||||
# Maintainers
|
||||
* [Jennifer Davis](https://github.com/sigje)
|
||||
* [Tim Smith](https://github.com/tas50)
|
||||
* [Thom May](https://github.com/thommay)
|
@ -1,40 +1,30 @@
|
||||
bluepill Cookbook
|
||||
=================
|
||||
|
||||
[](https://travis-ci.org/chef-cookbooks/bluepill)
|
||||
[](https://supermarket.chef.io/cookbooks/bluepill)
|
||||
# bluepill Cookbook
|
||||
[](https://travis-ci.org/chef-cookbooks/bluepill) [](https://supermarket.chef.io/cookbooks/bluepill)
|
||||
|
||||
Installs bluepill Ruby Gem and configures it to manage services. Also includes a LWRP.
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
#### Platforms
|
||||
## Requirements
|
||||
### Platforms
|
||||
Bluepill is a pure Ruby service management tool/library, so this cookbook should work on any system. The attributes do set up paths based on FHS locations, see below.
|
||||
|
||||
#### Chef
|
||||
- Chef 11+
|
||||
### Chef
|
||||
- Chef 12+
|
||||
|
||||
#### Cookbooks
|
||||
### Cookbooks
|
||||
- none
|
||||
|
||||
|
||||
Attributes
|
||||
----------
|
||||
## Attributes
|
||||
Default locations for bluepill are in "FHS compliant" locations.
|
||||
- `node["bluepill"]["bin"]` - Path to bluepill program, default is 'bluepill' in the RubyGems binary directory.
|
||||
- `node["bluepill"]["logfile"]` - Location of the bluepill log file, default "/var/log/bluepill.log".
|
||||
- `node["bluepill"]["conf_dir"]` - Location of service config files (pills), default "/etc/bluepill".
|
||||
- `node["bluepill"]["pid_dir"]` - Location of pidfiles, default "/var/run/bluepill"
|
||||
- `node["bluepill"]["state_dir"]` - Location of state directory, default "/var/lib/bluepill"
|
||||
- `node["bluepill"]["init_dir"]` - Location of init script directory, default selected by platform.
|
||||
- `node["bluepill"]["version"]` - Version of bluepill to install, default is latest.
|
||||
- `node["bluepill"]["use_rsyslog"]` - Enable configuration and use of rsyslog for bluepill.
|
||||
|
||||
* `node["bluepill"]["bin"]` - Path to bluepill program, default is 'bluepill' in the RubyGems binary directory.
|
||||
* `node["bluepill"]["logfile"]` - Location of the bluepill log file, default "/var/log/bluepill.log".
|
||||
* `node["bluepill"]["conf_dir"]` - Location of service config files (pills), default "/etc/bluepill".
|
||||
* `node["bluepill"]["pid_dir"]` - Location of pidfiles, default "/var/run/bluepill"
|
||||
* `node["bluepill"]["state_dir"]` - Location of state directory, default "/var/lib/bluepill"
|
||||
* `node["bluepill"]["init_dir"]` - Location of init script directory, default selected by platform.
|
||||
* `node["bluepill"]["version"]` - Version of bluepill to install, default is latest.
|
||||
* `node["bluepill"]["use_rsyslog"]` - Enable configuration and use of rsyslog for bluepill.
|
||||
|
||||
|
||||
Resources/Providers
|
||||
-------------------
|
||||
# Custom Resources
|
||||
This cookbook contains an LWRP, `bluepill_service`. This can be used with the normal Chef service resource, by using the `provider` parameter, or by specifying the `bluepill_service` shortcut. These two resources are equivalent.
|
||||
|
||||
```ruby
|
||||
@ -52,9 +42,7 @@ The load action should probably always be specified, to ensure that if bluepill
|
||||
|
||||
The recipe using the service must contain a template resource for the pill and it must be named `my_app.pill.erb`, where `my_app` is the service name passed to the bluepill service resource.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
## Usage
|
||||
Be sure to include the bluepill recipe in the run list to ensure that the gem and bluepill-related directories are created. This will also make the cookbook available on the system and other cookbooks won't need to explicitly depend on it in the metadata.
|
||||
|
||||
If the default directory locations in the attributes/default.rb aren't what you want, change them by setting them either in the attributes file itself, or create attributes in a role applied to any systems that will use bluepill.
|
||||
@ -76,11 +64,35 @@ end
|
||||
|
||||
See bluepill's documentation for more information on creating pill templates.
|
||||
|
||||
## Testing
|
||||
This cookbook has the following [ChefSpec custom matchers](https://github.com/sethvargo/chefspec#packaging-custom-matchers) defined:
|
||||
|
||||
License & Authors
|
||||
-----------------
|
||||
- enable_bluepill_service
|
||||
- load_bluepill_service
|
||||
- reload_bluepill_service
|
||||
- start_bluepill_service
|
||||
- disable_bluepill_service
|
||||
- stop_bluepill_service
|
||||
- restart_bluepill_service
|
||||
|
||||
**Author:** Cookbook Engineering Team (<cookbooks@chef.io>)
|
||||
### ChefSpec Examples:
|
||||
|
||||
```
|
||||
it 'enables my_app bluepill service' do
|
||||
chef_run.converge('my_app::default', described_recipe)
|
||||
expect(chef_run).to enable_bluepill_service('my_app')
|
||||
end
|
||||
|
||||
it 'reloads my_app bluepill service when pill file changes' do
|
||||
chef_run.converge('my_app::default', described_recipe)
|
||||
expect(chef_run).to create_template('/etc/bluepill/my_app.pill')
|
||||
my_app_pill = chef_run.template('/etc/bluepill/my_app.pill')
|
||||
expect(my_app_pill).to notify('bluepill_service[my_app]').to(:reload).delayed
|
||||
end
|
||||
```
|
||||
|
||||
## License & Authors
|
||||
**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))
|
||||
|
||||
**Copyright:** 2010-2015, Chef Software, Inc.
|
||||
|
||||
|
33
cookbooks/bluepill/libraries/matchers.rb
Normal file
33
cookbooks/bluepill/libraries/matchers.rb
Normal file
@ -0,0 +1,33 @@
|
||||
if defined?(ChefSpec)
|
||||
|
||||
ChefSpec.define_matcher(:bluepill_service)
|
||||
|
||||
def enable_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :enable, service)
|
||||
end
|
||||
|
||||
def load_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :load, service)
|
||||
end
|
||||
|
||||
def reload_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :reload, service)
|
||||
end
|
||||
|
||||
def start_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :start, service)
|
||||
end
|
||||
|
||||
def disable_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :disable, service)
|
||||
end
|
||||
|
||||
def stop_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :stop, service)
|
||||
end
|
||||
|
||||
def restart_bluepill_service(service)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:bluepill_service, :restart, service)
|
||||
end
|
||||
|
||||
end
|
File diff suppressed because one or more lines are too long
2
cookbooks/build-essential/.foodcritic
Normal file
2
cookbooks/build-essential/.foodcritic
Normal file
@ -0,0 +1,2 @@
|
||||
~FC052
|
||||
~FC057
|
@ -1,70 +1,82 @@
|
||||
build-essential Cookbook CHANGELOG
|
||||
==================================
|
||||
# build-essential Cookbook CHANGELOG
|
||||
|
||||
This file is used to list changes made in each version of the build-essential cookbook.
|
||||
|
||||
v2.2.4 (2015-10-06)
|
||||
-------------------
|
||||
* Add patch package on Fedora systems
|
||||
* Add additional platforms to Kitchen CI
|
||||
* Use Chef standard Rubocop file and resolve several issues
|
||||
* Update contributing and testing docs
|
||||
* Update Gemfile with the latest testing and development deps
|
||||
* Add maintainers.md and maintainers.toml files
|
||||
* Add chefignore file to limit the files uploaded to the Chef server
|
||||
* Add source_url and issues_url metadata for Supermarket
|
||||
## v2.4.0 (2016-03-21)
|
||||
|
||||
v2.2.3 (2015-04-15)
|
||||
-------------------
|
||||
* Don’t install omnibus-build-essential on Solaris 10 - We decided it’s easier to use the old GCC that ships with Solaris 10.
|
||||
* Use ChefDK for all Travis testing.
|
||||
- Add gettext package to RHEL / FreeBSD to match other platforms
|
||||
- Fix OS X version detection logic to properly detect OS X 10.10 and 10.11
|
||||
|
||||
v2.2.2 (2015-03-27)
|
||||
-------------------
|
||||
* Update Solar 10’s omnibus-build-essential to 0.0.5
|
||||
## v2.3.1 (2016-02-18)
|
||||
|
||||
v2.2.1 (2015-03-23)
|
||||
-------------------
|
||||
* Install GNU Patch on Solaris 11
|
||||
- Restore Chef 11 compatibility and add Travis / Test Kitchen testing for Chef 11
|
||||
|
||||
v2.2.0 (2015-03-18)
|
||||
-------------------
|
||||
* [solaris] Differentiate between Solaris 10 and 11
|
||||
* [solaris] Add ucb compat package
|
||||
* [solaris] Solaris 10 build essential setup
|
||||
* Fix metadata to use a string instead of a bool (see #56, #57)
|
||||
## v2.3.0 (2016-02-17)
|
||||
|
||||
v2.1.3 (2014-11-18)
|
||||
-------------------
|
||||
* Update metadata for supported versions of OS X (10.7+) as noted from
|
||||
v2.0.0 previously (#38)
|
||||
* Clarify requirement to have apt package cache updated in README. (#41)
|
||||
* Fix Xcode CLI installation on OS X (#50)
|
||||
- Add mingw/msys based build tools for Windows
|
||||
|
||||
v2.1.2 (2014-10-14)
|
||||
-------------------
|
||||
* Mac OS X 10.10 Yosemite support
|
||||
## v2.2.4 (2015-10-06)
|
||||
|
||||
v2.1.0 (2014-10-14)
|
||||
-------------------
|
||||
* Use fully-qualified names when installing FreeBSD package
|
||||
- Add patch package on Fedora systems
|
||||
- Add additional platforms to Kitchen CI
|
||||
- Use Chef standard Rubocop file and resolve several issues
|
||||
- Update contributing and testing docs
|
||||
- Update Gemfile with the latest testing and development deps
|
||||
- Add maintainers.md and maintainers.toml files
|
||||
- Add chefignore file to limit the files uploaded to the Chef server
|
||||
- Add source_url and issues_url metadata for Supermarket
|
||||
|
||||
v2.0.6 (2014-08-11)
|
||||
-------------------
|
||||
* Use the resource form of `remote_file` to prevent context issues
|
||||
## v2.2.3 (2015-04-15)
|
||||
|
||||
v2.0.4 (2014-06-06)
|
||||
-------------------
|
||||
* [COOK-4661] added patch package to _rhel recipe
|
||||
- Don't install omnibus-build-essential on Solaris 10 - We decided it's easier to use the old GCC that ships with Solaris 10.
|
||||
- Use ChefDK for all Travis testing.
|
||||
|
||||
## v2.2.2 (2015-03-27)
|
||||
|
||||
- Update Solar 10's omnibus-build-essential to 0.0.5
|
||||
|
||||
## v2.2.1 (2015-03-23)
|
||||
|
||||
- Install GNU Patch on Solaris 11
|
||||
|
||||
## v2.2.0 (2015-03-18)
|
||||
|
||||
- [solaris] Differentiate between Solaris 10 and 11
|
||||
- [solaris] Add ucb compat package
|
||||
- [solaris] Solaris 10 build essential setup
|
||||
- Fix metadata to use a string instead of a bool (see #56, #57)
|
||||
|
||||
## v2.1.3 (2014-11-18)
|
||||
|
||||
- Update metadata for supported versions of OS X (10.7+) as noted from
|
||||
- v2.0.0 previously (#38)
|
||||
- Clarify requirement to have apt package cache updated in README. (#41)
|
||||
- Fix Xcode CLI installation on OS X (#50)
|
||||
|
||||
## v2.1.2 (2014-10-14)
|
||||
|
||||
- Mac OS X 10.10 Yosemite support
|
||||
|
||||
## v2.1.0 (2014-10-14)
|
||||
|
||||
- Use fully-qualified names when installing FreeBSD package
|
||||
|
||||
## v2.0.6 (2014-08-11)
|
||||
|
||||
- Use the resource form of `remote_file` to prevent context issues
|
||||
|
||||
## v2.0.4 (2014-06-06)
|
||||
|
||||
- [COOK-4661] added patch package to _rhel recipe
|
||||
|
||||
## v2.0.2 (2014-05-02)
|
||||
|
||||
v2.0.2 (2014-05-02)
|
||||
-------------------
|
||||
- Updated documentation about older Chef versions
|
||||
- Added new SVG badges to the README
|
||||
- Fix a bug where `potentially_at_compile_time` fails on non-resources
|
||||
|
||||
v2.0.0 (2014-03-13)
|
||||
-------------------
|
||||
## v2.0.0 (2014-03-13)
|
||||
|
||||
- Updated tested harnesses to use latest ecosystem tools
|
||||
- Added support for FreeBSD
|
||||
- Added support for installing XCode Command Line Tools on OSX (10.7, 10.8, 10.9)
|
||||
@ -80,57 +92,60 @@ v2.0.0 (2014-03-13)
|
||||
- `compiletime` -> `compile_time` in node attributes
|
||||
- Cookbook version 2.x no longer supports Chef 10.x
|
||||
|
||||
v1.4.4 (2014-02-27)
|
||||
-------------------
|
||||
## v1.4.4 (2014-02-27)
|
||||
|
||||
- [COOK-4245] Wrong package name used for developer tools on OS X 10.9
|
||||
|
||||
v1.4.2
|
||||
------
|
||||
## v1.4.2
|
||||
|
||||
### Bug
|
||||
|
||||
- **[COOK-3318](https://tickets.chef.io/browse/COOK-3318)** - Use Mixlib::ShellOut instead of Chef::ShellOut
|
||||
|
||||
### New Feature
|
||||
|
||||
- **[COOK-3093](https://tickets.chef.io/browse/COOK-3093)** - Add OmniOS support
|
||||
|
||||
### Improvement
|
||||
|
||||
- **[COOK-3024](https://tickets.chef.io/browse/COOK-3024)** - Use newer package on SmartOS
|
||||
|
||||
v1.4.0
|
||||
------
|
||||
## v1.4.0
|
||||
|
||||
This version splits up the default recipe into recipes included based on the node's platform_family.
|
||||
|
||||
- [COOK-2505] - backport omnibus builder improvements
|
||||
|
||||
v1.3.4
|
||||
------
|
||||
## v1.3.4
|
||||
|
||||
- [COOK-2272] - Complete `platform_family` conversion in build-essential
|
||||
|
||||
v1.3.2
|
||||
------
|
||||
## v1.3.2
|
||||
|
||||
- [COOK-2069] - build-essential will install osx-gcc-installer when XCode is present
|
||||
|
||||
v1.3.0
|
||||
------
|
||||
## v1.3.0
|
||||
|
||||
- [COOK-1895] - support smartos
|
||||
|
||||
v1.2.0
|
||||
------
|
||||
## v1.2.0
|
||||
|
||||
- Add test-kitchen support (source repo only)
|
||||
- [COOK-1677] - build-essential cookbook support for OpenSuse and SLES
|
||||
- [COOK-1718] - build-essential cookbook metadata should include scientific
|
||||
- [COOK-1768] - The apt-get update in build-essentials needs to be renamed
|
||||
|
||||
v1.1.2
|
||||
------
|
||||
## v1.1.2
|
||||
|
||||
- [COOK-1620] - support OS X 10.8
|
||||
|
||||
v1.1.0
|
||||
------
|
||||
## v1.1.0
|
||||
|
||||
- [COOK-1098] - support amazon linux
|
||||
- [COOK-1149] - support Mac OS X
|
||||
- [COOK-1296] - allow for compile-time installation of packages through an attribute (see README)
|
||||
|
||||
v1.0.2
|
||||
------
|
||||
## v1.0.2
|
||||
|
||||
- [COOK-1098] - Add Amazon Linux platform support
|
||||
- [COOK-1149] - Add OS X platform support
|
||||
|
2
cookbooks/build-essential/CONTRIBUTING.md
Normal file
2
cookbooks/build-essential/CONTRIBUTING.md
Normal file
@ -0,0 +1,2 @@
|
||||
Please refer to
|
||||
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD
|
18
cookbooks/build-essential/MAINTAINERS.md
Normal file
18
cookbooks/build-essential/MAINTAINERS.md
Normal file
@ -0,0 +1,18 @@
|
||||
<!-- This is a generated file. Please do not edit directly -->
|
||||
|
||||
# Maintainers
|
||||
This file lists how this cookbook project is maintained. When making changes to the system, this
|
||||
file tells you who needs to review your patch - you need a simple majority of maintainers
|
||||
for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need
|
||||
to not receive a veto from a Lieutenant or the Project Lead.
|
||||
|
||||
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD)
|
||||
for details on the process and how to become a maintainer or the project lead.
|
||||
|
||||
# Project Maintainer
|
||||
* [Jennifer Davis](https://github.com/sigje)
|
||||
|
||||
# Maintainers
|
||||
* [Jennifer Davis](https://github.com/sigje)
|
||||
* [Tim Smith](https://github.com/tas50)
|
||||
* [Thom May](https://github.com/thommay)
|
@ -1,98 +1,93 @@
|
||||
Description
|
||||
===========
|
||||
[][cookbook]
|
||||
[][travis]
|
||||
# build-essential Cookbook
|
||||
[][cookbook] [][travis]
|
||||
|
||||
[cookbook]: https://community.chef.io/cookbooks/build-essential
|
||||
[travis]: http://travis-ci.org/chef-cookbooks/build-essential
|
||||
Installs packages required for compiling C software from source. Use this cookbook if you wish to compile C programs, or install RubyGems with native extensions.
|
||||
|
||||
Installs packages required for compiling C software from source. Use this
|
||||
cookbook if you wish to compile C programs, or install RubyGems with native
|
||||
extensions.
|
||||
## Requirements
|
||||
### Platforms
|
||||
- Debian/Ubuntu
|
||||
- RHEL/CentOS/Scientific/Amazon/Oracle
|
||||
- openSUSE
|
||||
- SmartOS
|
||||
- Fedora
|
||||
- Mac OS X
|
||||
- FreeBSD
|
||||
|
||||
### Chef
|
||||
- Chef 11+
|
||||
|
||||
### Cookbooks
|
||||
- Suggests pkgutil for Solaris based platforms
|
||||
|
||||
Requirements
|
||||
------------
|
||||
Chef 11+ and Ohai 6.14+ are required. For the latest list of supported
|
||||
platforms, please see the `metadata.rb`.
|
||||
|
||||
**Note for Debian platform family:** On Debian platform-family systems, it is recommended that `apt-get update` be run, to ensure that the package cache is updated. It's not in the scope of this cookbook to do that, as it can [create a duplicate resource](https://tickets.chef.io/browse/CHEF-3694). We recommend using the [apt](https://supermarket.chef.io/cookbooks/apt) cookbook to do this.
|
||||
|
||||
**Note for OmniOS**: Currently, OmniOS's Ruby package is built with
|
||||
GCC 4.6.3, and the path is hardcoded, as the gcc binaries are not
|
||||
installed in the default $PATH. This means that in order to install
|
||||
RubyGems into the "system" Ruby, one must install `developer/gcc46`.
|
||||
[An issue](https://github.com/omniti-labs/omnios-build/issues/19) is
|
||||
open upstream w/ OmniOS to rebuild the Ruby package with GCC 4.7.2.
|
||||
**Note for OmniOS**: Currently, OmniOS's Ruby package is built with GCC 4.6.3, and the path is hardcoded, as the gcc binaries are not installed in the default $PATH. This means that in order to install RubyGems into the "system" Ruby, one must install `developer/gcc46`. [An issue](https://github.com/omniti-labs/omnios-build/issues/19) is open upstream w/ OmniOS to rebuild the Ruby package with GCC 4.7.2.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
| Attribute | Default | Description |
|
||||
|----------------|:-------:|-----------------------------------|
|
||||
| `compile_time` | `false` | Execute resources at compile time |
|
||||
## Attributes
|
||||
|
||||
Attribute | Default | Description
|
||||
----------------------------------------- | :--------------------------: | ---------------------------------
|
||||
`node['build-essential']['compile_time']` | `false` | Execute resources at compile time
|
||||
`node['build-essential']['msys']['path']` | `#{ENV['SYSTEMDRIVE']\\msys` | Destination for msys (Windows only)
|
||||
|
||||
Usage
|
||||
-----
|
||||
## Usage
|
||||
Include the build-essential recipe in your run list:
|
||||
|
||||
```sh
|
||||
knife node run_list add NODE "recipe[build-essential::default]"
|
||||
```
|
||||
|
||||
or add the build-essential recipe as a dependency and include it from inside
|
||||
another cookbook:
|
||||
or add the build-essential recipe as a dependency and include it from inside another cookbook:
|
||||
|
||||
```ruby
|
||||
include_recipe 'build-essential::default'
|
||||
```
|
||||
|
||||
### Gems with C extensions
|
||||
For RubyGems that include native C extensions you wish to use with Chef, you
|
||||
should do the following.
|
||||
For RubyGems that include native C extensions you wish to use with Chef, you should do the following.
|
||||
- Set the `compile_time` attribute to true in your wrapper cookbook or role:
|
||||
|
||||
1. Set the `compile_time` attribute to true in your wrapper cookbook or role:
|
||||
```ruby
|
||||
# Wrapper attribute
|
||||
default['build-essential']['compile_time'] = true
|
||||
```
|
||||
|
||||
```ruby
|
||||
# Wrapper attribute
|
||||
default['build-essential']['compile_time'] = true
|
||||
```
|
||||
```ruby
|
||||
# Role
|
||||
default_attributes(
|
||||
'build-essential' => {
|
||||
'compile_time' => true
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
```ruby
|
||||
# Role
|
||||
default_attributes(
|
||||
'build-essential' => {
|
||||
'compile_time' => true
|
||||
}
|
||||
)
|
||||
```
|
||||
- Ensure that the C libraries, which include files and other assorted "dev"
|
||||
|
||||
1. Ensure that the C libraries, which include files and other assorted "dev"
|
||||
type packages, are installed in the compile phase after the build-essential
|
||||
recipe is executed. For example:
|
||||
type packages, are installed in the compile phase after the build-essential
|
||||
|
||||
```ruby
|
||||
include_recipe 'build-essential::default'
|
||||
recipe is executed. For example:
|
||||
|
||||
package('mypackage-devel') { action :nothing }.run_action(:install)
|
||||
```
|
||||
```ruby
|
||||
include_recipe 'build-essential::default'
|
||||
|
||||
1. Use the `chef_gem` resource in your recipe to install the gem with the native
|
||||
extension:
|
||||
package('mypackage-devel') { action :nothing }.run_action(:install)
|
||||
```
|
||||
|
||||
```ruby
|
||||
chef_gem 'gem-with-native-extension'
|
||||
```
|
||||
- Use the `chef_gem` resource in your recipe to install the gem with the native
|
||||
|
||||
extension:
|
||||
|
||||
License & Authors
|
||||
-----------------
|
||||
- Author: Seth Vargo (<sethvargo@gmail.com>)
|
||||
- Author: Joshua Timberman (<joshua@chef.io>)
|
||||
- Author: Seth Chisamore (<schisamo@chef.io>)
|
||||
```ruby
|
||||
chef_gem 'gem-with-native-extension'
|
||||
```
|
||||
|
||||
```text
|
||||
Copyright 2009-2015, Chef Software, Inc. (<legal@chef.io>)
|
||||
## License & Authors
|
||||
**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))
|
||||
|
||||
**Copyright:** 2009-2015, Chef Software, Inc.
|
||||
|
||||
```
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
@ -106,3 +101,5 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
||||
|
||||
[cookbook]: https://supermarket.chef.io/cookbooks/build-essential
|
||||
[travis]: http://travis-ci.org/chef-cookbooks/build-essential
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Attributes:: default
|
||||
#
|
||||
# Copyright 2008-2012, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -18,3 +18,4 @@
|
||||
#
|
||||
|
||||
default['build-essential']['compile_time'] = false
|
||||
default['build-essential']['msys']['path'] = "#{ENV['SYSTEMDRIVE']}\\msys"
|
||||
|
15
cookbooks/build-essential/libraries/_msys_helper.rb
Normal file
15
cookbooks/build-essential/libraries/_msys_helper.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module BuildEssential
|
||||
module MsysHelper
|
||||
#
|
||||
# This function returns a struct representing an
|
||||
# msys package. It has two fields: url and checksum
|
||||
#
|
||||
# @return [OpenStruct]
|
||||
#
|
||||
def msys_p(url, checksum)
|
||||
OpenStruct.new(url: url, checksum: checksum)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Recipe.send(:include, BuildEssential::MsysHelper)
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Library:: timing
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc.
|
||||
# Copyright 2014-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Library:: xcode_command_line_tools
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc.
|
||||
# Copyright 2014-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -29,10 +29,12 @@ class Chef
|
||||
def initialize(name, run_context = nil)
|
||||
super
|
||||
|
||||
@provider = case node['platform_version'].to_f
|
||||
when 10.7, 10.8
|
||||
# => Break down SemVer
|
||||
major, minor, _patch = node['platform_version'].split('.').map { |v| String(v) }
|
||||
@provider = case [major, minor].join('.')
|
||||
when '10.7', '10.8'
|
||||
Provider::XcodeCommandLineToolsFromDmg
|
||||
when 10.9, 10.10
|
||||
when '10.9', '10.10', '10.11'
|
||||
Provider::XcodeCommandLineToolsFromSoftwareUpdate
|
||||
else
|
||||
Chef::Log.warn <<-EOH
|
||||
@ -112,7 +114,7 @@ class Chef
|
||||
when 10.8
|
||||
'http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_march_2014.dmg'
|
||||
else
|
||||
fail "Unknown DMG download URL for OSX #{node['platform_version']}"
|
||||
raise "Unknown DMG download URL for OSX #{node['platform_version']}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1 +1 @@
|
||||
{"name":"build-essential","version":"2.2.4","description":"Installs C compiler / build tools","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","freebsd":">= 0.0.0","mac_os_x":">= 10.7.0","mac_os_x_server":">= 10.7.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","smartos":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{"pkgutil":">= 0.0.0"},"conflicting":{},"providing":{},"replacing":{},"attributes":{"build-essential/compile_time":{"display_name":"Build Essential Compile Time Execution","description":"Execute resources at compile time.","default":"false","recipes":["build-essential::default"]}},"groupings":{},"recipes":{"build-essential":"Installs packages required for compiling C software from source."},"source_url":"https://github.com/chef-cookbooks/build-essential","issues_url":"https://github.com/chef-cookbooks/build-essential/issues"}
|
||||
{"name":"build-essential","version":"2.4.0","description":"Installs C compiler / build tools","long_description":"# build-essential Cookbook\n[][cookbook] [][travis]\n\nInstalls packages required for compiling C software from source. Use this cookbook if you wish to compile C programs, or install RubyGems with native extensions.\n\n## Requirements\n### Platforms\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Amazon/Oracle\n- openSUSE\n- SmartOS\n- Fedora\n- Mac OS X\n- FreeBSD\n\n### Chef\n- Chef 11+\n\n### Cookbooks\n- Suggests pkgutil for Solaris based platforms\n\n\n**Note for Debian platform family:** On Debian platform-family systems, it is recommended that `apt-get update` be run, to ensure that the package cache is updated. It's not in the scope of this cookbook to do that, as it can [create a duplicate resource](https://tickets.chef.io/browse/CHEF-3694). We recommend using the [apt](https://supermarket.chef.io/cookbooks/apt) cookbook to do this.\n\n**Note for OmniOS**: Currently, OmniOS's Ruby package is built with GCC 4.6.3, and the path is hardcoded, as the gcc binaries are not installed in the default $PATH. This means that in order to install RubyGems into the \"system\" Ruby, one must install `developer/gcc46`. [An issue](https://github.com/omniti-labs/omnios-build/issues/19) is open upstream w/ OmniOS to rebuild the Ruby package with GCC 4.7.2.\n\n## Attributes\n\nAttribute | Default | Description\n----------------------------------------- | :--------------------------: | ---------------------------------\n`node['build-essential']['compile_time']` | `false` | Execute resources at compile time\n`node['build-essential']['msys']['path']` | `#{ENV['SYSTEMDRIVE']\\\\msys` | Destination for msys (Windows only)\n\n## Usage\nInclude the build-essential recipe in your run list:\n\n```sh\nknife node run_list add NODE \"recipe[build-essential::default]\"\n```\n\nor add the build-essential recipe as a dependency and include it from inside another cookbook:\n\n```ruby\ninclude_recipe 'build-essential::default'\n```\n\n### Gems with C extensions\nFor RubyGems that include native C extensions you wish to use with Chef, you should do the following.\n- Set the `compile_time` attribute to true in your wrapper cookbook or role:\n\n ```ruby\n # Wrapper attribute\n default['build-essential']['compile_time'] = true\n ```\n\n ```ruby\n # Role\n default_attributes(\n 'build-essential' => {\n 'compile_time' => true\n }\n )\n ```\n\n- Ensure that the C libraries, which include files and other assorted \"dev\"\n\n type packages, are installed in the compile phase after the build-essential\n\n recipe is executed. For example:\n\n ```ruby\n include_recipe 'build-essential::default'\n\n package('mypackage-devel') { action :nothing }.run_action(:install)\n ```\n\n- Use the `chef_gem` resource in your recipe to install the gem with the native\n\n extension:\n\n ```ruby\n chef_gem 'gem-with-native-extension'\n ```\n\n## License & Authors\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2009-2015, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n[cookbook]: https://supermarket.chef.io/cookbooks/build-essential\n[travis]: http://travis-ci.org/chef-cookbooks/build-essential\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","freebsd":">= 0.0.0","mac_os_x":">= 10.7.0","mac_os_x_server":">= 10.7.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","smartos":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{"7-zip":">= 0.0.0"},"recommendations":{},"suggestions":{"pkgutil":">= 0.0.0"},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"build-essential":"Installs packages required for compiling C software from source."}}
|
102
cookbooks/build-essential/providers/msys_archive.rb
Normal file
102
cookbooks/build-essential/providers/msys_archive.rb
Normal file
@ -0,0 +1,102 @@
|
||||
#
|
||||
# Cookbook Name:: build-essential
|
||||
# Provider:: msys_archive
|
||||
#
|
||||
# Copyright 2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
use_inline_resources
|
||||
|
||||
action :unpack do
|
||||
directory msys_dir do
|
||||
action :create
|
||||
end
|
||||
|
||||
directory "dir-#{mingw_dir}" do
|
||||
action :create
|
||||
path mingw_dir
|
||||
only_if do
|
||||
new_resource.mingw
|
||||
end
|
||||
end
|
||||
|
||||
directory cache_dir do
|
||||
action :create
|
||||
end
|
||||
|
||||
# Unpacking involves downloading the tar.whatever.
|
||||
# Then we unpack the tar.whatever with 7z, which
|
||||
# leaves us with a tar, which can finally be
|
||||
# untarred with 7z.
|
||||
|
||||
remote_file cache_path do
|
||||
source new_resource.source
|
||||
checksum new_resource.checksum
|
||||
notifies :run, "execute[#{archive_name}]", :immediately
|
||||
end
|
||||
|
||||
execute archive_name do
|
||||
command extract_cmd(cache_path, cache_dir)
|
||||
action :nothing
|
||||
notifies :run, "execute[#{tar_name}]", :immediately
|
||||
end
|
||||
|
||||
execute tar_name do
|
||||
command extract_cmd(tar_path, unpack_root_dir)
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
# msys packages will be extracted into the root dir
|
||||
# mingw packages will get extracted into the root/mingw dir
|
||||
def unpack_root_dir
|
||||
if new_resource.mingw
|
||||
mingw_dir
|
||||
else
|
||||
msys_dir
|
||||
end
|
||||
end
|
||||
|
||||
def msys_dir
|
||||
new_resource.root_dir
|
||||
end
|
||||
|
||||
def mingw_dir
|
||||
::File.join(new_resource.root_dir, 'mingw')
|
||||
end
|
||||
|
||||
def archive_name
|
||||
::File.basename(new_resource.source)
|
||||
end
|
||||
|
||||
def cache_dir
|
||||
::File.join(unpack_root_dir, '.cache')
|
||||
end
|
||||
|
||||
def cache_path
|
||||
::File.join(cache_dir, archive_name)
|
||||
end
|
||||
|
||||
def tar_name
|
||||
::File.basename(archive_name, ::File.extname(archive_name))
|
||||
end
|
||||
|
||||
def tar_path
|
||||
::File.join(cache_dir, tar_name)
|
||||
end
|
||||
|
||||
def extract_cmd(source_file, dest_dir)
|
||||
"7z x #{source_file} -o#{dest_dir} -r -y"
|
||||
end
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: debian
|
||||
#
|
||||
# Copyright 2008-2013, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: fedora
|
||||
#
|
||||
# Copyright 2008-2015, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: freebsd
|
||||
#
|
||||
# Copyright 2014, Chef Software, Inc.
|
||||
# Copyright 2014-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -21,4 +21,5 @@ potentially_at_compile_time do
|
||||
package 'devel/gmake'
|
||||
package 'devel/autoconf'
|
||||
package 'devel/m4'
|
||||
package 'devel/gettext'
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: mac_os_x
|
||||
#
|
||||
# Copyright 2008-2013, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: omnios
|
||||
#
|
||||
# Copyright 2013, Chef Software, Inc.
|
||||
# Copyright 2013-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: rhel
|
||||
#
|
||||
# Copyright 2008-2013, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -27,6 +27,7 @@ potentially_at_compile_time do
|
||||
package 'make'
|
||||
package 'm4'
|
||||
package 'patch'
|
||||
package 'gettext-devel'
|
||||
|
||||
# Ensure GCC 4 is available on older pre-6 EL
|
||||
if node['platform_version'].to_i < 6
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: smartos
|
||||
#
|
||||
# Copyright 2008-2013, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: solaris2
|
||||
#
|
||||
# Copyright 2013, Chef Software, Inc.
|
||||
# Copyright 2013-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -44,5 +44,5 @@ when 5.11
|
||||
package 'ucb'
|
||||
end
|
||||
else
|
||||
fail "Sorry, we don't support Solaris version #{node['platform_version']} at this juncture."
|
||||
raise "Sorry, we don't support Solaris version #{node['platform_version']} at this juncture."
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: suse
|
||||
#
|
||||
# Copyright 2008-2013, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
112
cookbooks/build-essential/recipes/_windows.rb
Normal file
112
cookbooks/build-essential/recipes/_windows.rb
Normal file
@ -0,0 +1,112 @@
|
||||
#
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: _mingw
|
||||
#
|
||||
# Copyright 2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require 'ostruct'
|
||||
|
||||
include_recipe '7-zip::default'
|
||||
|
||||
[
|
||||
msys_p('http://downloads.sourceforge.net/mingw/msysCORE-1.0.17-1-msys-1.0.17-bin.tar.lzma',
|
||||
'2d707ae394f5797a0718a1ffd886d4be1a83ed1f68a4ee4a5b19efd3208b037f'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/msysCORE-1.0.17-1-msys-1.0.17-ext.tar.lzma',
|
||||
'2c68f68cb2caa27aa014461133cf578433e62c823cdac3350be62b9c3e6460a0'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/coreutils-5.97-3-msys-1.0.13-bin.tar.lzma',
|
||||
'f8c7990416ea16a74ac336dcfe0f596bc46b8724b2d58cf8a3509414220b2366'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/coreutils-5.97-3-msys-1.0.13-ext.tar.lzma',
|
||||
'3f525aa6c94ff79ffd656ddf0a56d3244f982ea4a0d274674d9875afc1e04579'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma',
|
||||
'196921e8c232259c8e6a6852b9ee8d9ab2d29a91419f0c8dc27ba6f034231683'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma',
|
||||
'29db8c969661c511fbe2a341ab25c993c5f9c555842a75d6ddbcfa70dec16910'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libtermcap-0.20050421_1-2-msys-1.0.13-dll-0.tar.lzma',
|
||||
'62b58fe0880f0972fcc84a819265989b02439c1c5185870227bd25f870f7adb6'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/make-3.81-3-msys-1.0.13-bin.tar.lzma',
|
||||
'847f0cbbf07135801c8e67bf692d29b1821e816ad828753c997fa869a9b89988'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/perl-5.8.8-1-msys-1.0.17-bin.tar.lzma',
|
||||
'987b939ce00172dd034105d2a908cee5704f67027de98f4dcc69a1006a327a99'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/zlib-1.2.3-2-msys-1.0.13-dll.tar.lzma',
|
||||
'4178940828b928b2d5a33042cc83fbb992b4bfb9ffeaef6dc3e555f2a6a8c0d1'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libgdbm-1.8.3-3-msys-1.0.13-dll-3.tar.lzma',
|
||||
'7412f874487652e70022ab8601655ee359ed537b017b7dba360b69237c9093c6'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libcrypt-1.1_1-3-msys-1.0.13-dll-0.tar.lzma',
|
||||
'31f157b6993509849407672503b8b89e09e9e37e8833b6678b9cbbcbf597f918'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/bash-3.1.23-1-msys-1.0.18-bin.tar.xz',
|
||||
'38da5419969ab883058a96322bb0f51434dd4e9f71de09cd4f75b96750944533'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/mksh-40.0.0c-1-msys-1.0.17-bin.tar.lzma',
|
||||
'8311342acf0b9f0264fd0d8384a826537973d798ca5904349fea1e0c9d909e54'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/termcap-0.20050421_1-2-msys-1.0.13-bin.tar.lzma',
|
||||
'906e756332b5fd6c10eeb4b6362f5957dd8cafa5679f89d9adbae59dff7f2ff2'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libregex-1.20090805-2-msys-1.0.13-dll-1.tar.lzma',
|
||||
'85dd8c1e27a90675c5f867be57ba7ae2bb55dde8cd2d19f284c896be134bd3d1'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/crypt-1.1_1-3-msys-1.0.13-bin.tar.lzma',
|
||||
'58369b42c38144d3aa5a337ebf1e182a66e88db30ccc42796f2074f251ee1fed'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/m4-1.4.14-1-msys-1.0.13-bin.tar.lzma',
|
||||
'41058bc9a691ad01fdd979f1a4ac4ee071bd5ce93f660db5c0b3cfad4487e33e'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/bison-2.4.2-1-msys-1.0.13-bin.tar.lzma',
|
||||
'349f3e312bf71f8a2ac68a7bd2f86b03dacc565b0fd27eef5d604e8be402390e'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/flex-2.5.35-2-msys-1.0.13-bin.tar.lzma',
|
||||
'9715511a2eafb7e2402029059d4b9db96bd40d8b72908db2571c009745c47a63'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/findutils-4.4.2-2-msys-1.0.13-bin.tar.lzma',
|
||||
'779e819b7942dc070c45f4cba633e6a9ae4bfe8b506a3541f4ce86ad0595726d'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/sed-4.2.1-2-msys-1.0.13-bin.tar.lzma',
|
||||
'f73059204cecb691e7840108b7c0cbbfcebf50c0e5c6e3a2326e0eedce5d1b94'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/gawk-3.1.7-2-msys-1.0.13-bin.tar.lzma',
|
||||
'eb15478ea76e75b666ad7fc7049de21b9f487e0e1ea0e96d40953a477e91c3dd'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/grep-2.5.4-2-msys-1.0.13-bin.tar.lzma',
|
||||
'4842a1754df98db994622e8ffab3bea7fbce77e05778cd5d3831e76ac90440ba'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/less-436-2-msys-1.0.13-bin.tar.lzma',
|
||||
'1bbd114846026f9ca4fcc4e18ba20f060384f623f1ef22b326df8c55419c0b84'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/diffutils-2.8.7.20071206cvs-3-msys-1.0.13-bin.tar.lzma',
|
||||
'522889b044492dd2337c4752ba6262995a11f352ca5fb8a8660349413ea9b864'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/texinfo-4.13a-2-msys-1.0.13-bin.tar.lzma',
|
||||
'241eb8e376bf69588d0e02aede35771503c5dcb15c440f97e15e30da79fea864'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/libmagic-5.04-1-msys-1.0.13-dll-1.tar.lzma',
|
||||
'65117008598675823b3fb25296d0d6c332ce56b72950e0f90f9063ac098afac3'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/file-5.04-1-msys-1.0.13-bin.tar.lzma',
|
||||
'e9ceffa49629524c84d07da77c1a5f37837f68a09e56cad30bea1df0a21e5fc2'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/mintty-1.0.3-1-msys-1.0.17-bin.tar.lzma',
|
||||
'0b3e7b57c81646eccaff3ca0310abe8367ace69992640be87199ecf5d9443085'),
|
||||
msys_p('http://downloads.sourceforge.net/mingw/patch-2.6.1-1-msys-1.0.13-bin.tar.lzma',
|
||||
'c8b7771304fb5e9fc33d8fca9045402f2e1bca055bf0b28127f3c3e85a254f67')
|
||||
].each do |package|
|
||||
potentially_at_compile_time do
|
||||
build_essential_msys_archive package.url do
|
||||
checksum package.checksum
|
||||
root_dir node['build-essential']['msys']['path']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[
|
||||
msys_p('http://iweb.dl.sourceforge.net/project/tdm-gcc/TDM-GCC%205%20series/5.1.0-tdm64-1/gcc-5.1.0-tdm64-1-core.tar.lzma',
|
||||
'29393aac890847089ad1e93f81a28f6744b1609c00b25afca818f3903e42e4bd'),
|
||||
msys_p('http://iweb.dl.sourceforge.net/project/tdm-gcc/MinGW-w64%20runtime/GCC%205%20series/mingw64runtime-v4-git20150618-gcc5-tdm64-1.tar.lzma',
|
||||
'29186e0bb36824b10026d78bdcf238d631d8fc1d90718d2ebbd9ec239b6f94dd'),
|
||||
msys_p('http://sourceforge.net/projects/tdm-gcc/files/GNU%20binutils/binutils-2.25-tdm64-1.tar.lzma',
|
||||
'4722bb7b4d46cef714234109e25e5d1cfd29f4e53365b6d615c8a00735f60e40'),
|
||||
msys_p('http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%205%20series/5.1.0-tdm64-1/gcc-5.1.0-tdm64-1-c++.tar.lzma',
|
||||
'17fd497318d1ac187a113e8665330d746ad9607a0406ab2374db0d8e6f4094d1')
|
||||
].each do |package|
|
||||
potentially_at_compile_time do
|
||||
build_essential_msys_archive package.url do
|
||||
root_dir node['build-essential']['msys']['path']
|
||||
checksum package.checksum
|
||||
mingw true
|
||||
end
|
||||
end
|
||||
end
|
@ -2,7 +2,7 @@
|
||||
# Cookbook Name:: build-essential
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2008-2009, Chef Software, Inc.
|
||||
# Copyright 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
106
cookbooks/build-essential/resources/build_essential.rb
Normal file
106
cookbooks/build-essential/resources/build_essential.rb
Normal file
@ -0,0 +1,106 @@
|
||||
#
|
||||
# Cookbook:: build-essential
|
||||
# resource:: build_essential
|
||||
#
|
||||
# Copyright:: 2008-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
provides :build_essential
|
||||
resource_name :build_essential
|
||||
|
||||
property :compile_time, [true, false], default: false
|
||||
|
||||
action :install do
|
||||
case node['platform_family']
|
||||
when 'debian'
|
||||
package %w( autoconf binutils-doc bison build-essential flex gettext ncurses-dev )
|
||||
when 'fedora', 'rhel'
|
||||
package %w( autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch )
|
||||
|
||||
# Ensure GCC 4 is available on older pre-6 EL
|
||||
package %w( gcc44 gcc44-c++ ) if node['platform_version'].to_i < 6
|
||||
when 'freebsd'
|
||||
package 'devel/gmake'
|
||||
package 'devel/autoconf'
|
||||
package 'devel/m4'
|
||||
package 'devel/gettext'
|
||||
# Only install gcc on freebsd 9.x - 10 uses clang
|
||||
package 'lang/gcc49' if node['platform_version'].to_i <= 9
|
||||
when 'mac_os_x'
|
||||
xcode_command_line_tools 'install'
|
||||
when 'omnios'
|
||||
package 'developer/gcc48'
|
||||
package 'developer/object-file'
|
||||
package 'developer/linker'
|
||||
package 'developer/library/lint'
|
||||
package 'developer/build/gnu-make'
|
||||
package 'system/header'
|
||||
package 'system/library/math/header-math'
|
||||
|
||||
# Per OmniOS documentation, the gcc bin dir isn't in the default
|
||||
# $PATH, so add it to the running process environment
|
||||
# http://omnios.omniti.com/wiki.php/DevEnv
|
||||
ENV['PATH'] = "#{ENV['PATH']}:/opt/gcc-4.7.2/bin"
|
||||
when 'solaris2'
|
||||
if node['platform_version'].to_f == 5.10
|
||||
Chef::Log.warn('build-essential does not support Solaris 10. You will need to install SUNWbison, SUNWgcc, SUNWggrp, SUNWgmake, and SUNWgtar from the Solaris DVD')
|
||||
elsif node['platform_version'].to_f == 5.11
|
||||
package 'autoconf'
|
||||
package 'automake'
|
||||
package 'bison'
|
||||
package 'gnu-coreutils'
|
||||
package 'flex'
|
||||
package 'gcc' do
|
||||
# lock because we don't use 5 yet
|
||||
version '4.8.2'
|
||||
end
|
||||
package 'gcc-3'
|
||||
package 'gnu-grep'
|
||||
package 'gnu-make'
|
||||
package 'gnu-patch'
|
||||
package 'gnu-tar'
|
||||
package 'make'
|
||||
package 'pkg-config'
|
||||
package 'ucb'
|
||||
end
|
||||
when 'smartos'
|
||||
package 'autoconf'
|
||||
package 'binutils'
|
||||
package 'build-essential'
|
||||
package 'gcc47'
|
||||
package 'gmake'
|
||||
package 'pkg-config'
|
||||
when 'suse'
|
||||
package %w( autoconf bison flex gcc gcc-c++ kernel-default-devel make m4 )
|
||||
package %w( gcc48 gcc48-c++ ) if node['platform_version'].to_i < 12
|
||||
when 'windows'
|
||||
include_recipe 'build-essential::_windows'
|
||||
else
|
||||
Chef::Log.warn <<-EOH
|
||||
A build-essential recipe does not exist for '#{node['platform_family']}'. This
|
||||
means the build-essential cookbook does not have support for the
|
||||
#{node['platform_family']} family. If you are not compiling gems with native
|
||||
extensions or building packages from source, this will likely not affect you.
|
||||
EOH
|
||||
end
|
||||
end
|
||||
|
||||
# this resource forces itself to run at compile_time
|
||||
def after_created
|
||||
return unless compile_time
|
||||
Array(action).each do |action|
|
||||
run_action(action)
|
||||
end
|
||||
end
|
7
cookbooks/build-essential/resources/msys_archive.rb
Normal file
7
cookbooks/build-essential/resources/msys_archive.rb
Normal file
@ -0,0 +1,7 @@
|
||||
actions :unpack
|
||||
default_action :unpack
|
||||
|
||||
attribute :source, kind_of: String, name_attribute: true
|
||||
attribute :root_dir, kind_of: String, required: true
|
||||
attribute :mingw, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :checksum, kind_of: String
|
@ -0,0 +1,61 @@
|
||||
#
|
||||
# Cookbook:: build-essential
|
||||
# Resource:: xcode_command_line_tools
|
||||
#
|
||||
# Copyright:: 2014-2016, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
resource_name :xcode_command_line_tools
|
||||
|
||||
action :install do
|
||||
if installed?
|
||||
Chef::Log.debug("#{new_resource} already installed - skipping")
|
||||
else
|
||||
converge_by("Install #{new_resource}") do
|
||||
# This script was graciously borrowed and modified from Tim Sutton's
|
||||
# osx-vm-templates at https://github.com/timsutton/osx-vm-templates/blob/b001475df54a9808d3d56d06e71b8fa3001fff42/scripts/xcode-cli-tools.sh
|
||||
execute 'install XCode Command Line tools' do
|
||||
command <<-EOH.gsub(/^ {14}/, '')
|
||||
# create the placeholder file that's checked by CLI updates' .dist code
|
||||
# in Apple's SUS catalog
|
||||
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
|
||||
# find the CLI Tools update
|
||||
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
|
||||
# install it
|
||||
softwareupdate -i "$PROD" --verbose
|
||||
# Remove the placeholder to prevent perpetual appearance in the update utility
|
||||
rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
|
||||
EOH
|
||||
# rubocop:enable Metrics/LineLength
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
#
|
||||
# Determine if the XCode Command Line Tools are installed
|
||||
#
|
||||
# @return [true, false]
|
||||
#
|
||||
def installed?
|
||||
cmd = Mixlib::ShellOut.new('pkgutil --pkgs=com.apple.pkg.CLTools_Executables')
|
||||
cmd.run_command
|
||||
cmd.error!
|
||||
true
|
||||
rescue Mixlib::ShellOut::ShellCommandFailed
|
||||
false
|
||||
end
|
||||
end
|
2
cookbooks/chef-solo-search/.gitignore
vendored
2
cookbooks/chef-solo-search/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/Gemfile.lock
|
||||
/tests/gemfiles/*.lock
|
@ -1,9 +0,0 @@
|
||||
before_install: gem update --system 1.8.25
|
||||
before_script: chef-solo -v
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 1.9.2
|
||||
- 1.8.7
|
||||
gemfile:
|
||||
- tests/gemfiles/Gemfile.11
|
||||
- tests/gemfiles/Gemfile.10
|
@ -1,31 +0,0 @@
|
||||
==========================
|
||||
chef-solo-search Changelog
|
||||
==========================
|
||||
|
||||
Version 0.5.1, September 19, 2013
|
||||
---------------------------------
|
||||
* Added missing metadata.json file
|
||||
|
||||
|
||||
Version 0.5.0, September 19, 2013
|
||||
---------------------------------
|
||||
* Allow node data bag path to be configured
|
||||
* updated install instructions with focus on Chef 11
|
||||
* Fixed Treetop dependency such that the omnibus installer is working
|
||||
* Added proper ruby Gemfile
|
||||
* use rake as runner for the tests
|
||||
* Fixed Travis CI builds
|
||||
|
||||
|
||||
Version 0.4.0, March 8, 2013
|
||||
----------------------------
|
||||
* Added support for 'chef_environment:_default' to queries.
|
||||
* Special case for lucene "anything range" [* TO *]
|
||||
* Added support for ruby bundler
|
||||
* Added support for Berkshelf
|
||||
|
||||
Version 0.3.0, July 27, 2011
|
||||
----------------------------
|
||||
First release of chef-solo-search as a self-contained project.
|
||||
Search functionality has been added to the original concept and the search
|
||||
extension as well as the data bags extension are shipped in libraries/
|
@ -1,8 +0,0 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'chef', '>= 10.4'
|
||||
gem 'treetop'
|
||||
gem 'rake'
|
||||
gem 'ruby-wmi'
|
||||
gem 'win32-service', :platforms => [:mswin, :mingw]
|
||||
|
@ -1,202 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
@ -1,23 +0,0 @@
|
||||
========================
|
||||
chef-solo-search Notices
|
||||
========================
|
||||
|
||||
Developed at edelight GmbH (http://www.edelight-group.com/).
|
||||
|
||||
Contributors:
|
||||
|
||||
* Arjun Singh
|
||||
* Brian p o'rourke <bpo@somnambulance.net>
|
||||
* Chris Roberts <chrisroberts.code@gmail.com>
|
||||
* Greg Karékinian <greg+github@karekinian.com>
|
||||
* Jeff Wallace <jeff@tjwallace.ca>
|
||||
* Michael Glass <me@mike.is>
|
||||
* Miquel Torres <miquel.torres@edelight.de>
|
||||
* Markus Korn <markus.korn@edelight.de>
|
||||
* Matt Gleeson <matt@gleeson.org>
|
||||
* Patrick Debois <Patrick.Debois@jedi.be>
|
||||
* Patrick Wyatt <pat@codeofhonor.com>
|
||||
* Paweł Pacana <pawel.pacana@syswise.eu>
|
||||
* Seth Chisamore <schisamo@opscode.com>
|
||||
* Teemu Matilainen <teemu.matilainen@iki.fi>
|
||||
* Tyler Rick
|
@ -1,148 +0,0 @@
|
||||
# chef-solo-search
|
||||
|
||||
[](https://travis-ci.org/edelight/chef-solo-search)
|
||||
|
||||
Chef-solo-search is a cookbook library that adds data bag search powers
|
||||
to Chef Solo. Data bag support was added to Chef Solo by Chef 0.10.4.
|
||||
Please see *Supported queries* for a list of query types which are supported.
|
||||
|
||||
## Requirements
|
||||
|
||||
* ruby >= 1.8
|
||||
* ruby-chef >= 0.10.4
|
||||
|
||||
## Installation
|
||||
|
||||
Install this cookbook into your Chef repository using your favorite cookbook
|
||||
management tool
|
||||
([Librarian](https://github.com/applicationsonline/librarian-chef),
|
||||
[Berkshelf](https://github.com/RiotGames/berkshelf), knife...).
|
||||
|
||||
In Chef 11, you must either add this to the run list of the nodes where it's used or include it as a dependency in the recipes that use it. [See changes in Chef 11.](http://docs.opscode.com/breaking_changes_chef_11.html#non-recipe-file-evaluation-includes-dependencies)
|
||||
|
||||
Now you have to make sure chef-solo knows about data bags, therefore add
|
||||
|
||||
data_bag_path "<node_work_path>/data_bags"
|
||||
|
||||
to the config file of chef-solo (defaults to /etc/chef/solo.rb).
|
||||
|
||||
The same for your roles, add
|
||||
|
||||
role_path "<node_work_path>/roles"
|
||||
|
||||
## Supported queries
|
||||
|
||||
The search methods supports a basic sub-set of the lucene query language.
|
||||
Sample supported queries are:
|
||||
|
||||
### General queries:
|
||||
|
||||
search(:users, "*:*")
|
||||
search(:users)
|
||||
search(:users, nil)
|
||||
getting all items in ':users'
|
||||
search(:users, "username:*")
|
||||
search(:users, "username:[* TO *]")
|
||||
getting all items from ':users' which have a 'username' attribute
|
||||
search(:users, "(NOT username:*)")
|
||||
search(:users, "(NOT username:[* TO *])")
|
||||
getting all items from ':users' which don't have a 'username' attribute
|
||||
|
||||
### Queries on attributes with string values:
|
||||
|
||||
search(:users, "username:speedy")
|
||||
getting all items from ':users' with username equals 'speedy'
|
||||
search(:users, "NOT username:speedy")
|
||||
getting all items from ':users' with username is unequal to 'speedy'
|
||||
search(:users, "username:spe*")
|
||||
getting all items which 'username'-value begins with 'spe'
|
||||
|
||||
### Queries on attributes with array values:
|
||||
|
||||
search(:users, "children:tom")
|
||||
getting all items which 'children' attribute contains 'tom'
|
||||
search(:users, "children:t*")
|
||||
getting all items which have at least one element in 'children'
|
||||
which starts with 't'
|
||||
|
||||
### Queries on attributes with boolean values:
|
||||
|
||||
search(:users, "married:true")
|
||||
|
||||
### Queries in attributes with integer values:
|
||||
|
||||
search(:users, "age:35")
|
||||
|
||||
### OR conditions in queries:
|
||||
|
||||
search(:users, "age:42 OR age:22")
|
||||
|
||||
### AND conditions in queries:
|
||||
|
||||
search(:users, "married:true AND age:35")
|
||||
|
||||
### NOT condition in queries:
|
||||
|
||||
search(:users, "children:tom NOT gender:female")
|
||||
|
||||
### More complex queries:
|
||||
|
||||
search(:users, "children:tom NOT gender:female AND age:42")
|
||||
|
||||
|
||||
## Supported Objects
|
||||
The search methods have support for 'roles', 'nodes' and 'databags'.
|
||||
|
||||
### Roles
|
||||
You can use the standard role objects in json form and put them into your role path
|
||||
|
||||
{
|
||||
"name": "monitoring",
|
||||
"default_attributes": { },
|
||||
"override_attributes": { },
|
||||
"json_class": "Chef::Role",
|
||||
"description": "This is just a monitoring role, no big deal.",
|
||||
"run_list": [
|
||||
],
|
||||
"chef_type": "role"
|
||||
|
||||
|
||||
### Nodes
|
||||
Nodes are injected through a databag called 'node'. Create a databag called 'node' and put your json files there
|
||||
You can use the standard node objects in json form.
|
||||
|
||||
{
|
||||
"id": "vagrant",
|
||||
"name": "vagrant-vm",
|
||||
"chef_environment": "_default",
|
||||
"json_class": "Chef::Node",
|
||||
"automatic": {
|
||||
"hostname": "vagrant.vm",
|
||||
"os": "centos"
|
||||
},
|
||||
"normal": {
|
||||
},
|
||||
"chef_type": "node",
|
||||
"default": {
|
||||
},
|
||||
"override": {
|
||||
},
|
||||
"run_list": [
|
||||
"role[monitoring]"
|
||||
]
|
||||
}
|
||||
|
||||
### Databags
|
||||
You can use the standard databag objects in json form
|
||||
|
||||
{
|
||||
"id": "my-ssh",
|
||||
"hostgroup_name": "all",
|
||||
"command_line": "$USER1$/check_ssh $HOSTADDRESS$"
|
||||
}
|
||||
|
||||
## Running tests
|
||||
|
||||
Running tests is as simple as:
|
||||
|
||||
% rake test
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env rake
|
||||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.pattern = "tests/test_*.rb"
|
||||
t.libs = %w(libraries)
|
||||
end
|
||||
|
||||
desc "Run tests"
|
||||
task :default => :test
|
@ -1,74 +0,0 @@
|
||||
#
|
||||
# Copyright 2011, edelight GmbH
|
||||
#
|
||||
# Authors:
|
||||
# Markus Korn <markus.korn@edelight.de>
|
||||
# Seth Chisamore <schisamo@opscode.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if Chef::Config[:solo]
|
||||
|
||||
# add currrent dir to load path
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
# All chef/solr_query/* classes were removed in Chef 11; Load vendored copy
|
||||
# that ships with this cookbook
|
||||
$: << File.expand_path("vendor", File.dirname(__FILE__)) if Chef::VERSION.to_i >= 11
|
||||
|
||||
# Ensure the treetop gem is installed and available
|
||||
begin
|
||||
require 'treetop'
|
||||
rescue LoadError
|
||||
run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
|
||||
chef_gem = Chef::Resource::ChefGem.new("treetop", run_context)
|
||||
chef_gem.version('>= 1.4')
|
||||
chef_gem.run_action(:install)
|
||||
end
|
||||
|
||||
require 'search/overrides'
|
||||
require 'search/parser'
|
||||
|
||||
module Search; class Helper; end; end
|
||||
|
||||
# The search and data_bag related methods moved form `Chef::Mixin::Language`
|
||||
# to `Chef::DSL::DataQuery` in Chef 11.
|
||||
if Chef::VERSION.to_i >= 11
|
||||
module Chef::DSL::DataQuery
|
||||
def self.included(base)
|
||||
base.send(:include, Search::Overrides)
|
||||
end
|
||||
end
|
||||
Search::Helper.send(:include, Chef::DSL::DataQuery)
|
||||
else
|
||||
module Chef::Mixin::Language
|
||||
def self.included(base)
|
||||
base.send(:include, Search::Overrides)
|
||||
end
|
||||
end
|
||||
Search::Helper.send(:include, Chef::Mixin::Language)
|
||||
end
|
||||
|
||||
class Chef
|
||||
class Search
|
||||
class Query
|
||||
def initialize(*args)
|
||||
end
|
||||
def search(*args, &block)
|
||||
::Search::Helper.new.search(*args, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,100 +0,0 @@
|
||||
#
|
||||
# Copyright 2011, edelight GmbH
|
||||
#
|
||||
# Authors:
|
||||
# Markus Korn <markus.korn@edelight.de>
|
||||
# Seth Chisamore <schisamo@opscode.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module Search
|
||||
module Overrides
|
||||
# Overwrite the search method of recipes to operate locally by using
|
||||
# data found in data_bags.
|
||||
# Only very basic lucene syntax is supported and also sorting the result
|
||||
# is not implemented, if this search method does not support a given query
|
||||
# an exception is raised.
|
||||
# This search() method returns a block iterator or an Array, depending
|
||||
# on how this method is called.
|
||||
def search(obj, query=nil, sort=nil, start=0, rows=1000, &block)
|
||||
if !sort.nil?
|
||||
raise "Sorting search results is not supported"
|
||||
end
|
||||
_query = Query.parse(query)
|
||||
if _query.nil?
|
||||
raise "Query #{query} is not supported"
|
||||
end
|
||||
_result = []
|
||||
|
||||
case obj
|
||||
when :node
|
||||
nodes = search_nodes(_query, start, rows, &block)
|
||||
_result += nodes
|
||||
when :role
|
||||
roles = search_roles(_query, start, rows, &block)
|
||||
_result += roles
|
||||
else
|
||||
bags = search_data_bag(_query, obj, start, rows, &block)
|
||||
_result += bags
|
||||
end
|
||||
|
||||
|
||||
if block_given?
|
||||
pos = 0
|
||||
while (pos >= start and pos < (start + rows) and pos < _result.size)
|
||||
yield _result[pos]
|
||||
pos += 1
|
||||
end
|
||||
else
|
||||
return _result.slice(start, rows)
|
||||
end
|
||||
end
|
||||
|
||||
def search_nodes(_query, start, rows, &block)
|
||||
_result = []
|
||||
node_path = Chef::Config[:nodes_path] || File.join(Chef::Config[:data_bag_path], "node")
|
||||
Dir.glob(File.join(node_path, "*.json")).map do |f|
|
||||
# parse and hashify the node
|
||||
node = Chef::JSONCompat.from_json(IO.read(f))
|
||||
if _query.match(node.to_hash)
|
||||
_result << node
|
||||
end
|
||||
end
|
||||
return _result
|
||||
end
|
||||
|
||||
def search_roles(_query, start, rows, &block)
|
||||
_result = []
|
||||
Dir.glob(File.join(Chef::Config[:role_path], "*.json")).map do |f|
|
||||
# parse and hashify the role
|
||||
role = Chef::JSONCompat.from_json(IO.read(f))
|
||||
if _query.match(role.to_hash)
|
||||
_result << role
|
||||
end
|
||||
end
|
||||
return _result
|
||||
end
|
||||
|
||||
def search_data_bag(_query, bag_name, start, rows, &block)
|
||||
_result = []
|
||||
data_bag(bag_name.to_s).each do |bag_item_id|
|
||||
bag_item = data_bag_item(bag_name.to_s, bag_item_id)
|
||||
if _query.match(bag_item)
|
||||
_result << bag_item
|
||||
end
|
||||
end
|
||||
return _result
|
||||
end
|
||||
end
|
||||
end
|
@ -1,222 +0,0 @@
|
||||
#
|
||||
# Copyright 2011, edelight GmbH
|
||||
#
|
||||
# Authors:
|
||||
# Markus Korn <markus.korn@edelight.de>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/solr_query/query_transform'
|
||||
|
||||
# mock QueryTransform such that we can access the location of the lucene grammar
|
||||
class Chef
|
||||
class SolrQuery
|
||||
class QueryTransform
|
||||
def self.base_path
|
||||
class_variable_get(:@@base_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_flat_hash(hsh, prefix="")
|
||||
result = {}
|
||||
hsh.each_pair do |key, value|
|
||||
if value.kind_of?(Hash)
|
||||
result.merge!(build_flat_hash(value, "#{prefix}#{key}_"))
|
||||
else
|
||||
result[prefix+key] = value
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
module Lucene
|
||||
|
||||
class Term < Treetop::Runtime::SyntaxNode
|
||||
# compares a query value and a value, tailing '*'-wildcards are handled correctly.
|
||||
# Value can either be a string or an array, all other objects are converted
|
||||
# to a string and than checked.
|
||||
def match( value )
|
||||
if value.is_a?(Array)
|
||||
value.any?{ |x| self.match(x) }
|
||||
else
|
||||
File.fnmatch(self.text_value, value.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Field < Treetop::Runtime::SyntaxNode
|
||||
# simple field -> value matches, supporting tailing '*'-wildcards in keys
|
||||
# as well as in values
|
||||
def match( item )
|
||||
keys = self.elements[0].match(item)
|
||||
if keys.nil?
|
||||
false
|
||||
else
|
||||
keys.any?{ |key| self.elements[1].match(item[key]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# we don't support range matches
|
||||
# range of integers would be easy to implement
|
||||
# but string ranges are hard
|
||||
class FiledRange < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
# we handle '[* TO *]' as a special case since it is common in
|
||||
# cookbooks for matching the existence of keys
|
||||
class InclFieldRange
|
||||
def match(item)
|
||||
field = self.elements[0].text_value
|
||||
range_start = self.elements[1].transform
|
||||
range_end = self.elements[2].transform
|
||||
if range_start == "*" and range_end == "*"
|
||||
!!item[field]
|
||||
else
|
||||
raise "Ranges not really supported yet"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ExclFieldRange < FieldRange
|
||||
end
|
||||
|
||||
class RangeValue < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class FieldName < Treetop::Runtime::SyntaxNode
|
||||
def match( item )
|
||||
if self.text_value.count("_") > 0
|
||||
item.merge!(build_flat_hash(item))
|
||||
end
|
||||
if self.text_value.end_with?("*")
|
||||
part = self.text_value.chomp("*")
|
||||
item.keys.collect{ |key| key.start_with?(part)? key: nil}.compact
|
||||
else
|
||||
if item.has_key?(self.text_value)
|
||||
[self.text_value,]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Body < Treetop::Runtime::SyntaxNode
|
||||
def match( item )
|
||||
self.elements[0].match( item )
|
||||
end
|
||||
end
|
||||
|
||||
class Group < Treetop::Runtime::SyntaxNode
|
||||
def match( item )
|
||||
self.elements[0].match(item)
|
||||
end
|
||||
end
|
||||
|
||||
class BinaryOp < Treetop::Runtime::SyntaxNode
|
||||
def match( item )
|
||||
self.elements[1].match(
|
||||
self.elements[0].match(item),
|
||||
self.elements[2].match(item)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class OrOperator < Treetop::Runtime::SyntaxNode
|
||||
def match( cond1, cond2 )
|
||||
cond1 or cond2
|
||||
end
|
||||
end
|
||||
|
||||
class AndOperator < Treetop::Runtime::SyntaxNode
|
||||
def match( cond1, cond2 )
|
||||
cond1 and cond2
|
||||
end
|
||||
end
|
||||
|
||||
# we don't support fuzzy string matching
|
||||
class FuzzyOp < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class BoostOp < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class FuzzyParam < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class UnaryOp < Treetop::Runtime::SyntaxNode
|
||||
def match( item )
|
||||
self.elements[0].match(
|
||||
self.elements[1].match(item)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class NotOperator < Treetop::Runtime::SyntaxNode
|
||||
def match( cond )
|
||||
not cond
|
||||
end
|
||||
end
|
||||
|
||||
class RequiredOperator < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class ProhibitedOperator < Treetop::Runtime::SyntaxNode
|
||||
end
|
||||
|
||||
class Phrase < Treetop::Runtime::SyntaxNode
|
||||
# a quoted ::Term
|
||||
def match( value )
|
||||
self.elements[0].match(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Query
|
||||
# initialize the parser by using the grammar shipped with chef
|
||||
@@grammar = File.join(Chef::SolrQuery::QueryTransform.base_path, "lucene.treetop")
|
||||
Treetop.load(@@grammar)
|
||||
@@parser = LuceneParser.new
|
||||
|
||||
def self.parse(data)
|
||||
# parse the query into a query tree
|
||||
if data.nil?
|
||||
data = "*:*"
|
||||
end
|
||||
tree = @@parser.parse(data)
|
||||
if tree.nil?
|
||||
msg = "Parse error at offset: #{@@parser.index}\n"
|
||||
msg += "Reason: #{@@parser.failure_reason}"
|
||||
raise "Query #{data} is not supported: #{msg}"
|
||||
end
|
||||
self.clean_tree(tree)
|
||||
tree
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.clean_tree(root_node)
|
||||
# remove all SyntaxNode elements from the tree, we don't need them as
|
||||
# the related ruby class already knowns what to do.
|
||||
return if root_node.elements.nil?
|
||||
root_node.elements.delete_if do |node|
|
||||
node.class.name == "Treetop::Runtime::SyntaxNode"
|
||||
end
|
||||
root_node.elements.each { |node| self.clean_tree(node) }
|
||||
end
|
||||
end
|
||||
|
@ -1,150 +0,0 @@
|
||||
#
|
||||
# Author:: Seth Falcon (<seth@opscode.com>)
|
||||
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
grammar Lucene
|
||||
|
||||
rule body
|
||||
(expression / space)* <Body>
|
||||
end
|
||||
|
||||
rule expression
|
||||
operation / group / field / field_range / term / string
|
||||
end
|
||||
|
||||
rule term
|
||||
keyword valid_letter+ <Term> / !keyword !"?" valid_letter <Term>
|
||||
end
|
||||
|
||||
rule field
|
||||
field_name ":" (term/string/group) <Field>
|
||||
end
|
||||
|
||||
rule field_range
|
||||
field_name ":" "[" range_value " TO " range_value "]" <InclFieldRange>
|
||||
/
|
||||
field_name ":" "{" range_value " TO " range_value "}" <ExclFieldRange>
|
||||
end
|
||||
|
||||
rule field_name
|
||||
!keyword valid_letter+ <FieldName>
|
||||
end
|
||||
|
||||
rule range_value
|
||||
valid_letter+ <RangeValue> / "*" <RangeValue>
|
||||
end
|
||||
|
||||
rule group
|
||||
space? '(' body ')' space? <Group>
|
||||
end
|
||||
|
||||
rule operation
|
||||
binary_op / unary_op / fuzzy_op / boost_op
|
||||
end
|
||||
|
||||
rule unary_op
|
||||
not_op / required_op / prohibited_op
|
||||
end
|
||||
|
||||
rule binary_op
|
||||
(group / field / field_range / term) space? boolean_operator space+ body <BinaryOp>
|
||||
end
|
||||
|
||||
rule boolean_operator
|
||||
and_operator / or_operator
|
||||
end
|
||||
|
||||
rule and_operator
|
||||
'AND' <AndOperator> / '&&' <AndOperator>
|
||||
end
|
||||
|
||||
rule or_operator
|
||||
'OR' <OrOperator> / '||' <OrOperator>
|
||||
end
|
||||
|
||||
rule not_op
|
||||
not_operator space (group / field / field_range / term / string) <UnaryOp>
|
||||
/
|
||||
bang_operator space? (group / field / field_range / term / string) <UnaryOp>
|
||||
end
|
||||
|
||||
rule not_operator
|
||||
'NOT' <NotOperator>
|
||||
end
|
||||
|
||||
rule bang_operator
|
||||
'!' <NotOperator>
|
||||
end
|
||||
|
||||
rule required_op
|
||||
!valid_letter required_operator (term/string) <UnaryOp>
|
||||
/
|
||||
required_operator (term/string) <UnaryOp>
|
||||
end
|
||||
|
||||
rule required_operator
|
||||
'+' <RequiredOperator>
|
||||
end
|
||||
|
||||
rule prohibited_op
|
||||
!valid_letter prohibited_operator (field/field_range/term/string) <UnaryOp>
|
||||
end
|
||||
|
||||
rule prohibited_operator
|
||||
'-' <ProhibitedOperator>
|
||||
end
|
||||
|
||||
rule boost_op
|
||||
(term/string) '^' fuzzy_param <BoostOp>
|
||||
end
|
||||
|
||||
rule fuzzy_op
|
||||
(term/string) '~' fuzzy_param? (space / !valid_letter) <FuzzyOp>
|
||||
end
|
||||
|
||||
rule fuzzy_param
|
||||
[0-9] '.'? [0-9] <FuzzyParam> / [0-9]+ <FuzzyParam>
|
||||
end
|
||||
|
||||
rule string
|
||||
'"' term (space term)* '"' <Phrase>
|
||||
end
|
||||
|
||||
rule keyword
|
||||
'AND' / 'OR' / 'NOT'
|
||||
end
|
||||
|
||||
rule valid_letter
|
||||
start_letter+ ([a-zA-Z0-9@*?_.-] / '\\' special_char)*
|
||||
end
|
||||
|
||||
rule start_letter
|
||||
[a-zA-Z0-9@._*] / '\\' special_char
|
||||
end
|
||||
|
||||
rule end_letter
|
||||
[a-zA-Z0-9*?_.] / '\\' special_char
|
||||
end
|
||||
|
||||
rule special_char
|
||||
[-+&|!(){}\[\]^"~*?:\\]
|
||||
end
|
||||
|
||||
rule space
|
||||
[\s]+
|
||||
end
|
||||
end
|
@ -1,285 +0,0 @@
|
||||
#
|
||||
# Author:: Seth Falcon (<seth@opscode.com>)
|
||||
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'treetop'
|
||||
|
||||
module Lucene
|
||||
SEP = "__=__"
|
||||
|
||||
class Term < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"T:#{self.text_value}"
|
||||
end
|
||||
|
||||
def transform
|
||||
self.text_value
|
||||
end
|
||||
end
|
||||
|
||||
class Field < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
field = self.elements[0].text_value
|
||||
term = self.elements[1].to_array
|
||||
"(F:#{field} #{term})"
|
||||
end
|
||||
|
||||
def transform
|
||||
field = self.elements[0].text_value
|
||||
term = self.elements[1]
|
||||
if term.is_a? Phrase
|
||||
str = term.transform
|
||||
# remove quotes
|
||||
str = str[1 ... (str.length - 1)]
|
||||
"content:\"#{field}#{SEP}#{str}\""
|
||||
else
|
||||
"content:#{field}#{SEP}#{term.transform}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class FieldRange < Treetop::Runtime::SyntaxNode
|
||||
|
||||
def to_array
|
||||
field = self.elements[0].text_value
|
||||
range_start = self.elements[1].to_array
|
||||
range_end = self.elements[2].to_array
|
||||
"(FR:#{field} #{left}#{range_start}#{right} #{left}#{range_end}#{right})"
|
||||
end
|
||||
|
||||
def transform
|
||||
field = self.elements[0].text_value
|
||||
range_start = self.elements[1].transform
|
||||
range_end = self.elements[2].transform
|
||||
# FIXME: handle special cases for missing start/end
|
||||
if ("*" == range_start && "*" == range_end)
|
||||
"content:#{field}#{SEP}*"
|
||||
elsif "*" == range_end
|
||||
"content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}\\ufff0#{right}"
|
||||
elsif "*" == range_start
|
||||
"content:#{left}#{field}#{SEP} TO #{field}#{SEP}#{range_end}#{right}"
|
||||
else
|
||||
"content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}#{range_end}#{right}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class InclFieldRange < FieldRange
|
||||
def left
|
||||
"["
|
||||
end
|
||||
def right
|
||||
"]"
|
||||
end
|
||||
end
|
||||
|
||||
class ExclFieldRange < FieldRange
|
||||
def left
|
||||
"{"
|
||||
end
|
||||
def right
|
||||
"}"
|
||||
end
|
||||
end
|
||||
|
||||
class RangeValue < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
self.text_value
|
||||
end
|
||||
|
||||
def transform
|
||||
to_array
|
||||
end
|
||||
end
|
||||
|
||||
class FieldName < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
self.text_value
|
||||
end
|
||||
|
||||
def transform
|
||||
to_array
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Body < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
self.elements.map { |x| x.to_array }.join(" ")
|
||||
end
|
||||
|
||||
def transform
|
||||
self.elements.map { |x| x.transform }.join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
class Group < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"(" + self.elements[0].to_array + ")"
|
||||
end
|
||||
|
||||
def transform
|
||||
"(" + self.elements[0].transform + ")"
|
||||
end
|
||||
end
|
||||
|
||||
class BinaryOp < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
op = self.elements[1].to_array
|
||||
a = self.elements[0].to_array
|
||||
b = self.elements[2].to_array
|
||||
"(#{op} #{a} #{b})"
|
||||
end
|
||||
|
||||
def transform
|
||||
op = self.elements[1].transform
|
||||
a = self.elements[0].transform
|
||||
b = self.elements[2].transform
|
||||
"#{a} #{op} #{b}"
|
||||
end
|
||||
end
|
||||
|
||||
class AndOperator < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"OP:AND"
|
||||
end
|
||||
|
||||
def transform
|
||||
"AND"
|
||||
end
|
||||
end
|
||||
|
||||
class OrOperator < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"OP:OR"
|
||||
end
|
||||
|
||||
def transform
|
||||
"OR"
|
||||
end
|
||||
end
|
||||
|
||||
class FuzzyOp < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
a = self.elements[0].to_array
|
||||
param = self.elements[1]
|
||||
if param
|
||||
"(OP:~ #{a} #{param.to_array})"
|
||||
else
|
||||
"(OP:~ #{a})"
|
||||
end
|
||||
end
|
||||
|
||||
def transform
|
||||
a = self.elements[0].transform
|
||||
param = self.elements[1]
|
||||
if param
|
||||
"#{a}~#{param.transform}"
|
||||
else
|
||||
"#{a}~"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class BoostOp < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
a = self.elements[0].to_array
|
||||
param = self.elements[1]
|
||||
"(OP:^ #{a} #{param.to_array})"
|
||||
end
|
||||
|
||||
def transform
|
||||
a = self.elements[0].transform
|
||||
param = self.elements[1]
|
||||
"#{a}^#{param.transform}"
|
||||
end
|
||||
end
|
||||
|
||||
class FuzzyParam < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
self.text_value
|
||||
end
|
||||
|
||||
def transform
|
||||
self.text_value
|
||||
end
|
||||
end
|
||||
|
||||
class UnaryOp < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
op = self.elements[0].to_array
|
||||
a = self.elements[1].to_array
|
||||
"(#{op} #{a})"
|
||||
end
|
||||
|
||||
def transform
|
||||
op = self.elements[0].transform
|
||||
a = self.elements[1].transform
|
||||
spc = case op
|
||||
when "+", "-"
|
||||
""
|
||||
else
|
||||
" "
|
||||
end
|
||||
"#{op}#{spc}#{a}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class NotOperator < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"OP:NOT"
|
||||
end
|
||||
|
||||
def transform
|
||||
"NOT"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class RequiredOperator < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"OP:+"
|
||||
end
|
||||
|
||||
def transform
|
||||
"+"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ProhibitedOperator < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"OP:-"
|
||||
end
|
||||
|
||||
def transform
|
||||
"-"
|
||||
end
|
||||
end
|
||||
|
||||
class Phrase < Treetop::Runtime::SyntaxNode
|
||||
def to_array
|
||||
"STR:#{self.text_value}"
|
||||
end
|
||||
|
||||
def transform
|
||||
"#{self.text_value}"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,65 +0,0 @@
|
||||
#
|
||||
# Author:: Seth Falcon (<seth@opscode.com>)
|
||||
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require 'treetop'
|
||||
require 'chef/solr_query/lucene_nodes'
|
||||
|
||||
class Chef
|
||||
class Exceptions
|
||||
class QueryParseError < StandardError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Chef
|
||||
class SolrQuery
|
||||
class QueryTransform
|
||||
@@base_path = File.expand_path(File.dirname(__FILE__))
|
||||
Treetop.load(File.join(@@base_path, 'lucene.treetop'))
|
||||
@@parser = LuceneParser.new
|
||||
|
||||
def self.parse(data)
|
||||
tree = @@parser.parse(data)
|
||||
msg = "Parse error at offset: #{@@parser.index}\n"
|
||||
msg += "Reason: #{@@parser.failure_reason}"
|
||||
raise Chef::Exceptions::QueryParseError, msg if tree.nil?
|
||||
self.clean_tree(tree)
|
||||
tree.to_array
|
||||
end
|
||||
|
||||
def self.transform(data)
|
||||
return "*:*" if data == "*:*"
|
||||
tree = @@parser.parse(data)
|
||||
msg = "Parse error at offset: #{@@parser.index}\n"
|
||||
msg += "Reason: #{@@parser.failure_reason}"
|
||||
raise Chef::Exceptions::QueryParseError, msg if tree.nil?
|
||||
self.clean_tree(tree)
|
||||
tree.transform
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.clean_tree(root_node)
|
||||
return if root_node.elements.nil?
|
||||
root_node.elements.delete_if do |node|
|
||||
node.class.name == "Treetop::Runtime::SyntaxNode"
|
||||
end
|
||||
root_node.elements.each { |node| self.clean_tree(node) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,35 +0,0 @@
|
||||
{
|
||||
"license": "Apache 2.0",
|
||||
"replacing": {
|
||||
},
|
||||
"suggestions": {
|
||||
},
|
||||
"long_description": "# chef-solo-search\n\n[](https://travis-ci.org/edelight/chef-solo-search)\n\nChef-solo-search is a cookbook library that adds data bag search powers\nto Chef Solo. Data bag support was added to Chef Solo by Chef 0.10.4.\nPlease see *Supported queries* for a list of query types which are supported.\n\n## Requirements\n\n * ruby >= 1.8\n * ruby-chef >= 0.10.4\n\n## Installation\n\nInstall this cookbook into your Chef repository using your favorite cookbook\nmanagement tool\n([Librarian](https://github.com/applicationsonline/librarian-chef),\n[Berkshelf](https://github.com/RiotGames/berkshelf), knife...).\n\nIn Chef 11, you must either add this to the run list of the nodes where it's used or include it as a dependency in the recipes that use it. [See changes in Chef 11.](http://docs.opscode.com/breaking_changes_chef_11.html#non-recipe-file-evaluation-includes-dependencies)\n\nNow you have to make sure chef-solo knows about data bags, therefore add\n\n data_bag_path \"<node_work_path>/data_bags\"\n\nto the config file of chef-solo (defaults to /etc/chef/solo.rb).\n\nThe same for your roles, add\n\n role_path \"<node_work_path>/roles\"\n\n## Supported queries\n\nThe search methods supports a basic sub-set of the lucene query language.\nSample supported queries are:\n\n### General queries:\n\n search(:users, \"*:*\")\n search(:users)\n search(:users, nil)\n getting all items in ':users'\n search(:users, \"username:*\")\n search(:users, \"username:[* TO *]\")\n getting all items from ':users' which have a 'username' attribute\n search(:users, \"(NOT username:*)\")\n search(:users, \"(NOT username:[* TO *])\")\n getting all items from ':users' which don't have a 'username' attribute\n\n### Queries on attributes with string values:\n\n search(:users, \"username:speedy\")\n getting all items from ':users' with username equals 'speedy'\n search(:users, \"NOT username:speedy\")\n getting all items from ':users' with username is unequal to 'speedy'\n search(:users, \"username:spe*\")\n getting all items which 'username'-value begins with 'spe'\n\n### Queries on attributes with array values:\n\n search(:users, \"children:tom\")\n getting all items which 'children' attribute contains 'tom'\n search(:users, \"children:t*\")\n getting all items which have at least one element in 'children'\n which starts with 't'\n\n### Queries on attributes with boolean values:\n\n search(:users, \"married:true\")\n\n### Queries in attributes with integer values:\n\n search(:users, \"age:35\")\n\n### OR conditions in queries:\n\n search(:users, \"age:42 OR age:22\")\n\n### AND conditions in queries:\n\n search(:users, \"married:true AND age:35\")\n\n### NOT condition in queries:\n\n search(:users, \"children:tom NOT gender:female\")\n\n### More complex queries:\n\n search(:users, \"children:tom NOT gender:female AND age:42\")\n\n\n## Supported Objects\nThe search methods have support for 'roles', 'nodes' and 'databags'.\n\n### Roles\nYou can use the standard role objects in json form and put them into your role path\n\n {\n \"name\": \"monitoring\",\n \"default_attributes\": { },\n \"override_attributes\": { },\n \"json_class\": \"Chef::Role\",\n \"description\": \"This is just a monitoring role, no big deal.\",\n \"run_list\": [\n ],\n \"chef_type\": \"role\"\n\n\n### Nodes\nNodes are injected through a databag called 'node'. Create a databag called 'node' and put your json files there\nYou can use the standard node objects in json form.\n\n {\n \"id\": \"vagrant\",\n \"name\": \"vagrant-vm\",\n \"chef_environment\": \"_default\",\n \"json_class\": \"Chef::Node\",\n \"automatic\": {\n \"hostname\": \"vagrant.vm\",\n \"os\": \"centos\"\n },\n \"normal\": {\n },\n \"chef_type\": \"node\",\n \"default\": {\n },\n \"override\": {\n },\n \"run_list\": [\n \"role[monitoring]\"\n ]\n }\n\n### Databags\nYou can use the standard databag objects in json form\n\n {\n \"id\": \"my-ssh\",\n \"hostgroup_name\": \"all\",\n \"command_line\": \"$USER1$/check_ssh $HOSTADDRESS$\"\n }\n\n## Running tests\n\nRunning tests is as simple as:\n\n % rake test\n",
|
||||
"attributes": {
|
||||
},
|
||||
"providing": {
|
||||
},
|
||||
"maintainer_email": "markus.korn@edelight.de",
|
||||
"groupings": {
|
||||
},
|
||||
"conflicting": {
|
||||
},
|
||||
"description": "Data bag search for Chef Solo",
|
||||
"name": "chef-solo-search",
|
||||
"version": "0.5.1",
|
||||
"dependencies": {
|
||||
},
|
||||
"platforms": {
|
||||
"freebsd": ">= 0.0.0",
|
||||
"fedora": ">= 0.0.0",
|
||||
"debian": ">= 0.0.0",
|
||||
"ubuntu": ">= 0.0.0",
|
||||
"centos": ">= 0.0.0",
|
||||
"redhat": ">= 0.0.0"
|
||||
},
|
||||
"maintainer": "edelight GmbH",
|
||||
"recipes": {
|
||||
},
|
||||
"recommendations": {
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
name "chef-solo-search"
|
||||
maintainer "edelight GmbH"
|
||||
maintainer_email "markus.korn@edelight.de"
|
||||
license "Apache 2.0"
|
||||
description "Data bag search for Chef Solo"
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version "0.5.1"
|
||||
|
||||
%w{ ubuntu debian redhat centos fedora freebsd}.each do |os|
|
||||
supports os
|
||||
end
|
@ -1,2 +0,0 @@
|
||||
# This file is intentionally blank, which allows this
|
||||
# entire repository to be used as a cookbook
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"id": "alpha",
|
||||
"name": "alpha.example.com",
|
||||
"json_class": "Chef::Node",
|
||||
"run_list": ["role[test_server]"],
|
||||
"chef_environment": "default",
|
||||
"automatic": {
|
||||
"hostname": "alpha.example.com"
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"id": "beta",
|
||||
"name": "beta.example.com",
|
||||
"json_class": "Chef::Node",
|
||||
"run_list": ["role[test_server]","role[beta_server]"],
|
||||
"chef_environment": "default",
|
||||
"automatic": {
|
||||
"hostname": "beta.example.com"
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"id": "without_json_class",
|
||||
"name": "wjc.example.com",
|
||||
"chef_environment": "default",
|
||||
"hostname": "wjc.example.com",
|
||||
"run_list": ["role[test_server]"]
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"id": "jerry",
|
||||
"username": "speedy",
|
||||
"age": 22,
|
||||
"gender": "male",
|
||||
"married": true,
|
||||
"color": "green"
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"id": "lea",
|
||||
"username": "lea",
|
||||
"age": 35,
|
||||
"gender": "female",
|
||||
"married": true,
|
||||
"children": ["tom"],
|
||||
"tag": "tag::test",
|
||||
"tags": ["tag::first", "tag::second"]
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
{
|
||||
"id": "mike",
|
||||
"username": "mike the hammer",
|
||||
"age": 42,
|
||||
"gender": "male",
|
||||
"married": true,
|
||||
"children": ["tom", "jerry"],
|
||||
"address": {
|
||||
"street": {
|
||||
"floor": 1
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"id": "tom",
|
||||
"username": "tom von homme",
|
||||
"age": 13,
|
||||
"gender": "male",
|
||||
"married": false,
|
||||
"address": {
|
||||
"street": "wilhelmsstrasse"
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "chef", "~> 10.0"
|
||||
gem "rake"
|
@ -1,5 +0,0 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "chef", "~> 11.0"
|
||||
gem "rake"
|
||||
gem "treetop"
|
@ -1,45 +0,0 @@
|
||||
#
|
||||
# Copyright 2011, edelight GmbH
|
||||
#
|
||||
# Authors:
|
||||
# Markus Korn <markus.korn@edelight.de>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "test/unit"
|
||||
require "chef"
|
||||
|
||||
# mocking chef such that it thinks it's running as chef-solo and knows about
|
||||
# the location of the data_bag
|
||||
Chef::Config[:solo] = true
|
||||
Chef::Config[:data_bag_path] = "tests/data/data_bags"
|
||||
|
||||
def data_bag_item(bag, item)
|
||||
# wrapper around creating a new Recipe instance and calling data_bag on it
|
||||
node = Chef::Node.new()
|
||||
events = Chef::EventDispatch::Dispatcher.new
|
||||
cookbooks = Chef::CookbookCollection.new()
|
||||
run_context = Chef::RunContext.new(node, cookbooks, events)
|
||||
return Chef::Recipe.new("test_cookbook", "test_recipe", run_context).data_bag_item(bag, item)
|
||||
end
|
||||
|
||||
class TestDataBags < Test::Unit::TestCase
|
||||
|
||||
def test_data_bag
|
||||
item = data_bag_item("users", "mike")
|
||||
assert_equal item["age"], 42
|
||||
assert_equal item[:age], nil #upstream code for chef-solo does not use mashes
|
||||
end
|
||||
|
||||
end
|
@ -1,244 +0,0 @@
|
||||
#
|
||||
# Copyright 2011, edelight GmbH
|
||||
#
|
||||
# Authors:
|
||||
# Markus Korn <markus.korn@edelight.de>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "rubygems"
|
||||
require "test/unit"
|
||||
require "chef"
|
||||
|
||||
# mocking chef such that it thinks it's running as chef-solo and knows about
|
||||
# the location of the data_bag
|
||||
Chef::Config[:solo] = true
|
||||
Chef::Config[:data_bag_path] = "#{File.dirname(__FILE__)}/data/data_bags"
|
||||
|
||||
# load the extension
|
||||
require File.expand_path('../../libraries/search', __FILE__)
|
||||
|
||||
module SearchDbTests
|
||||
|
||||
def test_search_all
|
||||
# try to get data of all users
|
||||
nodes = search(:users, "*:*")
|
||||
assert_equal nodes.length, 4
|
||||
nodes = search(:users)
|
||||
assert_equal nodes.length, 4
|
||||
nodes = search(:users, nil)
|
||||
assert_equal nodes.length, 4
|
||||
end
|
||||
|
||||
def test_search_exact_match
|
||||
nodes = search(:users, "username:speedy")
|
||||
assert_equal nodes.length, 1
|
||||
assert_equal nodes[0]["username"], "speedy"
|
||||
end
|
||||
|
||||
def test_get_all_with_field
|
||||
nodes = search(:users, "username:*")
|
||||
assert nodes.length > 0
|
||||
assert nodes.all?{|x| !x["username"].nil?}
|
||||
end
|
||||
|
||||
def test_get_all_without_field
|
||||
nodes = search(:users, "(NOT username:*)")
|
||||
assert nodes.length == 0
|
||||
nodes = search(:users, "(NOT color:*)")
|
||||
assert nodes.length == 3
|
||||
assert nodes.all?{|x| x["color"].nil?}
|
||||
end
|
||||
|
||||
def test_get_all_but_speedy
|
||||
nodes = search(:users, "NOT username:speedy")
|
||||
assert nodes.length > 0
|
||||
assert nodes.all?{|x| x["username"] != "speedy"}
|
||||
end
|
||||
|
||||
def test_array_includes
|
||||
nodes = search(:users, "children:tom")
|
||||
assert nodes.length == 2
|
||||
assert nodes.all?{ |x| x["children"].include?("tom") }
|
||||
nodes = search(:users, "children:jerry")
|
||||
assert nodes.length == 1
|
||||
assert nodes.all?{ |x| x["children"].include?("jerry") }
|
||||
end
|
||||
|
||||
def test_boolean
|
||||
nodes = search(:users, "married:true")
|
||||
assert nodes.length == 3
|
||||
assert nodes.all?{ |x| x["married"] == true }
|
||||
nodes = search(:users, "married:false")
|
||||
assert nodes.length == 1
|
||||
assert nodes[0]["married"] == false
|
||||
end
|
||||
|
||||
def test_integer
|
||||
nodes = search(:users, "age:35")
|
||||
assert nodes.length == 1
|
||||
assert nodes[0]["age"] == 35
|
||||
end
|
||||
|
||||
def test_AND_condition
|
||||
nodes = search(:users, "married:true AND age:35")
|
||||
assert nodes.length == 1
|
||||
assert nodes[0]["username"] == "lea"
|
||||
end
|
||||
|
||||
def test_OR_condition
|
||||
nodes = search(:users, "age:42 OR age:22")
|
||||
assert nodes.length == 2
|
||||
end
|
||||
|
||||
def test_NOT_condition
|
||||
nodes = search(:users, "children:tom AND (NOT gender:female)")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "children:tom AND (NOT gender:female) AND age:42")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "children:tom AND (NOT gender:female) AND (NOT age:42)")
|
||||
assert nodes.length == 0
|
||||
end
|
||||
|
||||
def test_any_value
|
||||
nodes = search(:users, "children:*")
|
||||
assert nodes.length == 2
|
||||
end
|
||||
|
||||
def test_any_value_lucene_range
|
||||
nodes = search(:users, "address:[* TO *]")
|
||||
assert nodes.length == 2
|
||||
end
|
||||
|
||||
def test_general_lucene_range_fails
|
||||
assert_raises RuntimeError do
|
||||
nodes = search(:users, "children:[aaa TO zzz]")
|
||||
end
|
||||
end
|
||||
|
||||
def test_block_usage
|
||||
# bracket syntax
|
||||
result = []
|
||||
search(:users, "*:*") {|x| result << x["id"]}
|
||||
assert result.length == 4
|
||||
|
||||
# do...end syntax
|
||||
result = []
|
||||
search(:users) do |x|
|
||||
result << x["id"]
|
||||
end
|
||||
assert result.length == 4
|
||||
end
|
||||
|
||||
def test_check_escaped_chars
|
||||
nodes = search(:users, 'tag:tag\:\:test')
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "tag:tag\\:\\:test")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, 'tags:tag\:\:first')
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "tags:tag\\:\\:first")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, 'tags:tag\:\:*')
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "tags:tag\\:\\:*")
|
||||
assert nodes.length == 1
|
||||
end
|
||||
|
||||
def test_wildcards
|
||||
nodes = search(:users, "gender:f??ale")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "username:spee?y")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "username:spee*")
|
||||
assert nodes.length == 1
|
||||
end
|
||||
|
||||
def test_empty_field_value
|
||||
assert_raise(RuntimeError) {
|
||||
search(:users, "gender:#{nil} AND age:35")
|
||||
}
|
||||
assert_raise(RuntimeError) {
|
||||
search(:users, "gender: AND age:35")
|
||||
}
|
||||
assert_raise(RuntimeError) {
|
||||
search(:users, "gender:\"\" AND age:35")
|
||||
}
|
||||
end
|
||||
|
||||
def test_OR_group
|
||||
nodes = search(:users, "id:(mike OR tom)")
|
||||
assert nodes.length == 2
|
||||
end
|
||||
|
||||
def test_nested_fieldnames
|
||||
nodes = search(:users, "address_street:wilhelmsstrasse")
|
||||
assert nodes.length == 1
|
||||
nodes = search(:users, "address_street_floor:1")
|
||||
assert nodes.length == 1
|
||||
end
|
||||
end
|
||||
|
||||
module SearchNodeTests
|
||||
def test_list_nodes
|
||||
nodes = search(:node)
|
||||
assert_equal Chef::Node, nodes.find{ |n| n["hostname"] == "alpha.example.com" }.class
|
||||
assert_equal Chef::Node, nodes.find{ |n| n["hostname"] == "beta.example.com" }.class
|
||||
assert_equal Hash, nodes.find{ |n| n["hostname"] == "wjc.example.com" }.class
|
||||
assert_equal 3, nodes.length
|
||||
end
|
||||
|
||||
def test_search_node_with_wide_filter
|
||||
nodes = search(:node, "role:test_server AND chef_environment:default")
|
||||
assert_equal 2, nodes.length
|
||||
end
|
||||
|
||||
def test_search_node_with_narrow_filter
|
||||
nodes = search(:node, "role:beta_server")
|
||||
assert_equal 1, nodes.length
|
||||
end
|
||||
|
||||
def test_search_node_with_attr_filter
|
||||
nodes = search(:node, "hostname:beta.example.com")
|
||||
assert_equal 1, nodes.length
|
||||
end
|
||||
|
||||
def test_search_node_without_json_class
|
||||
nodes = search(:node, "chef_environment:default")
|
||||
assert_equal 3, nodes.length
|
||||
end
|
||||
end
|
||||
|
||||
class TestImplicitSearchDB < Test::Unit::TestCase
|
||||
include SearchDbTests
|
||||
include SearchNodeTests
|
||||
|
||||
def search(*args, &block)
|
||||
# wrapper around creating a new Recipe instance and calling search on it
|
||||
node = Chef::Node.new()
|
||||
cookbooks = Chef::CookbookCollection.new()
|
||||
run_context = Chef::RunContext.new(node, cookbooks, nil)
|
||||
return Chef::Recipe.new("test_cookbook", "test_recipe", run_context).search(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
class TestExplicitSearchDB < Test::Unit::TestCase
|
||||
include SearchDbTests
|
||||
include SearchNodeTests
|
||||
|
||||
def search(*args, &block)
|
||||
Chef::Search::Query.new.search(*args, &block)
|
||||
end
|
||||
end
|
||||
|
48
cookbooks/compat_resource/CHANGELOG.md
Normal file
48
cookbooks/compat_resource/CHANGELOG.md
Normal file
@ -0,0 +1,48 @@
|
||||
# compat_resource Cookbook CHANGELOG
|
||||
|
||||
This file is used to list changes made in each version of the compat_resource cookbook.
|
||||
|
||||
## 12.16.2 (2016-11-09)
|
||||
|
||||
- Sync chef-client changes from Chef 12.16.42
|
||||
|
||||
## 12.16.1 (2016-10-20)
|
||||
|
||||
- add delayed_action helper
|
||||
|
||||
## 12.16.0 (2016-10-19)
|
||||
|
||||
- Sync chef-client changes from Chef 12.16.14
|
||||
|
||||
## 12.14.7 (2016-09-26)
|
||||
|
||||
- Update to 12.14.89 Chef
|
||||
- Fix autoload by applying fix from #106
|
||||
|
||||
## 12.14.6 (2016-09-20)
|
||||
|
||||
- Update backported codebase to Chef 12.14.77 which brings in yum_repository updates and why-run enabled by default in custom resources
|
||||
|
||||
## 12.14.5 (2016-09-19)
|
||||
|
||||
- Prevent spamming messages in Chefspec runs for cookbooks that depend on compat_resource
|
||||
|
||||
## 12.14.4 (2016-09-19)
|
||||
|
||||
- Fix delayed notifications cloning
|
||||
|
||||
## 12.14.3 (2016-09-12)
|
||||
|
||||
- Fix subscribes notifications
|
||||
|
||||
## 12.14.2 (2016-09-09)
|
||||
|
||||
- Improve documentation
|
||||
- keep ChefCompat::Resource defined even if we don't load
|
||||
|
||||
## 12.14.1 (2016-09-07)
|
||||
|
||||
- add yum_repository resource from Chef 12.14
|
||||
- Update the minimum chef version in the metadata to 12.1
|
||||
- Added maintainers files
|
||||
- suppress constant redef warnings when running chefspec
|
2
cookbooks/compat_resource/CONTRIBUTING.md
Normal file
2
cookbooks/compat_resource/CONTRIBUTING.md
Normal file
@ -0,0 +1,2 @@
|
||||
Please refer to
|
||||
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD
|
16
cookbooks/compat_resource/MAINTAINERS.md
Normal file
16
cookbooks/compat_resource/MAINTAINERS.md
Normal file
@ -0,0 +1,16 @@
|
||||
<!-- This is a generated file. Please do not edit directly -->
|
||||
|
||||
# Maintainers
|
||||
|
||||
This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead.
|
||||
|
||||
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead.
|
||||
|
||||
# Project Maintainer
|
||||
* [Lamont Granquist](https://github.com/lamont-granquist)
|
||||
|
||||
# Maintainers
|
||||
* [Jennifer Davis](https://github.com/sigje)
|
||||
* [Tim Smith](https://github.com/tas50)
|
||||
* [Thom May](https://github.com/thommay)
|
||||
* [Lamont Granquist](https://github.com/lamont-granquist)
|
60
cookbooks/compat_resource/README.md
Normal file
60
cookbooks/compat_resource/README.md
Normal file
@ -0,0 +1,60 @@
|
||||
# compat_resource cookbook
|
||||
|
||||
[](https://travis-ci.org/chef-cookbooks/compat_resource) [](https://supermarket.chef.io/cookbooks/compat_resource)
|
||||
|
||||
This cookbook backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards. This includes [Custom Resource](https://docs.chef.io/custom_resources.html) functionality, notification improvements, as well as new resources added to core chef. It allows for the usage of these new resources in cookbooks without requiring the very latest Chef client release.
|
||||
|
||||
## Backported functionality
|
||||
|
||||
- [Custom Resources](https://docs.chef.io/custom_resources.html)
|
||||
- [apt_repository](https://docs.chef.io/resource_apt_repository.html)
|
||||
- [apt_update](https://docs.chef.io/resource_apt_update.html)
|
||||
- [systemd_unit](https://docs.chef.io/resource_systemd_unit.html)
|
||||
- [yum_repository](https://docs.chef.io/resource_yum_repository.html)
|
||||
- [:before notifications](https://docs.chef.io/resources.html#timers)
|
||||
|
||||
## Requirements
|
||||
|
||||
### Platforms
|
||||
|
||||
- All platforms supported by Chef
|
||||
|
||||
### Chef
|
||||
|
||||
- Chef 12.1+
|
||||
|
||||
### Cookbooks
|
||||
|
||||
- none
|
||||
|
||||
## Usage
|
||||
|
||||
To use this cookbook, put `depends 'compat_resource'` in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works.
|
||||
|
||||
## Custom Resources?
|
||||
|
||||
Curious about how to use custom resources?
|
||||
|
||||
- Docs: <https://docs.chef.io/custom_resources.html>
|
||||
- Slides: <https://docs.chef.io/decks/custom_resources.html>
|
||||
|
||||
## License & Authors
|
||||
|
||||
- Author:: Lamont Granquist ([lamont@chef.io](mailto:lamont@chef.io))
|
||||
- Author:: John Keiser ([jkeiser@chef.io](mailto:jkeiser@chef.io))
|
||||
|
||||
```text
|
||||
Copyright:: 2015-2016 Chef Software, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
@ -0,0 +1,29 @@
|
||||
module ChefCompat
|
||||
module CopiedFromChef
|
||||
def self.extend_chef_module(chef_module, target)
|
||||
target.instance_eval do
|
||||
include chef_module
|
||||
@chef_module = chef_module
|
||||
def self.method_missing(name, *args, &block)
|
||||
@chef_module.send(name, *args, &block)
|
||||
end
|
||||
def self.const_missing(name)
|
||||
@chef_module.const_get(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This patch to CopiedFromChef's ActionClass is necessary for the include to work
|
||||
require 'chef/resource'
|
||||
class Chef < ::Chef
|
||||
class Resource < ::Chef::Resource
|
||||
module ActionClass
|
||||
def self.use_inline_resources
|
||||
end
|
||||
def self.include_resource_dsl(include_resource_dsl)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,47 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/constants'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
NOT_PASSED = Object.new
|
||||
def NOT_PASSED.to_s
|
||||
"NOT_PASSED"
|
||||
end
|
||||
|
||||
def NOT_PASSED.inspect
|
||||
to_s
|
||||
end
|
||||
NOT_PASSED.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,40 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/delayed_evaluator'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class DelayedEvaluator < (defined?(::Chef::DelayedEvaluator) ? ::Chef::DelayedEvaluator : Proc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,73 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/core'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/universal"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/notifying_block"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
# Part of a family of DSL mixins.
|
||||
#
|
||||
# Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
|
||||
# - this does not target core chef resources and providers.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - cookbook authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
|
||||
# - this adds cores providers on top of the Recipe DSL.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - core chef authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
|
||||
# - this adds resources and attributes files.
|
||||
# - do not add helpers which manipulate the resource collection.
|
||||
# - this is for general-purpose stuff that is useful nearly everywhere.
|
||||
# - it also pollutes the namespace of nearly every context, watch out.
|
||||
#
|
||||
module Core
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Core, self) if defined?(::Chef::DSL::Core)
|
||||
include Chef::DSL::Universal
|
||||
include Chef::DSL::DeclareResource
|
||||
include Chef::Mixin::NotifyingBlock
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,315 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/declare_resource'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
module DeclareResource
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::DeclareResource, self) if defined?(::Chef::DSL::DeclareResource)
|
||||
|
||||
# Helper for switching run_contexts. Allows for using :parent or :root in place of
|
||||
# passing the run_context. Executes the block in the run_context. Returns the return
|
||||
# value of the passed block.
|
||||
#
|
||||
# @param rc [Chef::RunContext,Symbol] Either :root, :parent or a Chef::RunContext
|
||||
#
|
||||
# @return return value of the block
|
||||
#
|
||||
# @example
|
||||
# # creates/returns a 'service[foo]' resource in the root run_context
|
||||
# resource = with_run_context(:root)
|
||||
# edit_resource(:service, "foo") do
|
||||
# action :nothing
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def with_run_context(rc)
|
||||
raise ArgumentError, "with_run_context is useless without a block" unless block_given?
|
||||
old_run_context = @run_context
|
||||
@run_context =
|
||||
case rc
|
||||
when Chef::RunContext
|
||||
rc
|
||||
when :root
|
||||
run_context.root_run_context
|
||||
when :parent
|
||||
run_context.parent_run_context
|
||||
else
|
||||
raise ArgumentError, "bad argument to run_context helper, must be :root, :parent, or a Chef::RunContext"
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
@run_context = old_run_context
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and delete it. This
|
||||
# will raise Chef::Exceptions::ResourceNotFound if the resource is not found.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The resource
|
||||
#
|
||||
# @example
|
||||
# delete_resource!(:template, '/x/y.txy')
|
||||
#
|
||||
def delete_resource!(type, name, run_context: self.run_context)
|
||||
run_context.resource_collection.delete("#{type}[#{name}]").tap do |resource|
|
||||
# Purge any pending notifications too. This will not raise an exception
|
||||
# if there are no notifications.
|
||||
if resource
|
||||
run_context.before_notification_collection.delete(resource.declared_key)
|
||||
run_context.immediate_notification_collection.delete(resource.declared_key)
|
||||
run_context.delayed_notification_collection.delete(resource.declared_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and delete it. Returns
|
||||
# nil if the resource is not found and should not fail.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The resource
|
||||
#
|
||||
# @example
|
||||
# delete_resource(:template, '/x/y.txy')
|
||||
#
|
||||
def delete_resource(type, name, run_context: self.run_context)
|
||||
delete_resource!(type, name, run_context: run_context)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
nil
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name and edit the resource. If the resource is not
|
||||
# found this will raise Chef::Exceptions::ResourceNotFound. This is the correct API to use for
|
||||
# "chef_rewind" functionality.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# edit_resource!(:template, '/x/y.txy') do
|
||||
# cookbook_name: cookbook_name
|
||||
# end
|
||||
#
|
||||
def edit_resource!(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
resource = find_resource!(type, name, run_context: run_context)
|
||||
if resource_attrs_block
|
||||
if defined?(new_resource)
|
||||
resource.instance_exec(new_resource, &resource_attrs_block)
|
||||
else
|
||||
resource.instance_exec(&resource_attrs_block)
|
||||
end
|
||||
end
|
||||
resource
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If it exists,
|
||||
# return it. If it does not exist, create it. This is a useful function
|
||||
# for accumulator patterns. In CRUD terminology this is an "upsert" operation and is
|
||||
# used to assert that the resource must exist with the specified properties.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The updated or created resource
|
||||
#
|
||||
# @example
|
||||
# resource = edit_resource(:template, '/x/y.txy') do
|
||||
# source "y.txy.erb"
|
||||
# variables {}
|
||||
# end
|
||||
# resource.variables.merge!({ home: "/home/klowns" })
|
||||
#
|
||||
def edit_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
edit_resource!(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If the resource is not
|
||||
# found this will raise Chef::Exceptions::ResourceNotFound. This API is identical to the
|
||||
# resources() call and while it is a synonym it is not intended to deprecate that call.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# resource = find_resource!(:template, '/x/y.txy')
|
||||
#
|
||||
def find_resource!(type, name, run_context: self.run_context)
|
||||
raise ArgumentError, "find_resource! does not take a block" if block_given?
|
||||
run_context.resource_collection.find(type => name)
|
||||
end
|
||||
|
||||
# Lookup a resource in the resource collection by name. If the resource is not found
|
||||
# the will be no exception raised and the call will return nil. If a block is given and
|
||||
# no resource is found it will create the resource using the block, if the resource is
|
||||
# found then the block will not be applied. The block version is similar to create_if_missing
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
#
|
||||
# @return [Chef::Resource] The updated resource
|
||||
#
|
||||
# @example
|
||||
# if ( find_resource(:template, '/x/y.txy') )
|
||||
# # do something
|
||||
# else
|
||||
# # don't worry about the error
|
||||
# end
|
||||
#
|
||||
# @example
|
||||
# # this API can be used to return a resource from an outer run context, and will only create
|
||||
# # an action :nothing service if one does not already exist.
|
||||
# resource = with_run_context(:root) do
|
||||
# find_resource(:service, 'whatever') do
|
||||
# action :nothing
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def find_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block)
|
||||
find_resource!(type, name, run_context: run_context)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
if resource_attrs_block
|
||||
declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end # returns nil otherwise
|
||||
end
|
||||
|
||||
# Instantiates a resource (via #build_resource), then adds it to the
|
||||
# resource collection. Note that resource classes are looked up directly,
|
||||
# so this will create the resource you intended even if the method name
|
||||
# corresponding to that resource has been overridden.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The new resource.
|
||||
#
|
||||
# @example
|
||||
# declare_resource(:file, '/x/y.txy', caller[0]) do
|
||||
# action :delete
|
||||
# end
|
||||
# # Equivalent to
|
||||
# file '/x/y.txt' do
|
||||
# action :delete
|
||||
# end
|
||||
#
|
||||
def declare_resource(type, name, created_at = nil, run_context: self.run_context, create_if_missing: false, &resource_attrs_block)
|
||||
created_at ||= caller[0]
|
||||
|
||||
if create_if_missing
|
||||
Chef::Log.deprecation "build_resource with a create_if_missing flag is deprecated, use edit_resource instead"
|
||||
# midly goofy since we call edit_resource only to re-call ourselves, but that's why its deprecated...
|
||||
return edit_resource(type, name, created_at, run_context: run_context, &resource_attrs_block)
|
||||
end
|
||||
|
||||
resource = build_resource(type, name, created_at, &resource_attrs_block)
|
||||
|
||||
run_context.resource_collection.insert(resource, resource_type: type, instance_name: name)
|
||||
resource
|
||||
end
|
||||
|
||||
# Instantiate a resource of the given +type+ with the given +name+ and
|
||||
# attributes as given in the +resource_attrs_block+.
|
||||
#
|
||||
# The resource is NOT added to the resource collection.
|
||||
#
|
||||
# @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
|
||||
# @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
|
||||
# @param created_at [String] The caller of the resource. Use `caller[0]`
|
||||
# to get the caller of your function. Defaults to the caller of this
|
||||
# function.
|
||||
# @param run_context [Chef::RunContext] the run_context of the resource collection to operate on
|
||||
# @param resource_attrs_block A block that lets you set attributes of the
|
||||
# resource (it is instance_eval'd on the resource instance).
|
||||
#
|
||||
# @return [Chef::Resource] The new resource.
|
||||
#
|
||||
# @example
|
||||
# build_resource(:file, '/x/y.txy', caller[0]) do
|
||||
# action :delete
|
||||
# end
|
||||
#
|
||||
def build_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block)
|
||||
created_at ||= caller[0]
|
||||
|
||||
# this needs to be lazy in order to avoid circular dependencies since ResourceBuilder
|
||||
# will requires the entire provider+resolver universe
|
||||
require "chef_compat/copied_from_chef/chef/resource_builder" unless defined?(Chef::ResourceBuilder)
|
||||
|
||||
Chef::ResourceBuilder.new(
|
||||
type: type,
|
||||
name: name,
|
||||
created_at: created_at,
|
||||
params: @params,
|
||||
run_context: run_context,
|
||||
cookbook_name: cookbook_name,
|
||||
recipe_name: recipe_name,
|
||||
enclosing_provider: self.is_a?(Chef::Provider) ? self : nil
|
||||
).build(&resource_attrs_block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,292 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/platform_introspection'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
|
||||
# == Chef::DSL::PlatformIntrospection
|
||||
# Provides the DSL for platform-dependent switch logic, such as
|
||||
# #value_for_platform.
|
||||
module PlatformIntrospection
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::PlatformIntrospection, self) if defined?(::Chef::DSL::PlatformIntrospection)
|
||||
|
||||
# Implementation class for determining platform dependent values
|
||||
class PlatformDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformDependentValue : Object)
|
||||
|
||||
# Create a platform dependent value object.
|
||||
# === Arguments
|
||||
# platform_hash (Hash) a hash of the same structure as Chef::Platform,
|
||||
# like this:
|
||||
# {
|
||||
# :debian => {:default => 'the value for all debian'}
|
||||
# [:centos, :redhat, :fedora] => {:default => "value for all EL variants"}
|
||||
# :ubuntu => { :default => "default for ubuntu", '10.04' => "value for 10.04 only"},
|
||||
# :default => "the default when nothing else matches"
|
||||
# }
|
||||
# * platforms can be specified as Symbols or Strings
|
||||
# * multiple platforms can be grouped by using an Array as the key
|
||||
# * values for platforms need to be Hashes of the form:
|
||||
# {platform_version => value_for_that_version}
|
||||
# * the exception to the above is the default value, which is given as
|
||||
# :default => default_value
|
||||
def initialize(platform_hash)
|
||||
super if defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue)
|
||||
@values = {}
|
||||
platform_hash.each { |platforms, value| set(platforms, value) }
|
||||
end
|
||||
|
||||
def value_for_node(node)
|
||||
platform, version = node[:platform].to_s, node[:platform_version].to_s
|
||||
# Check if we match a version constraint via Chef::VersionConstraint::Platform and Chef::Version::Platform
|
||||
matched_value = match_versions(node)
|
||||
if @values.key?(platform) && @values[platform].key?(version)
|
||||
@values[platform][version]
|
||||
elsif matched_value
|
||||
matched_value
|
||||
elsif @values.key?(platform) && @values[platform].key?("default")
|
||||
@values[platform]["default"]
|
||||
elsif @values.key?("default")
|
||||
@values["default"]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def match_versions(node)
|
||||
begin
|
||||
platform, version = node[:platform].to_s, node[:platform_version].to_s
|
||||
return nil unless @values.key?(platform)
|
||||
node_version = Chef::Version::Platform.new(version)
|
||||
key_matches = []
|
||||
keys = @values[platform].keys
|
||||
keys.each do |k|
|
||||
begin
|
||||
if Chef::VersionConstraint::Platform.new(k).include?(node_version)
|
||||
key_matches << k
|
||||
end
|
||||
rescue Chef::Exceptions::InvalidVersionConstraint => e
|
||||
Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
|
||||
Chef::Log.debug(e)
|
||||
end
|
||||
end
|
||||
return @values[platform][version] if key_matches.include?(version)
|
||||
case key_matches.length
|
||||
when 0
|
||||
return nil
|
||||
when 1
|
||||
return @values[platform][key_matches.first]
|
||||
else
|
||||
raise "Multiple matches detected for #{platform} with values #{@values}. The matches are: #{key_matches}"
|
||||
end
|
||||
rescue Chef::Exceptions::InvalidCookbookVersion => e
|
||||
# Lets not break because someone passes a weird string like 'default' :)
|
||||
Chef::Log.debug(e)
|
||||
Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint"
|
||||
return nil
|
||||
rescue Chef::Exceptions::InvalidPlatformVersion => e
|
||||
Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format"
|
||||
Chef::Log.debug(e)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def set(platforms, value)
|
||||
if platforms.to_s == "default"
|
||||
@values["default"] = value
|
||||
else
|
||||
assert_valid_platform_values!(platforms, value)
|
||||
Array(platforms).each { |platform| @values[platform.to_s] = normalize_keys(value) }
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_keys(hash)
|
||||
hash.inject({}) do |h, key_value|
|
||||
keys, value = *key_value
|
||||
Array(keys).each do |key|
|
||||
h[key.to_s] = value
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def assert_valid_platform_values!(platforms, value)
|
||||
unless value.kind_of?(Hash)
|
||||
msg = "platform dependent values must be specified in the format :platform => {:version => value} "
|
||||
msg << "you gave a value #{value.inspect} for platform(s) #{platforms}"
|
||||
raise ArgumentError, msg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Given a hash similar to the one we use for Platforms, select a value from the hash. Supports
|
||||
# per platform defaults, along with a single base default. Arrays may be passed as hash keys and
|
||||
# will be expanded.
|
||||
#
|
||||
# === Parameters
|
||||
# platform_hash:: A platform-style hash.
|
||||
#
|
||||
# === Returns
|
||||
# value:: Whatever the most specific value of the hash is.
|
||||
def value_for_platform(platform_hash)
|
||||
PlatformDependentValue.new(platform_hash).value_for_node(node)
|
||||
end
|
||||
|
||||
# Given a list of platforms, returns true if the current recipe is being run on a node with
|
||||
# that platform, false otherwise.
|
||||
#
|
||||
# === Parameters
|
||||
# args:: A list of platforms. Each platform can be in string or symbol format.
|
||||
#
|
||||
# === Returns
|
||||
# true:: If the current platform is in the list
|
||||
# false:: If the current platform is not in the list
|
||||
def platform?(*args)
|
||||
has_platform = false
|
||||
|
||||
args.flatten.each do |platform|
|
||||
has_platform = true if platform.to_s == node[:platform]
|
||||
end
|
||||
|
||||
has_platform
|
||||
end
|
||||
|
||||
# Implementation class for determining platform family dependent values
|
||||
class PlatformFamilyDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue : Object)
|
||||
|
||||
# Create a platform family dependent value object.
|
||||
# === Arguments
|
||||
# platform_family_hash (Hash) a map of platform families to values.
|
||||
# like this:
|
||||
# {
|
||||
# :rhel => "value for all EL variants"
|
||||
# :fedora => "value for fedora variants fedora and amazon" ,
|
||||
# [:fedora, :rhel] => "value for all known redhat variants"
|
||||
# :debian => "value for debian variants including debian, ubuntu, mint" ,
|
||||
# :default => "the default when nothing else matches"
|
||||
# }
|
||||
# * platform families can be specified as Symbols or Strings
|
||||
# * multiple platform families can be grouped by using an Array as the key
|
||||
# * values for platform families can be any object, with no restrictions. Some examples:
|
||||
# - [:stop, :start]
|
||||
# - "mysql-devel"
|
||||
# - { :key => "value" }
|
||||
def initialize(platform_family_hash)
|
||||
super if defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue)
|
||||
@values = {}
|
||||
@values["default"] = nil
|
||||
platform_family_hash.each { |platform_families, value| set(platform_families, value) }
|
||||
end
|
||||
|
||||
def value_for_node(node)
|
||||
if node.key?(:platform_family)
|
||||
platform_family = node[:platform_family].to_s
|
||||
if @values.key?(platform_family)
|
||||
@values[platform_family]
|
||||
else
|
||||
@values["default"]
|
||||
end
|
||||
else
|
||||
@values["default"]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set(platform_family, value)
|
||||
if platform_family.to_s == "default"
|
||||
@values["default"] = value
|
||||
else
|
||||
Array(platform_family).each { |family| @values[family.to_s] = value }
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Given a hash mapping platform families to values, select a value from the hash. Supports a single
|
||||
# base default if platform family is not in the map. Arrays may be passed as hash keys and will be
|
||||
# expanded
|
||||
#
|
||||
# === Parameters
|
||||
# platform_family_hash:: A hash in the form { platform_family_name => value }
|
||||
#
|
||||
# === Returns
|
||||
# value:: Whatever the most specific value of the hash is.
|
||||
def value_for_platform_family(platform_family_hash)
|
||||
PlatformFamilyDependentValue.new(platform_family_hash).value_for_node(node)
|
||||
end
|
||||
|
||||
# Given a list of platform families, returns true if the current recipe is being run on a
|
||||
# node within that platform family, false otherwise.
|
||||
#
|
||||
# === Parameters
|
||||
# args:: A list of platform families. Each platform family can be in string or symbol format.
|
||||
#
|
||||
# === Returns
|
||||
# true:: if the current node platform family is in the list.
|
||||
# false:: if the current node platform family is not in the list.
|
||||
def platform_family?(*args)
|
||||
args.flatten.any? do |platform_family|
|
||||
platform_family.to_s == node[:platform_family]
|
||||
end
|
||||
end
|
||||
|
||||
# Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb
|
||||
# Given a node object, returns whether the node is a docker container.
|
||||
#
|
||||
# === Parameters
|
||||
# node:: [Chef::Node] The node to check.
|
||||
#
|
||||
# === Returns
|
||||
# true:: if the current node is a docker container
|
||||
# false:: if the current node is not a docker container
|
||||
def docker?(node = run_context.nil? ? nil : run_context.node)
|
||||
# Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
|
||||
# and that makes us sad too.
|
||||
node && node[:virtualization] && node[:virtualization][:systems] &&
|
||||
node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# **DEPRECATED**
|
||||
# This used to be part of chef/mixin/language. Load the file to activate the deprecation code.
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,37 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/recipe'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/dsl/core"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
module Recipe
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe, self) if defined?(::Chef::DSL::Recipe)
|
||||
include Chef::DSL::Core
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
module FullDSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe::FullDSL, self) if defined?(::Chef::DSL::Recipe::FullDSL)
|
||||
include Chef::DSL::Recipe
|
||||
extend Chef::Mixin::LazyModuleInclude
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,70 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/dsl/universal'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Author:: Christopher Walters (<cw@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/dsl/platform_introspection"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/powershell_out"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module DSL
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL)
|
||||
# Part of a family of DSL mixins.
|
||||
#
|
||||
# Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
|
||||
# - this does not target core chef resources and providers.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - cookbook authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
|
||||
# - this adds cores providers on top of the Recipe DSL.
|
||||
# - this is restricted to recipe/resource/provider context where a resource collection exists.
|
||||
# - core chef authors should typically include modules into here.
|
||||
#
|
||||
# Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
|
||||
# - this adds resources and attributes files.
|
||||
# - do not add helpers which manipulate the resource collection.
|
||||
# - this is for general-purpose stuff that is useful nearly everywhere.
|
||||
# - it also pollutes the namespace of nearly every context, watch out.
|
||||
#
|
||||
module Universal
|
||||
CopiedFromChef.extend_chef_module(::Chef::DSL::Universal, self) if defined?(::Chef::DSL::Universal)
|
||||
include Chef::DSL::PlatformIntrospection
|
||||
include Chef::Mixin::PowershellOut
|
||||
include Chef::Mixin::ShellOut
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,98 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/lazy_module_include'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Copyright:: Copyright 2011-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
# If you have:
|
||||
#
|
||||
# module A
|
||||
# extend LazyModuleInclude
|
||||
# end
|
||||
#
|
||||
# module B
|
||||
# include A
|
||||
# end
|
||||
#
|
||||
# module C
|
||||
# include B
|
||||
# end
|
||||
#
|
||||
# module Monkeypatches
|
||||
# def monkey
|
||||
# puts "monkey!"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# A.send(:include, Monkeypatches)
|
||||
#
|
||||
# Then B and C and any classes that they're included in will also get the #monkey method patched into them.
|
||||
#
|
||||
module LazyModuleInclude
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::LazyModuleInclude, self) if defined?(::Chef::Mixin::LazyModuleInclude)
|
||||
|
||||
# Most of the magick is in this hook which creates a closure over the parent class and then builds an
|
||||
# "infector" module which infects all descendants and which is responsible for updating the list of
|
||||
# descendants in the parent class.
|
||||
def included(klass)
|
||||
super
|
||||
parent_klass = self
|
||||
infector = Module.new do
|
||||
define_method(:included) do |subklass|
|
||||
super(subklass)
|
||||
subklass.extend(infector)
|
||||
parent_klass.descendants.push(subklass)
|
||||
end
|
||||
end
|
||||
klass.extend(infector)
|
||||
parent_klass.descendants.push(klass)
|
||||
end
|
||||
|
||||
def descendants
|
||||
@descendants ||= []
|
||||
end
|
||||
|
||||
def include(*classes)
|
||||
super
|
||||
classes.each do |klass|
|
||||
descendants.each do |descendant|
|
||||
descendant.send(:include, klass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,74 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/notifying_block'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Author:: Lamont Granquist <lamont@chef.io>
|
||||
# Copyright:: Copyright 2010-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module NotifyingBlock
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::NotifyingBlock, self) if defined?(::Chef::Mixin::NotifyingBlock)
|
||||
|
||||
def notifying_block(&block)
|
||||
begin
|
||||
subcontext = subcontext_block(&block)
|
||||
Chef::Runner.new(subcontext).converge
|
||||
ensure
|
||||
# recipes don't have a new_resource
|
||||
if respond_to?(:new_resource)
|
||||
if subcontext && subcontext.resource_collection.any?(&:updated?)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def subcontext_block(parent_context = nil, &block)
|
||||
parent_context ||= @run_context
|
||||
sub_run_context = parent_context.create_child
|
||||
|
||||
begin
|
||||
outer_run_context = @run_context
|
||||
@run_context = sub_run_context
|
||||
instance_eval(&block)
|
||||
ensure
|
||||
@run_context = outer_run_context
|
||||
end
|
||||
|
||||
sub_run_context
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,510 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/params_validate'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Adam Jacob (<adam@chef.io>)
|
||||
# Copyright:: Copyright 2008-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/constants"
|
||||
require "chef_compat/copied_from_chef/chef/property"
|
||||
require "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module ParamsValidate
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::ParamsValidate, self) if defined?(::Chef::Mixin::ParamsValidate)
|
||||
# Takes a hash of options, along with a map to validate them. Returns the original
|
||||
# options hash, plus any changes that might have been made (through things like setting
|
||||
# default values in the validation map)
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# validate({ :one => "neat" }, { :one => { :kind_of => String }})
|
||||
#
|
||||
# Would raise an exception if the value of :one above is not a kind_of? string. Valid
|
||||
# map options are:
|
||||
#
|
||||
# @param opts [Hash<Symbol,Object>] Validation opts.
|
||||
# @option opts [Object,Array] :is An object, or list of
|
||||
# objects, that must match the value using Ruby's `===` operator
|
||||
# (`opts[:is].any? { |v| v === value }`). (See #_pv_is.)
|
||||
# @option opts [Object,Array] :equal_to An object, or list
|
||||
# of objects, that must be equal to the value using Ruby's `==`
|
||||
# operator (`opts[:is].any? { |v| v == value }`) (See #_pv_equal_to.)
|
||||
# @option opts [Regexp,Array<Regexp>] :regex An object, or
|
||||
# list of objects, that must match the value with `regex.match(value)`.
|
||||
# (See #_pv_regex)
|
||||
# @option opts [Class,Array<Class>] :kind_of A class, or
|
||||
# list of classes, that the value must be an instance of. (See
|
||||
# #_pv_kind_of.)
|
||||
# @option opts [Hash<String,Proc>] :callbacks A hash of
|
||||
# messages -> procs, all of which match the value. The proc must
|
||||
# return a truthy or falsey value (true means it matches). (See
|
||||
# #_pv_callbacks.)
|
||||
# @option opts [Symbol,Array<Symbol>] :respond_to A method
|
||||
# name, or list of method names, the value must respond to. (See
|
||||
# #_pv_respond_to.)
|
||||
# @option opts [Symbol,Array<Symbol>] :cannot_be A property,
|
||||
# or a list of properties, that the value cannot have (such as `:nil` or
|
||||
# `:empty`). The method with a questionmark at the end is called on the
|
||||
# value (e.g. `value.empty?`). If the value does not have this method,
|
||||
# it is considered valid (i.e. if you don't respond to `empty?` we
|
||||
# assume you are not empty). (See #_pv_cannot_be.)
|
||||
# @option opts [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# (See #_pv_coerce.) (See #_pv_coerce.)
|
||||
# @option opts [Boolean] :required `true` if this property
|
||||
# must be present and not `nil`; `false` otherwise. This is checked
|
||||
# after the resource is fully initialized. (See #_pv_required.)
|
||||
# @option opts [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set. (See
|
||||
# #_pv_name_property.)
|
||||
# @option opts [Boolean] :name_attribute Same as `name_property`.
|
||||
# @option opts [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties). (See #_pv_default.)
|
||||
#
|
||||
def validate(opts, map)
|
||||
map = map.validation_options if map.is_a?(Property)
|
||||
|
||||
#--
|
||||
# validate works by taking the keys in the validation map, assuming it's a hash, and
|
||||
# looking for _pv_:symbol as methods. Assuming it find them, it calls the right
|
||||
# one.
|
||||
#++
|
||||
raise ArgumentError, "Options must be a hash" unless opts.kind_of?(Hash)
|
||||
raise ArgumentError, "Validation Map must be a hash" unless map.kind_of?(Hash)
|
||||
|
||||
map.each do |key, validation|
|
||||
unless key.kind_of?(Symbol) || key.kind_of?(String)
|
||||
raise ArgumentError, "Validation map keys must be symbols or strings!"
|
||||
end
|
||||
case validation
|
||||
when true
|
||||
_pv_required(opts, key)
|
||||
when false
|
||||
true
|
||||
when Hash
|
||||
validation.each do |check, carg|
|
||||
check_method = "_pv_#{check}"
|
||||
if self.respond_to?(check_method, true)
|
||||
self.send(check_method, opts, key, carg)
|
||||
else
|
||||
raise ArgumentError, "Validation map has unknown check: #{check}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
opts
|
||||
end
|
||||
|
||||
def lazy(&block)
|
||||
DelayedEvaluator.new(&block)
|
||||
end
|
||||
|
||||
def set_or_return(symbol, value, validation)
|
||||
property = SetOrReturnProperty.new(name: symbol, **validation)
|
||||
property.call(self, value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def explicitly_allows_nil?(key, validation)
|
||||
validation.has_key?(:is) && _pv_is({ key => nil }, key, validation[:is], raise_error: false)
|
||||
end
|
||||
|
||||
# Return the value of a parameter, or nil if it doesn't exist.
|
||||
def _pv_opts_lookup(opts, key)
|
||||
if opts.has_key?(key.to_s)
|
||||
opts[key.to_s]
|
||||
elsif opts.has_key?(key.to_sym)
|
||||
opts[key.to_sym]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# Raise an exception if the parameter is not found.
|
||||
def _pv_required(opts, key, is_required = true, explicitly_allows_nil = false)
|
||||
if is_required
|
||||
return true if opts.has_key?(key.to_s) && (explicitly_allows_nil || !opts[key.to_s].nil?)
|
||||
return true if opts.has_key?(key.to_sym) && (explicitly_allows_nil || !opts[key.to_sym].nil?)
|
||||
raise Exceptions::ValidationFailed, "Required argument #{key.inspect} is missing!"
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# List of things values must be equal to.
|
||||
#
|
||||
# Uses Ruby's `==` to evaluate (equal_to == value). At least one must
|
||||
# match for the value to be valid.
|
||||
#
|
||||
# `nil` passes this validation automatically.
|
||||
#
|
||||
# @return [Array,nil] List of things values must be equal to, or nil if
|
||||
# equal_to is unspecified.
|
||||
#
|
||||
def _pv_equal_to(opts, key, to_be)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
to_be = Array(to_be)
|
||||
to_be.each do |tb|
|
||||
return true if value == tb
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of things values must be instances of.
|
||||
#
|
||||
# Uses value.kind_of?(kind_of) to evaluate. At least one must match for
|
||||
# the value to be valid.
|
||||
#
|
||||
# `nil` automatically passes this validation.
|
||||
#
|
||||
def _pv_kind_of(opts, key, to_be)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
to_be = Array(to_be)
|
||||
to_be.each do |tb|
|
||||
return true if value.kind_of?(tb)
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of method names values must respond to.
|
||||
#
|
||||
# Uses value.respond_to?(respond_to) to evaluate. At least one must match
|
||||
# for the value to be valid.
|
||||
#
|
||||
def _pv_respond_to(opts, key, method_name_list)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
unless value.nil?
|
||||
Array(method_name_list).each do |method_name|
|
||||
unless value.respond_to?(method_name)
|
||||
raise Exceptions::ValidationFailed, "Option #{key} must have a #{method_name} method!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of things that must not be true about the value.
|
||||
#
|
||||
# Calls `value.<thing>?` All responses must be false for the value to be
|
||||
# valid.
|
||||
# Values which do not respond to <thing>? are considered valid (because if
|
||||
# a value doesn't respond to `:readable?`, then it probably isn't
|
||||
# readable.)
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, cannot_be: [ :nil, :empty ]
|
||||
# x [ 1, 2 ] #=> valid
|
||||
# x 1 #=> valid
|
||||
# x [] #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
def _pv_cannot_be(opts, key, predicate_method_base_name)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
Array(predicate_method_base_name).each do |method_name|
|
||||
predicate_method = :"#{method_name}?"
|
||||
|
||||
if value.respond_to?(predicate_method)
|
||||
if value.send(predicate_method)
|
||||
raise Exceptions::ValidationFailed, "Option #{key} cannot be #{predicate_method_base_name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The default value for a property.
|
||||
#
|
||||
# When the property is not assigned, this will be used.
|
||||
#
|
||||
# If this is a lazy value, it will either be passed the resource as a value,
|
||||
# or if the lazy proc does not take parameters, it will be run in the
|
||||
# context of the instance with instance_eval.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, default: 10
|
||||
# ```
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x
|
||||
# property :y, default: lazy { x+2 }
|
||||
# ```
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x
|
||||
# property :y, default: lazy { |r| r.x+2 }
|
||||
# ```
|
||||
#
|
||||
def _pv_default(opts, key, default_value)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if value.nil?
|
||||
default_value = default_value.freeze if !default_value.is_a?(DelayedEvaluator)
|
||||
opts[key] = default_value
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of regexes values that must match.
|
||||
#
|
||||
# Uses regex.match() to evaluate. At least one must match for the value to
|
||||
# be valid.
|
||||
#
|
||||
# `nil` passes regex validation automatically.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, regex: [ /abc/, /xyz/ ]
|
||||
# ```
|
||||
#
|
||||
def _pv_regex(opts, key, regex)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
Array(regex).flatten.each do |r|
|
||||
return true if r.match(value.to_s)
|
||||
end
|
||||
raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# List of procs we pass the value to.
|
||||
#
|
||||
# All procs must return true for the value to be valid. If any procs do
|
||||
# not return true, the key will be used for the message: `"Property x's
|
||||
# value :y <message>"`.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, callbacks: { "is bigger than 10" => proc { |v| v <= 10 }, "is not awesome" => proc { |v| !v.awesome }}
|
||||
# ```
|
||||
#
|
||||
def _pv_callbacks(opts, key, callbacks)
|
||||
raise ArgumentError, "Callback list must be a hash!" unless callbacks.kind_of?(Hash)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
if !value.nil?
|
||||
callbacks.each do |message, zeproc|
|
||||
unless zeproc.call(value)
|
||||
raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} #{message}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Allows a parameter to default to the value of the resource name.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, name_property: true
|
||||
# ```
|
||||
#
|
||||
def _pv_name_property(opts, key, is_name_property = true)
|
||||
if is_name_property
|
||||
if opts[key].nil?
|
||||
raise CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key] = self.instance_variable_get(:"@name")
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :_pv_name_attribute :_pv_name_property
|
||||
|
||||
#
|
||||
# List of valid things values can be.
|
||||
#
|
||||
# Uses Ruby's `===` to evaluate (is === value). At least one must match
|
||||
# for the value to be valid.
|
||||
#
|
||||
# If a proc is passed, it is instance_eval'd in the resource, passed the
|
||||
# value, and must return a truthy or falsey value.
|
||||
#
|
||||
# @example Class
|
||||
# ```ruby
|
||||
# property :x, String
|
||||
# x 'valid' #=> valid
|
||||
# x 1 #=> invalid
|
||||
# x nil #=> invalid
|
||||
#
|
||||
# @example Value
|
||||
# ```ruby
|
||||
# property :x, [ :a, :b, :c, nil ]
|
||||
# x :a #=> valid
|
||||
# x nil #=> valid
|
||||
# ```
|
||||
#
|
||||
# @example Regex
|
||||
# ```ruby
|
||||
# property :x, /bar/
|
||||
# x 'foobar' #=> valid
|
||||
# x 'foo' #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example Proc
|
||||
# ```ruby
|
||||
# property :x, proc { |x| x > y }
|
||||
# property :y, default: 2
|
||||
# x 3 #=> valid
|
||||
# x 1 #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example Property
|
||||
# ```ruby
|
||||
# type = Property.new(is: String)
|
||||
# property :x, type
|
||||
# x 'foo' #=> valid
|
||||
# x 1 #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
# @example RSpec Matcher
|
||||
# ```ruby
|
||||
# include RSpec::Matchers
|
||||
# property :x, a_string_matching /bar/
|
||||
# x 'foobar' #=> valid
|
||||
# x 'foo' #=> invalid
|
||||
# x nil #=> invalid
|
||||
# ```
|
||||
#
|
||||
def _pv_is(opts, key, to_be, raise_error: true)
|
||||
return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym)
|
||||
value = _pv_opts_lookup(opts, key)
|
||||
to_be = [ to_be ].flatten(1)
|
||||
errors = []
|
||||
passed = to_be.any? do |tb|
|
||||
case tb
|
||||
when Proc
|
||||
raise CannotValidateStaticallyError, "is: proc { } must be evaluated once for each resource" if self == Chef::Mixin::ParamsValidate
|
||||
instance_exec(value, &tb)
|
||||
when Property
|
||||
begin
|
||||
validate(opts, { key => tb.validation_options })
|
||||
true
|
||||
rescue Exceptions::ValidationFailed
|
||||
# re-raise immediately if there is only one "is" so we get a better stack
|
||||
raise if to_be.size == 1
|
||||
errors << $!
|
||||
false
|
||||
end
|
||||
else
|
||||
tb === value
|
||||
end
|
||||
end
|
||||
if passed
|
||||
true
|
||||
else
|
||||
message = "Property #{key} must be one of: #{to_be.map { |v| v.inspect }.join(", ")}! You passed #{value.inspect}."
|
||||
unless errors.empty?
|
||||
message << " Errors:\n#{errors.map { |m| "- #{m}" }.join("\n")}"
|
||||
end
|
||||
raise Exceptions::ValidationFailed, message
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Method to mess with a value before it is validated and stored.
|
||||
#
|
||||
# Allows you to transform values into a canonical form that is easy to
|
||||
# work with.
|
||||
#
|
||||
# This is passed the value to transform, and is run in the context of the
|
||||
# instance (so it has access to other resource properties). It must return
|
||||
# the value that will be stored in the instance.
|
||||
#
|
||||
# @example
|
||||
# ```ruby
|
||||
# property :x, Integer, coerce: { |v| v.to_i }
|
||||
# ```
|
||||
#
|
||||
def _pv_coerce(opts, key, coercer)
|
||||
if opts.has_key?(key.to_s)
|
||||
raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key.to_s] = instance_exec(opts[key], &coercer)
|
||||
elsif opts.has_key?(key.to_sym)
|
||||
raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
|
||||
opts[key.to_sym] = instance_exec(opts[key], &coercer)
|
||||
end
|
||||
end
|
||||
|
||||
# We allow Chef::Mixin::ParamsValidate.validate(), but we will raise an
|
||||
# error if you try to do anything requiring there to be an actual resource.
|
||||
# This way, you can statically validate things if you have constant validation
|
||||
# (which is the norm).
|
||||
extend self
|
||||
|
||||
# Used by #set_or_return to avoid emitting a deprecation warning for
|
||||
# "value nil" and to keep default stickiness working exactly the same
|
||||
# @api private
|
||||
class SetOrReturnProperty < (defined?(::Chef::Mixin::ParamsValidate::SetOrReturnProperty) ? ::Chef::Mixin::ParamsValidate::SetOrReturnProperty : Chef::Property)
|
||||
def get(resource, nil_set: false)
|
||||
value = super
|
||||
# All values are sticky, frozen or not
|
||||
if !is_set?(resource)
|
||||
set_value(resource, value)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
def call(resource, value = NOT_PASSED)
|
||||
# setting to nil does a get
|
||||
if value.nil? && !explicitly_accepts_nil?(resource)
|
||||
get(resource, nil_set: true)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,117 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/powershell_out'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#--
|
||||
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module PowershellOut
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::PowershellOut, self) if defined?(::Chef::Mixin::PowershellOut)
|
||||
include Chef::Mixin::ShellOut
|
||||
include Chef::Mixin::WindowsArchitectureHelper
|
||||
|
||||
# Run a command under powershell with the same API as shell_out. The
|
||||
# options hash is extended to take an "architecture" flag which
|
||||
# can be set to :i386 or :x86_64 to force the windows architecture.
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def powershell_out(*command_args)
|
||||
script = command_args.first
|
||||
options = command_args.last.is_a?(Hash) ? command_args.last : nil
|
||||
|
||||
run_command_with_os_architecture(script, options)
|
||||
end
|
||||
|
||||
# Run a command under powershell with the same API as shell_out!
|
||||
# (raises exceptions on errors)
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def powershell_out!(*command_args)
|
||||
cmd = powershell_out(*command_args)
|
||||
cmd.error!
|
||||
cmd
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Helper function to run shell_out and wrap it with the correct
|
||||
# flags to possibly disable WOW64 redirection (which we often need
|
||||
# because chef-client runs as a 32-bit app on 64-bit windows).
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @param options [Hash] options hash
|
||||
# @return [Mixlib::Shellout] mixlib-shellout object
|
||||
def run_command_with_os_architecture(script, options)
|
||||
options ||= {}
|
||||
options = options.dup
|
||||
arch = options.delete(:architecture)
|
||||
|
||||
with_os_architecture(nil, architecture: arch) do
|
||||
shell_out(
|
||||
build_powershell_command(script),
|
||||
options
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# Helper to build a powershell command around the script to run.
|
||||
#
|
||||
# @param script [String] script to run
|
||||
# @retrurn [String] powershell command to execute
|
||||
def build_powershell_command(script)
|
||||
flags = [
|
||||
# Hides the copyright banner at startup.
|
||||
"-NoLogo",
|
||||
# Does not present an interactive prompt to the user.
|
||||
"-NonInteractive",
|
||||
# Does not load the Windows PowerShell profile.
|
||||
"-NoProfile",
|
||||
# always set the ExecutionPolicy flag
|
||||
# see http://technet.microsoft.com/en-us/library/ee176961.aspx
|
||||
"-ExecutionPolicy Unrestricted",
|
||||
# Powershell will hang if STDIN is redirected
|
||||
# http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
|
||||
"-InputFormat None",
|
||||
]
|
||||
|
||||
"powershell.exe #{flags.join(' ')} -Command \"#{script.gsub('"', '\"')}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,328 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/mixin/properties'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/params_validate"
|
||||
require "chef_compat/copied_from_chef/chef/property"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
module Mixin
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin)
|
||||
module Properties
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties, self) if defined?(::Chef::Mixin::Properties)
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties::ClassMethods, self) if defined?(::Chef::Mixin::Properties::ClassMethods)
|
||||
#
|
||||
# The list of properties defined on this resource.
|
||||
#
|
||||
# Everything defined with `property` is in this list.
|
||||
#
|
||||
# @param include_superclass [Boolean] `true` to include properties defined
|
||||
# on superclasses; `false` or `nil` to return the list of properties
|
||||
# directly on this class.
|
||||
#
|
||||
# @return [Hash<Symbol,Property>] The list of property names and types.
|
||||
#
|
||||
def properties(include_superclass = true)
|
||||
if include_superclass
|
||||
result = {}
|
||||
ancestors.reverse_each { |c| result.merge!(c.properties(false)) if c.respond_to?(:properties) }
|
||||
result
|
||||
else
|
||||
@properties ||= {}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Create a property on this resource class.
|
||||
#
|
||||
# If a superclass has this property, or if this property has already been
|
||||
# defined by this resource, this will *override* the previous value.
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
# @param type [Object,Array<Object>] The type(s) of this property.
|
||||
# If present, this is prepended to the `is` validation option.
|
||||
# @param options [Hash<Symbol,Object>] Validation options.
|
||||
# @option options [Object,Array] :is An object, or list of
|
||||
# objects, that must match the value using Ruby's `===` operator
|
||||
# (`options[:is].any? { |v| v === value }`).
|
||||
# @option options [Object,Array] :equal_to An object, or list
|
||||
# of objects, that must be equal to the value using Ruby's `==`
|
||||
# operator (`options[:is].any? { |v| v == value }`)
|
||||
# @option options [Regexp,Array<Regexp>] :regex An object, or
|
||||
# list of objects, that must match the value with `regex.match(value)`.
|
||||
# @option options [Class,Array<Class>] :kind_of A class, or
|
||||
# list of classes, that the value must be an instance of.
|
||||
# @option options [Hash<String,Proc>] :callbacks A hash of
|
||||
# messages -> procs, all of which match the value. The proc must
|
||||
# return a truthy or falsey value (true means it matches).
|
||||
# @option options [Symbol,Array<Symbol>] :respond_to A method
|
||||
# name, or list of method names, the value must respond to.
|
||||
# @option options [Symbol,Array<Symbol>] :cannot_be A property,
|
||||
# or a list of properties, that the value cannot have (such as `:nil` or
|
||||
# `:empty`). The method with a questionmark at the end is called on the
|
||||
# value (e.g. `value.empty?`). If the value does not have this method,
|
||||
# it is considered valid (i.e. if you don't respond to `empty?` we
|
||||
# assume you are not empty).
|
||||
# @option options [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# @option options [Boolean] :required `true` if this property
|
||||
# must be present; `false` otherwise. This is checked after the resource
|
||||
# is fully initialized.
|
||||
# @option options [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set.
|
||||
# @option options [Boolean] :name_attribute Same as `name_property`.
|
||||
# @option options [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties).
|
||||
# @option options [Boolean] :desired_state `true` if this property is
|
||||
# part of desired state. Defaults to `true`.
|
||||
# @option options [Boolean] :identity `true` if this property
|
||||
# is part of object identity. Defaults to `false`.
|
||||
# @option options [Boolean] :sensitive `true` if this property could
|
||||
# contain sensitive information and whose value should be redacted
|
||||
# in any resource reporting / auditing output. Defaults to `false`.
|
||||
#
|
||||
# @example Bare property
|
||||
# property :x
|
||||
#
|
||||
# @example With just a type
|
||||
# property :x, String
|
||||
#
|
||||
# @example With just options
|
||||
# property :x, default: 'hi'
|
||||
#
|
||||
# @example With type and options
|
||||
# property :x, String, default: 'hi'
|
||||
#
|
||||
def property(name, type = NOT_PASSED, **options)
|
||||
name = name.to_sym
|
||||
|
||||
options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo }
|
||||
|
||||
options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
|
||||
options[:name] = name
|
||||
options[:declared_in] = self
|
||||
|
||||
if type == NOT_PASSED
|
||||
# If a type is not passed, the property derives from the
|
||||
# superclass property (if any)
|
||||
if properties.has_key?(name)
|
||||
property = properties[name].derive(**options)
|
||||
else
|
||||
property = property_type(**options)
|
||||
end
|
||||
|
||||
# If a Property is specified, derive a new one from that.
|
||||
elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property)
|
||||
property = type.derive(**options)
|
||||
|
||||
# If a primitive type was passed, combine it with "is"
|
||||
else
|
||||
if options[:is]
|
||||
options[:is] = ([ type ] + [ options[:is] ]).flatten(1)
|
||||
else
|
||||
options[:is] = type
|
||||
end
|
||||
property = property_type(**options)
|
||||
end
|
||||
|
||||
local_properties = properties(false)
|
||||
local_properties[name] = property
|
||||
|
||||
property.emit_dsl
|
||||
end
|
||||
|
||||
#
|
||||
# Create a reusable property type that can be used in multiple properties
|
||||
# in different resources.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Validation options. see #property for
|
||||
# the list of options.
|
||||
#
|
||||
# @example
|
||||
# property_type(default: 'hi')
|
||||
#
|
||||
def property_type(**options)
|
||||
Property.derive(**options)
|
||||
end
|
||||
|
||||
#
|
||||
# Create a lazy value for assignment to a default value.
|
||||
#
|
||||
# @param block The block to run when the value is retrieved.
|
||||
#
|
||||
# @return [Chef::DelayedEvaluator] The lazy value
|
||||
#
|
||||
def lazy(&block)
|
||||
DelayedEvaluator.new(&block)
|
||||
end
|
||||
|
||||
#
|
||||
# Get or set the list of desired state properties for this resource.
|
||||
#
|
||||
# State properties are properties that describe the desired state
|
||||
# of the system, such as file permissions or ownership.
|
||||
# In general, state properties are properties that could be populated by
|
||||
# examining the state of the system (e.g., File.stat can tell you the
|
||||
# permissions on an existing file). Contrarily, properties that are not
|
||||
# "state properties" usually modify the way Chef itself behaves, for example
|
||||
# by providing additional options for a package manager to use when
|
||||
# installing a package.
|
||||
#
|
||||
# This list is used by the Chef client auditing system to extract
|
||||
# information from resources to describe changes made to the system.
|
||||
#
|
||||
# This method is unnecessary when declaring properties with `property`;
|
||||
# properties are added to state_properties by default, and can be turned off
|
||||
# with `desired_state: false`.
|
||||
#
|
||||
# ```ruby
|
||||
# property :x # part of desired state
|
||||
# property :y, desired_state: false # not part of desired state
|
||||
# ```
|
||||
#
|
||||
# @param names [Array<Symbol>] A list of property names to set as desired
|
||||
# state.
|
||||
#
|
||||
# @return [Array<Property>] All properties in desired state.
|
||||
#
|
||||
def state_properties(*names)
|
||||
if !names.empty?
|
||||
names = names.map { |name| name.to_sym }.uniq
|
||||
|
||||
local_properties = properties(false)
|
||||
# Add new properties to the list.
|
||||
names.each do |name|
|
||||
property = properties[name]
|
||||
if !property
|
||||
self.property name, instance_variable_name: false, desired_state: true
|
||||
elsif !property.desired_state?
|
||||
self.property name, desired_state: true
|
||||
end
|
||||
end
|
||||
|
||||
# If state_attrs *excludes* something which is currently desired state,
|
||||
# mark it as desired_state: false.
|
||||
local_properties.each do |name, property|
|
||||
if property.desired_state? && !names.include?(name)
|
||||
self.property name, desired_state: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
properties.values.select { |property| property.desired_state? }
|
||||
end
|
||||
|
||||
#
|
||||
# Set the identity of this resource to a particular set of properties.
|
||||
#
|
||||
# This drives #identity, which returns data that uniquely refers to a given
|
||||
# resource on the given node (in such a way that it can be correlated
|
||||
# across Chef runs).
|
||||
#
|
||||
# This method is unnecessary when declaring properties with `property`;
|
||||
# properties can be added to identity during declaration with
|
||||
# `identity: true`.
|
||||
#
|
||||
# ```ruby
|
||||
# property :x, identity: true # part of identity
|
||||
# property :y # not part of identity
|
||||
# ```
|
||||
#
|
||||
# If no properties are marked as identity, "name" is considered the identity.
|
||||
#
|
||||
# @param names [Array<Symbol>] A list of property names to set as the identity.
|
||||
#
|
||||
# @return [Array<Property>] All identity properties.
|
||||
#
|
||||
def identity_properties(*names)
|
||||
if !names.empty?
|
||||
names = names.map { |name| name.to_sym }
|
||||
|
||||
# Add or change properties that are not part of the identity.
|
||||
names.each do |name|
|
||||
property = properties[name]
|
||||
if !property
|
||||
self.property name, instance_variable_name: false, identity: true
|
||||
elsif !property.identity?
|
||||
self.property name, identity: true
|
||||
end
|
||||
end
|
||||
|
||||
# If identity_properties *excludes* something which is currently part of
|
||||
# the identity, mark it as identity: false.
|
||||
properties.each do |name, property|
|
||||
if property.identity? && !names.include?(name)
|
||||
|
||||
self.property name, identity: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = properties.values.select { |property| property.identity? }
|
||||
result = [ properties[:name] ] if result.empty?
|
||||
result
|
||||
end
|
||||
|
||||
def included(other)
|
||||
other.extend ClassMethods
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(other)
|
||||
other.extend ClassMethods
|
||||
end
|
||||
|
||||
include Chef::Mixin::ParamsValidate
|
||||
|
||||
#
|
||||
# Whether this property has been set (or whether it has a default that has
|
||||
# been retrieved).
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
# @return [Boolean] `true` if the property has been set.
|
||||
#
|
||||
def property_is_set?(name)
|
||||
property = self.class.properties[name.to_sym]
|
||||
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
||||
property.is_set?(self)
|
||||
end
|
||||
|
||||
#
|
||||
# Clear this property as if it had never been set. It will thereafter return
|
||||
# the default.
|
||||
# been retrieved).
|
||||
#
|
||||
# @param name [Symbol] The name of the property.
|
||||
#
|
||||
def reset_property(name)
|
||||
property = self.class.properties[name.to_sym]
|
||||
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
||||
property.reset(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,713 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/property'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser <jkeiser@chef.io>
|
||||
# Copyright:: Copyright 2015-2016, John Keiser.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/delayed_evaluator"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
#
|
||||
# Type and validation information for a property on a resource.
|
||||
#
|
||||
# A property named "x" manipulates the "@x" instance variable on a
|
||||
# resource. The *presence* of the variable (`instance_variable_defined?(@x)`)
|
||||
# tells whether the variable is defined; it may have any actual value,
|
||||
# constrained only by validation.
|
||||
#
|
||||
# Properties may have validation, defaults, and coercion, and have full
|
||||
# support for lazy values.
|
||||
#
|
||||
# @see Chef::Resource.property
|
||||
# @see Chef::DelayedEvaluator
|
||||
#
|
||||
class Property < (defined?(::Chef::Property) ? ::Chef::Property : Object)
|
||||
#
|
||||
# Create a reusable property type that can be used in multiple properties
|
||||
# in different resources.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Validation options. See Chef::Resource.property for
|
||||
# the list of options.
|
||||
#
|
||||
# @example
|
||||
# Property.derive(default: 'hi')
|
||||
#
|
||||
def self.derive(**options)
|
||||
new(**options)
|
||||
end
|
||||
|
||||
#
|
||||
# Create a new property.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] Property options, including
|
||||
# control options here, as well as validation options (see
|
||||
# Chef::Mixin::ParamsValidate#validate for a description of validation
|
||||
# options).
|
||||
# @option options [Symbol] :name The name of this property.
|
||||
# @option options [Class] :declared_in The class this property comes from.
|
||||
# @option options [Symbol] :instance_variable_name The instance variable
|
||||
# tied to this property. Must include a leading `@`. Defaults to `@<name>`.
|
||||
# `nil` means the property is opaque and not tied to a specific instance
|
||||
# variable.
|
||||
# @option options [Boolean] :desired_state `true` if this property is part of desired
|
||||
# state. Defaults to `true`.
|
||||
# @option options [Boolean] :identity `true` if this property is part of object
|
||||
# identity. Defaults to `false`.
|
||||
# @option options [Boolean] :name_property `true` if this
|
||||
# property defaults to the same value as `name`. Equivalent to
|
||||
# `default: lazy { name }`, except that #property_is_set? will
|
||||
# return `true` if the property is set *or* if `name` is set.
|
||||
# @option options [Boolean] :nillable `true` opt-in to Chef-13 style behavior where
|
||||
# attempting to set a nil value will really set a nil value instead of issuing
|
||||
# a warning and operating like a getter
|
||||
# @option options [Object] :default The value this property
|
||||
# will return if the user does not set one. If this is `lazy`, it will
|
||||
# be run in the context of the instance (and able to access other
|
||||
# properties) and cached. If not, the value will be frozen with Object#freeze
|
||||
# to prevent users from modifying it in an instance.
|
||||
# @option options [Proc] :coerce A proc which will be called to
|
||||
# transform the user input to canonical form. The value is passed in,
|
||||
# and the transformed value returned as output. Lazy values will *not*
|
||||
# be passed to this method until after they are evaluated. Called in the
|
||||
# context of the resource (meaning you can access other properties).
|
||||
# @option options [Boolean] :required `true` if this property
|
||||
# must be present; `false` otherwise. This is checked after the resource
|
||||
# is fully initialized.
|
||||
#
|
||||
def initialize(**options)
|
||||
super if defined?(::Chef::Property)
|
||||
options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo }
|
||||
@options = options
|
||||
options[:name] = options[:name].to_sym if options[:name]
|
||||
options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name]
|
||||
|
||||
# Replace name_attribute with name_property
|
||||
if options.has_key?(:name_attribute)
|
||||
# If we have both name_attribute and name_property and they differ, raise an error
|
||||
if options.has_key?(:name_property)
|
||||
raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{self}."
|
||||
end
|
||||
# replace name_property with name_attribute in place
|
||||
options = Hash[options.map { |k, v| k == :name_attribute ? [ :name_property, v ] : [ k, v ] }]
|
||||
@options = options
|
||||
end
|
||||
|
||||
# Only pick the first of :default, :name_property and :name_attribute if
|
||||
# more than one is specified.
|
||||
if options.has_key?(:default) && options[:name_property]
|
||||
if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default)
|
||||
options.delete(:default)
|
||||
preferred_default = :name_property
|
||||
else
|
||||
options.delete(:name_property)
|
||||
preferred_default = :default
|
||||
end
|
||||
Chef.log_deprecation("Cannot specify both default and name_property together on property #{self}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property.")
|
||||
end
|
||||
|
||||
# Validate the default early, so the user gets a good error message, and
|
||||
# cache it so we don't do it again if so
|
||||
begin
|
||||
# If we can validate it all the way to output, do it.
|
||||
@stored_default = input_to_stored_value(nil, default, is_default: true)
|
||||
rescue Chef::Exceptions::CannotValidateStaticallyError
|
||||
# If the validation is not static (i.e. has procs), we will have to
|
||||
# coerce and validate the default each time we run
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{name || "<property type>"}#{declared_in ? " of resource #{declared_in.resource_name}" : ""}"
|
||||
end
|
||||
|
||||
#
|
||||
# The name of this property.
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
def name
|
||||
options[:name]
|
||||
end
|
||||
|
||||
#
|
||||
# The class this property was defined in.
|
||||
#
|
||||
# @return [Class]
|
||||
#
|
||||
def declared_in
|
||||
options[:declared_in]
|
||||
end
|
||||
|
||||
#
|
||||
# The instance variable associated with this property.
|
||||
#
|
||||
# Defaults to `@<name>`
|
||||
#
|
||||
# @return [Symbol]
|
||||
#
|
||||
def instance_variable_name
|
||||
if options.has_key?(:instance_variable_name)
|
||||
options[:instance_variable_name]
|
||||
elsif name
|
||||
:"@#{name}"
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The raw default value for this resource.
|
||||
#
|
||||
# Does not coerce or validate the default. Does not evaluate lazy values.
|
||||
#
|
||||
# Defaults to `lazy { name }` if name_property is true; otherwise defaults to
|
||||
# `nil`
|
||||
#
|
||||
def default
|
||||
return options[:default] if options.has_key?(:default)
|
||||
return Chef::DelayedEvaluator.new { name } if name_property?
|
||||
nil
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is part of the resource's natural identity or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def identity?
|
||||
options[:identity]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is part of desired state or not.
|
||||
#
|
||||
# Defaults to true.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def desired_state?
|
||||
return true if !options.has_key?(:desired_state)
|
||||
options[:desired_state]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this is name_property or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def name_property?
|
||||
options[:name_property]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property has a default value.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def has_default?
|
||||
options.has_key?(:default) || name_property?
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property is required or not.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def required?
|
||||
options[:required]
|
||||
end
|
||||
|
||||
#
|
||||
# Whether this property is sensitive or not.
|
||||
#
|
||||
# Defaults to false.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def sensitive?
|
||||
options.fetch(:sensitive, false)
|
||||
end
|
||||
|
||||
#
|
||||
# Validation options. (See Chef::Mixin::ParamsValidate#validate.)
|
||||
#
|
||||
# @return [Hash<Symbol,Object>]
|
||||
#
|
||||
def validation_options
|
||||
@validation_options ||= options.reject do |k, v|
|
||||
[:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable, :sensitive].include?(k)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Handle the property being called.
|
||||
#
|
||||
# The base implementation does the property get-or-set:
|
||||
#
|
||||
# ```ruby
|
||||
# resource.myprop # get
|
||||
# resource.myprop value # set
|
||||
# ```
|
||||
#
|
||||
# Subclasses may implement this with any arguments they want, as long as
|
||||
# the corresponding DSL calls it correctly.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
# @param value The value to set (or NOT_PASSED if it is a get).
|
||||
#
|
||||
# @return The current value of the property. If it is a `set`, lazy values
|
||||
# will be returned without running, validating or coercing. If it is a
|
||||
# `get`, the non-lazy, coerced, validated value will always be returned.
|
||||
#
|
||||
def call(resource, value = NOT_PASSED)
|
||||
if value == NOT_PASSED
|
||||
return get(resource)
|
||||
end
|
||||
|
||||
if value.nil? && !nillable?
|
||||
# In Chef 12, value(nil) does a *get* instead of a set, so we
|
||||
# warn if the value would have been changed. In Chef 13, it will be
|
||||
# equivalent to value = nil.
|
||||
result = get(resource, nil_set: true)
|
||||
|
||||
# Warn about this becoming a set in Chef 13.
|
||||
begin
|
||||
input_to_stored_value(resource, value)
|
||||
# If nil is valid, and it would change the value, warn that this will change to a set.
|
||||
if !result.nil?
|
||||
Chef.log_deprecation("An attempt was made to change #{name} from #{result.inspect} to nil by calling #{name}(nil). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil.")
|
||||
end
|
||||
rescue Chef::Exceptions::DeprecatedFeatureError
|
||||
raise
|
||||
rescue
|
||||
# If nil is invalid, warn that this will become an error.
|
||||
Chef.log_deprecation("nil is an invalid value for #{self}. In Chef 13, this warning will change to an error. Error: #{$!}")
|
||||
end
|
||||
|
||||
result
|
||||
else
|
||||
# Anything else, such as myprop(value) is a set
|
||||
set(resource, value)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Get the property value from the resource, handling lazy values,
|
||||
# defaults, and validation.
|
||||
#
|
||||
# - If the property's value is lazy, it is evaluated, coerced and validated.
|
||||
# - If the property has no value, and is required, raises ValidationFailed.
|
||||
# - If the property has no value, but has a lazy default, it is evaluated,
|
||||
# coerced and validated. If the evaluated value is frozen, the resulting
|
||||
# - If the property has no value, but has a default, the default value
|
||||
# will be returned and frozen. If the default value is lazy, it will be
|
||||
# evaluated, coerced and validated, and the result stored in the property.
|
||||
# - If the property has no value, but is name_property, `resource.name`
|
||||
# is retrieved, coerced, validated and stored in the property.
|
||||
# - Otherwise, `nil` is returned.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
# @return The value of the property.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property, or if the value is required and not set.
|
||||
#
|
||||
def get(resource, nil_set: false)
|
||||
# If it's set, return it (and evaluate any lazy values)
|
||||
if is_set?(resource)
|
||||
value = get_value(resource)
|
||||
value = stored_value_to_output(resource, value)
|
||||
|
||||
else
|
||||
# We are getting the default value.
|
||||
|
||||
# If the user does something like this:
|
||||
#
|
||||
# ```
|
||||
# class MyResource < Chef::Resource
|
||||
# property :content
|
||||
# action :create do
|
||||
# file '/x.txt' do
|
||||
# content content
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# ```
|
||||
#
|
||||
# It won't do what they expect. This checks whether you try to *read*
|
||||
# `content` while we are compiling the resource.
|
||||
if !nil_set &&
|
||||
resource.respond_to?(:resource_initializing) &&
|
||||
resource.resource_initializing &&
|
||||
resource.respond_to?(:enclosing_provider) &&
|
||||
resource.enclosing_provider &&
|
||||
resource.enclosing_provider.new_resource &&
|
||||
resource.enclosing_provider.new_resource.respond_to?(name)
|
||||
Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
|
||||
end
|
||||
|
||||
if has_default?
|
||||
# If we were able to cache the stored_default, grab it.
|
||||
if defined?(@stored_default)
|
||||
value = @stored_default
|
||||
else
|
||||
# Otherwise, we have to validate it now.
|
||||
value = input_to_stored_value(resource, default, is_default: true)
|
||||
end
|
||||
value = stored_value_to_output(resource, value, is_default: true)
|
||||
|
||||
# If the value is mutable (non-frozen), we set it on the instance
|
||||
# so that people can mutate it. (All constant default values are
|
||||
# frozen.)
|
||||
if !value.frozen? && !value.nil?
|
||||
set_value(resource, value)
|
||||
end
|
||||
|
||||
value
|
||||
|
||||
elsif required?
|
||||
raise Chef::Exceptions::ValidationFailed, "#{name} is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Set the value of this property in the given resource.
|
||||
#
|
||||
# Non-lazy values are coerced and validated before being set. Coercion
|
||||
# and validation of lazy values is delayed until they are first retrieved.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to set this property in.
|
||||
# @param value The value to set.
|
||||
#
|
||||
# @return The value that was set, after coercion (if lazy, still returns
|
||||
# the lazy value)
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def set(resource, value)
|
||||
set_value(resource, input_to_stored_value(resource, value))
|
||||
end
|
||||
|
||||
#
|
||||
# Find out whether this property has been set.
|
||||
#
|
||||
# This will be true if:
|
||||
# - The user explicitly set the value
|
||||
# - The property has a default, and the value was retrieved.
|
||||
#
|
||||
# From this point of view, it is worth looking at this as "what does the
|
||||
# user think this value should be." In order words, if the user grabbed
|
||||
# the value, even if it was a default, they probably based calculations on
|
||||
# it. If they based calculations on it and the value changes, the rest of
|
||||
# the world gets inconsistent.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def is_set?(resource)
|
||||
value_is_set?(resource)
|
||||
end
|
||||
|
||||
#
|
||||
# Reset the value of this property so that is_set? will return false and the
|
||||
# default will be returned in the future.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource to get the property from.
|
||||
#
|
||||
def reset(resource)
|
||||
reset_value(resource)
|
||||
end
|
||||
|
||||
#
|
||||
# Coerce an input value into canonical form for the property.
|
||||
#
|
||||
# After coercion, the value is suitable for storage in the resource.
|
||||
# You must validate values after coercion, however.
|
||||
#
|
||||
# Does no special handling for lazy values.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're coercing against
|
||||
# (to provide context for the coerce).
|
||||
# @param value The value to coerce.
|
||||
#
|
||||
# @return The coerced value.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def coerce(resource, value)
|
||||
if options.has_key?(:coerce)
|
||||
# If we have no default value, `nil` is never coerced or validated
|
||||
unless !has_default? && value.nil?
|
||||
value = exec_in_resource(resource, options[:coerce], value)
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
#
|
||||
# Validate a value.
|
||||
#
|
||||
# Calls Chef::Mixin::ParamsValidate#validate with #validation_options as
|
||||
# options.
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're validating against
|
||||
# (to provide context for the validate).
|
||||
# @param value The value to validate.
|
||||
#
|
||||
# @raise Chef::Exceptions::ValidationFailed If the value is invalid for
|
||||
# this property.
|
||||
#
|
||||
def validate(resource, value)
|
||||
# If we have no default value, `nil` is never coerced or validated
|
||||
unless value.nil? && !has_default?
|
||||
if resource
|
||||
resource.validate({ name => value }, { name => validation_options })
|
||||
else
|
||||
name = self.name || :property_type
|
||||
Chef::Mixin::ParamsValidate.validate({ name => value }, { name => validation_options })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Derive a new Property that is just like this one, except with some added or
|
||||
# changed options.
|
||||
#
|
||||
# @param options [Hash<Symbol,Object>] List of options that would be passed
|
||||
# to #initialize.
|
||||
#
|
||||
# @return [Property] The new property type.
|
||||
#
|
||||
def derive(**modified_options)
|
||||
# Since name_property, name_attribute and default override each other,
|
||||
# if you specify one of them in modified_options it overrides anything in
|
||||
# the original options.
|
||||
options = self.options
|
||||
if modified_options.has_key?(:name_property) ||
|
||||
modified_options.has_key?(:name_attribute) ||
|
||||
modified_options.has_key?(:default)
|
||||
options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default }
|
||||
end
|
||||
self.class.new(options.merge(modified_options))
|
||||
end
|
||||
|
||||
#
|
||||
# Emit the DSL for this property into the resource class (`declared_in`).
|
||||
#
|
||||
# Creates a getter and setter for the property.
|
||||
#
|
||||
def emit_dsl
|
||||
# We don't create the getter/setter if it's a custom property; we will
|
||||
# be using the existing getter/setter to manipulate it instead.
|
||||
return if !instance_variable_name
|
||||
|
||||
# We prefer this form because the property name won't show up in the
|
||||
# stack trace if you use `define_method`.
|
||||
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
||||
def #{name}(value=NOT_PASSED)
|
||||
raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given?
|
||||
self.class.properties[#{name.inspect}].call(self, value)
|
||||
end
|
||||
def #{name}=(value)
|
||||
raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given?
|
||||
self.class.properties[#{name.inspect}].set(self, value)
|
||||
end
|
||||
EOM
|
||||
rescue SyntaxError
|
||||
# If the name is not a valid ruby name, we use define_method.
|
||||
declared_in.define_method(name) do |value = NOT_PASSED, &block|
|
||||
raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
|
||||
self.class.properties[name].call(self, value)
|
||||
end
|
||||
declared_in.define_method("#{name}=") do |value, &block|
|
||||
raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
|
||||
self.class.properties[name].set(self, value)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The options this Property will use for get/set behavior and validation.
|
||||
#
|
||||
# @see #initialize for a list of valid options.
|
||||
#
|
||||
attr_reader :options
|
||||
|
||||
#
|
||||
# Find out whether this type accepts nil explicitly.
|
||||
#
|
||||
# A type accepts nil explicitly if "is" allows nil, it validates as nil, *and* is not simply
|
||||
# an empty type.
|
||||
#
|
||||
# A type is presumed to accept nil if it does coercion (which must handle nil).
|
||||
#
|
||||
# These examples accept nil explicitly:
|
||||
# ```ruby
|
||||
# property :a, [ String, nil ]
|
||||
# property :a, [ String, NilClass ]
|
||||
# property :a, [ String, proc { |v| v.nil? } ]
|
||||
# ```
|
||||
#
|
||||
# This does not (because the "is" doesn't exist or doesn't have nil):
|
||||
#
|
||||
# ```ruby
|
||||
# property :x, String
|
||||
# ```
|
||||
#
|
||||
# These do not, even though nil would validate fine (because they do not
|
||||
# have "is"):
|
||||
#
|
||||
# ```ruby
|
||||
# property :a
|
||||
# property :a, equal_to: [ 1, 2, 3, nil ]
|
||||
# property :a, kind_of: [ String, NilClass ]
|
||||
# property :a, respond_to: [ ]
|
||||
# property :a, callbacks: { "a" => proc { |v| v.nil? } }
|
||||
# ```
|
||||
#
|
||||
# @param resource [Chef::Resource] The resource we're coercing against
|
||||
# (to provide context for the coerce).
|
||||
#
|
||||
# @return [Boolean] Whether this value explicitly accepts nil.
|
||||
#
|
||||
# @api private
|
||||
def explicitly_accepts_nil?(resource)
|
||||
options.has_key?(:coerce) ||
|
||||
(options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false))
|
||||
end
|
||||
|
||||
# @api private
|
||||
def get_value(resource)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_get(instance_variable_name)
|
||||
else
|
||||
resource.send(name)
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def set_value(resource, value)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_set(instance_variable_name, value)
|
||||
else
|
||||
resource.send(name, value)
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def value_is_set?(resource)
|
||||
if instance_variable_name
|
||||
resource.instance_variable_defined?(instance_variable_name)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def reset_value(resource)
|
||||
if instance_variable_name
|
||||
if value_is_set?(resource)
|
||||
resource.remove_instance_variable(instance_variable_name)
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Property #{name} has no instance variable defined and cannot be reset"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def exec_in_resource(resource, proc, *args)
|
||||
if resource
|
||||
if proc.arity > args.size
|
||||
value = proc.call(resource, *args)
|
||||
else
|
||||
value = resource.instance_exec(*args, &proc)
|
||||
end
|
||||
else
|
||||
# If we don't have a resource yet, we can't exec in resource!
|
||||
raise Chef::Exceptions::CannotValidateStaticallyError, "Cannot validate or coerce without a resource"
|
||||
end
|
||||
end
|
||||
|
||||
def input_to_stored_value(resource, value, is_default: false)
|
||||
unless value.is_a?(DelayedEvaluator)
|
||||
value = coerce_and_validate(resource, value, is_default: is_default)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
def stored_value_to_output(resource, value, is_default: false)
|
||||
# Crack open lazy values before giving the result to the user
|
||||
if value.is_a?(DelayedEvaluator)
|
||||
value = exec_in_resource(resource, value)
|
||||
value = coerce_and_validate(resource, value, is_default: is_default)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# Coerces and validates the value. If the value is a default, it will warn
|
||||
# the user that invalid defaults are bad mmkay, and return it as if it were
|
||||
# valid.
|
||||
def coerce_and_validate(resource, value, is_default: false)
|
||||
result = coerce(resource, value)
|
||||
begin
|
||||
# If the input is from a default, we need to emit an invalid default warning on validate.
|
||||
validate(resource, result)
|
||||
rescue Chef::Exceptions::CannotValidateStaticallyError
|
||||
# This one gets re-raised
|
||||
raise
|
||||
rescue
|
||||
# Anything else is just an invalid default: in those cases, we just
|
||||
# warn and return the (possibly coerced) value to the user.
|
||||
if is_default
|
||||
if value.nil?
|
||||
Chef.log_deprecation("Default value nil is invalid for property #{self}. Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property #{name.inspect}, [ String, nil ], default: nil'). Error: #{$!}")
|
||||
else
|
||||
Chef.log_deprecation("Default value #{value.inspect} is invalid for property #{self}. In Chef 13 this will become an error: #{$!}.")
|
||||
end
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def nillable?
|
||||
!!options[:nillable]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,164 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/dsl/core"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
include Chef::DSL::Core
|
||||
attr_accessor :action
|
||||
def initialize(new_resource, run_context)
|
||||
super if defined?(::Chef::Provider)
|
||||
@new_resource = new_resource
|
||||
@action = action
|
||||
@current_resource = nil
|
||||
@run_context = run_context
|
||||
@converge_actions = nil
|
||||
|
||||
@recipe_name = nil
|
||||
@cookbook_name = nil
|
||||
self.class.include_resource_dsl_module(new_resource)
|
||||
end
|
||||
def converge_if_changed(*properties, &converge_block)
|
||||
if !converge_block
|
||||
raise ArgumentError, "converge_if_changed must be passed a block!"
|
||||
end
|
||||
|
||||
properties = new_resource.class.state_properties.map { |p| p.name } if properties.empty?
|
||||
properties = properties.map { |p| p.to_sym }
|
||||
if current_resource
|
||||
# Collect the list of modified properties
|
||||
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
|
||||
modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) }
|
||||
if modified.empty?
|
||||
properties_str = if sensitive
|
||||
specified_properties.join(", ")
|
||||
else
|
||||
specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")
|
||||
end
|
||||
Chef::Log.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.")
|
||||
return false
|
||||
end
|
||||
|
||||
# Print the pretty green text and run the block
|
||||
property_size = modified.map { |p| p.size }.max
|
||||
modified.map! do |p|
|
||||
properties_str = if sensitive
|
||||
"(suppressed sensitive property)"
|
||||
else
|
||||
"#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})"
|
||||
end
|
||||
" set #{p.to_s.ljust(property_size)} to #{properties_str}"
|
||||
end
|
||||
converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block)
|
||||
|
||||
else
|
||||
# The resource doesn't exist. Mark that we are *creating* this, and
|
||||
# write down any properties we are setting.
|
||||
property_size = properties.map { |p| p.size }.max
|
||||
created = properties.map do |property|
|
||||
default = " (default value)" unless new_resource.property_is_set?(property)
|
||||
properties_str = if sensitive
|
||||
"(suppressed sensitive property)"
|
||||
else
|
||||
new_resource.send(property).inspect
|
||||
end
|
||||
" set #{property.to_s.ljust(property_size)} to #{properties_str}#{default}"
|
||||
end
|
||||
|
||||
converge_by([ "create #{new_resource.identity}" ] + created, &converge_block)
|
||||
end
|
||||
true
|
||||
end
|
||||
def self.include_resource_dsl(include_resource_dsl)
|
||||
@include_resource_dsl = include_resource_dsl
|
||||
end
|
||||
def self.include_resource_dsl_module(resource)
|
||||
if @include_resource_dsl && !defined?(@included_resource_dsl_module)
|
||||
provider_class = self
|
||||
@included_resource_dsl_module = Module.new do
|
||||
extend Forwardable
|
||||
define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
|
||||
define_singleton_method(:inspect) { to_s }
|
||||
# Add a delegator for each explicit property that will get the *current* value
|
||||
# of the property by default instead of the *actual* value.
|
||||
resource.class.properties.each do |name, property|
|
||||
class_eval(<<-EOM, __FILE__, __LINE__)
|
||||
def #{name}(*args, &block)
|
||||
# If no arguments were passed, we process "get" by defaulting
|
||||
# the value to current_resource, not new_resource. This helps
|
||||
# avoid issues where resources accidentally overwrite perfectly
|
||||
# valid stuff with default values.
|
||||
if args.empty? && !block
|
||||
if !new_resource.property_is_set?(__method__) && current_resource
|
||||
return current_resource.public_send(__method__)
|
||||
end
|
||||
end
|
||||
new_resource.public_send(__method__, *args, &block)
|
||||
end
|
||||
EOM
|
||||
end
|
||||
dsl_methods =
|
||||
resource.class.public_instance_methods +
|
||||
resource.class.protected_instance_methods -
|
||||
provider_class.instance_methods -
|
||||
resource.class.properties.keys
|
||||
def_delegators(:new_resource, *dsl_methods)
|
||||
end
|
||||
include @included_resource_dsl_module
|
||||
end
|
||||
end
|
||||
def self.use_inline_resources
|
||||
extend InlineResources::ClassMethods
|
||||
include InlineResources
|
||||
end
|
||||
module InlineResources
|
||||
CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources, self) if defined?(::Chef::Provider::InlineResources)
|
||||
def compile_and_converge_action(&block)
|
||||
old_run_context = run_context
|
||||
@run_context = run_context.create_child
|
||||
return_value = instance_eval(&block)
|
||||
Chef::Runner.new(run_context).converge
|
||||
return_value
|
||||
ensure
|
||||
if run_context.resource_collection.any? { |r| r.updated? }
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
@run_context = old_run_context
|
||||
end
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources::ClassMethods, self) if defined?(::Chef::Provider::InlineResources::ClassMethods)
|
||||
def action(name, &block)
|
||||
# We need the block directly in a method so that `super` works
|
||||
define_method("compile_action_#{name}", &block)
|
||||
# We try hard to use `def` because define_method doesn't show the method name in the stack.
|
||||
begin
|
||||
class_eval <<-EOM
|
||||
def action_#{name}
|
||||
compile_and_converge_action { compile_action_#{name} }
|
||||
end
|
||||
EOM
|
||||
rescue SyntaxError
|
||||
define_method("action_#{name}") { send("compile_action_#{name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
protected
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,269 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/apt_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class AptRepository < (defined?(::Chef::Provider::AptRepository) ? ::Chef::Provider::AptRepository : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :apt_repository do
|
||||
which("apt-get")
|
||||
end
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
end
|
||||
|
||||
action :add do
|
||||
unless new_resource.key.nil?
|
||||
if is_key_id?(new_resource.key) && !has_cookbook_file?(new_resource.key)
|
||||
install_key_from_keyserver
|
||||
else
|
||||
install_key_from_uri
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:execute, "apt-cache gencaches") do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
declare_resource(:apt_update, new_resource.name) do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
components = if is_ppa_url?(new_resource.uri) && new_resource.components.empty?
|
||||
"main"
|
||||
else
|
||||
new_resource.components
|
||||
end
|
||||
|
||||
repo = build_repo(
|
||||
new_resource.uri,
|
||||
new_resource.distribution,
|
||||
components,
|
||||
new_resource.trusted,
|
||||
new_resource.arch,
|
||||
new_resource.deb_src
|
||||
)
|
||||
|
||||
declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do
|
||||
owner "root"
|
||||
group "root"
|
||||
mode "0644"
|
||||
content repo
|
||||
sensitive new_resource.sensitive
|
||||
action :create
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.name}.list")
|
||||
converge_by "Removing #{new_resource.name} repository from /etc/apt/sources.list.d/" do
|
||||
declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do
|
||||
sensitive new_resource.sensitive
|
||||
action :delete
|
||||
notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild
|
||||
end
|
||||
|
||||
declare_resource(:apt_update, new_resource.name) do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def is_key_id?(id)
|
||||
id = id[2..-1] if id.start_with?("0x")
|
||||
id =~ /^\h+$/ && [8, 16, 40].include?(id.length)
|
||||
end
|
||||
|
||||
def extract_fingerprints_from_cmd(cmd)
|
||||
so = shell_out(cmd)
|
||||
so.run_command
|
||||
so.stdout.split(/\n/).map do |t|
|
||||
if z = t.match(/^ +Key fingerprint = ([0-9A-F ]+)/)
|
||||
z[1].split.join
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
def key_is_valid?(cmd, key)
|
||||
valid = true
|
||||
|
||||
so = shell_out(cmd)
|
||||
so.run_command
|
||||
so.stdout.split(/\n/).map do |t|
|
||||
if t =~ %r{^\/#{key}.*\[expired: .*\]$}
|
||||
Chef::Log.debug "Found expired key: #{t}"
|
||||
valid = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Log.debug "key #{key} #{valid ? "is valid" : "is not valid"}"
|
||||
valid
|
||||
end
|
||||
|
||||
def cookbook_name
|
||||
new_resource.cookbook || new_resource.cookbook_name
|
||||
end
|
||||
|
||||
def has_cookbook_file?(fn)
|
||||
run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn)
|
||||
end
|
||||
|
||||
def no_new_keys?(file)
|
||||
installed_keys = extract_fingerprints_from_cmd("apt-key finger")
|
||||
proposed_keys = extract_fingerprints_from_cmd("gpg --with-fingerprint #{file}")
|
||||
(installed_keys & proposed_keys).sort == proposed_keys.sort
|
||||
end
|
||||
|
||||
def install_key_from_uri
|
||||
key_name = new_resource.key.gsub(/[^0-9A-Za-z\-]/, "_")
|
||||
cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name)
|
||||
type = if new_resource.key.start_with?("http")
|
||||
:remote_file
|
||||
elsif has_cookbook_file?(new_resource.key)
|
||||
:cookbook_file
|
||||
else
|
||||
raise Chef::Exceptions::FileNotFound, "Cannot locate key file"
|
||||
end
|
||||
|
||||
declare_resource(type, cached_keyfile) do
|
||||
source new_resource.key
|
||||
mode "0644"
|
||||
sensitive new_resource.sensitive
|
||||
action :create
|
||||
end
|
||||
|
||||
raise "The key #{cached_keyfile} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("gpg #{cached_keyfile}", "")
|
||||
|
||||
declare_resource(:execute, "apt-key add #{cached_keyfile}") do
|
||||
sensitive new_resource.sensitive
|
||||
action :run
|
||||
not_if do
|
||||
no_new_keys?(cached_keyfile)
|
||||
end
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
end
|
||||
end
|
||||
|
||||
def install_key_from_keyserver(key = new_resource.key, keyserver = new_resource.keyserver)
|
||||
cmd = "apt-key adv --recv"
|
||||
cmd << " --keyserver-options http-proxy=#{new_resource.key_proxy}" if new_resource.key_proxy
|
||||
cmd << " --keyserver "
|
||||
cmd << if keyserver.start_with?("hkp://")
|
||||
keyserver
|
||||
else
|
||||
"hkp://#{keyserver}:80"
|
||||
end
|
||||
|
||||
cmd << " #{key}"
|
||||
|
||||
declare_resource(:execute, "install-key #{key}") do
|
||||
command cmd
|
||||
sensitive new_resource.sensitive
|
||||
not_if do
|
||||
present = extract_fingerprints_from_cmd("apt-key finger").any? do |fp|
|
||||
fp.end_with? key.upcase
|
||||
end
|
||||
present && key_is_valid?("apt-key list", key.upcase)
|
||||
end
|
||||
notifies :run, "execute[apt-cache gencaches]", :immediately
|
||||
end
|
||||
|
||||
raise "The key #{key} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("apt-key list", key.upcase)
|
||||
end
|
||||
|
||||
def install_ppa_key(owner, repo)
|
||||
url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}"
|
||||
key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"')
|
||||
install_key_from_keyserver(key_id, "keyserver.ubuntu.com")
|
||||
rescue Net::HTTPServerException => e
|
||||
raise "Could not access Launchpad ppa API: #{e.message}"
|
||||
end
|
||||
|
||||
def is_ppa_url?(url)
|
||||
url.start_with?("ppa:")
|
||||
end
|
||||
|
||||
def make_ppa_url(ppa)
|
||||
return unless is_ppa_url?(ppa)
|
||||
owner, repo = ppa[4..-1].split("/")
|
||||
repo ||= "ppa"
|
||||
|
||||
install_ppa_key(owner, repo)
|
||||
"http://ppa.launchpad.net/#{owner}/#{repo}/ubuntu"
|
||||
end
|
||||
|
||||
def build_repo(uri, distribution, components, trusted, arch, add_src = false)
|
||||
uri = make_ppa_url(uri) if is_ppa_url?(uri)
|
||||
|
||||
uri = '"' + uri + '"' unless uri.start_with?("'", '"')
|
||||
components = Array(components).join(" ")
|
||||
options = []
|
||||
options << "arch=#{arch}" if arch
|
||||
options << "trusted=yes" if trusted
|
||||
optstr = unless options.empty?
|
||||
"[" + options.join(" ") + "]"
|
||||
end
|
||||
info = [ optstr, uri, distribution, components ].compact.join(" ")
|
||||
repo = "deb #{info}\n"
|
||||
repo << "deb-src #{info}\n" if add_src
|
||||
repo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :apt_repository
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,105 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/apt_update'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/provider"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class AptUpdate < (defined?(::Chef::Provider::AptUpdate) ? ::Chef::Provider::AptUpdate : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :apt_update do
|
||||
which("apt-get")
|
||||
end
|
||||
|
||||
APT_CONF_DIR = "/etc/apt/apt.conf.d"
|
||||
STAMP_DIR = "/var/lib/apt/periodic"
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
end
|
||||
|
||||
action :periodic do
|
||||
if !apt_up_to_date?
|
||||
converge_by "update new lists of packages" do
|
||||
do_update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :update do
|
||||
converge_by "force update new lists of packages" do
|
||||
do_update
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Determines whether we need to run `apt-get update`
|
||||
#
|
||||
# @return [Boolean]
|
||||
def apt_up_to_date?
|
||||
::File.exist?("#{STAMP_DIR}/update-success-stamp") &&
|
||||
::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency
|
||||
end
|
||||
|
||||
def do_update
|
||||
[STAMP_DIR, APT_CONF_DIR].each do |d|
|
||||
declare_resource(:directory, d) do
|
||||
recursive true
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:file, "#{APT_CONF_DIR}/15update-stamp") do
|
||||
content "APT::Update::Post-Invoke-Success {\"touch #{STAMP_DIR}/update-success-stamp 2>/dev/null || true\";};\n"
|
||||
action :create_if_missing
|
||||
end
|
||||
|
||||
declare_resource(:execute, "apt-get -q update")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :apt_update
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,56 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/noop'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class Noop < (defined?(::Chef::Provider::Noop) ? ::Chef::Provider::Noop : Chef::Provider)
|
||||
def load_current_resource; end
|
||||
|
||||
def respond_to_missing?(method_sym, include_private = false)
|
||||
method_sym.to_s.start_with?("action_") || super
|
||||
end
|
||||
|
||||
def method_missing(method_sym, *arguments, &block)
|
||||
if method_sym.to_s =~ /^action_/
|
||||
Chef::Log.debug("NoOp-ing for #{method_sym}")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,253 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/systemd_unit'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Nathan Williams (<nath.e.will@gmail.com>)
|
||||
# Copyright:: Copyright 2016, Nathan Williams
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/provider"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class SystemdUnit < (defined?(::Chef::Provider::SystemdUnit) ? ::Chef::Provider::SystemdUnit : Chef::Provider)
|
||||
include Chef::Mixin::Which
|
||||
include Chef::Mixin::ShellOut
|
||||
|
||||
provides :systemd_unit, os: "linux"
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::SystemdUnit.new(new_resource.name)
|
||||
|
||||
current_resource.content(::File.read(unit_path)) if ::File.exist?(unit_path)
|
||||
current_resource.user(new_resource.user)
|
||||
current_resource.enabled(enabled?)
|
||||
current_resource.active(active?)
|
||||
current_resource.masked(masked?)
|
||||
current_resource.static(static?)
|
||||
current_resource.triggers_reload(new_resource.triggers_reload)
|
||||
|
||||
current_resource
|
||||
end
|
||||
|
||||
def define_resource_requirements
|
||||
super
|
||||
|
||||
requirements.assert(:create) do |a|
|
||||
a.assertion { IniParse.parse(new_resource.to_ini) }
|
||||
a.failure_message "Unit content is not valid INI text"
|
||||
end
|
||||
end
|
||||
|
||||
def action_create
|
||||
if current_resource.content != new_resource.to_ini
|
||||
converge_by("creating unit: #{new_resource.name}") do
|
||||
manage_unit_file(:create)
|
||||
daemon_reload if new_resource.triggers_reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_delete
|
||||
if ::File.exist?(unit_path)
|
||||
converge_by("deleting unit: #{new_resource.name}") do
|
||||
manage_unit_file(:delete)
|
||||
daemon_reload if new_resource.triggers_reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_enable
|
||||
if current_resource.static
|
||||
Chef::Log.debug("#{new_resource.name} is a static unit, enabling is a NOP.")
|
||||
end
|
||||
|
||||
unless current_resource.enabled || current_resource.static
|
||||
converge_by("enabling unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:enable, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_disable
|
||||
if current_resource.static
|
||||
Chef::Log.debug("#{new_resource.name} is a static unit, disabling is a NOP.")
|
||||
end
|
||||
|
||||
if current_resource.enabled && !current_resource.static
|
||||
converge_by("disabling unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:disable, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_mask
|
||||
unless current_resource.masked
|
||||
converge_by("masking unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:mask, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_unmask
|
||||
if current_resource.masked
|
||||
converge_by("unmasking unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:unmask, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_start
|
||||
unless current_resource.active
|
||||
converge_by("starting unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:start, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_stop
|
||||
if current_resource.active
|
||||
converge_by("stopping unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:stop, new_resource.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def action_restart
|
||||
converge_by("restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:restart, new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload
|
||||
if current_resource.active
|
||||
converge_by("reloading unit: #{new_resource.name}") do
|
||||
systemctl_execute!(:reload, new_resource.name)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.name} is not active, skipping reload.")
|
||||
end
|
||||
end
|
||||
|
||||
def action_try_restart
|
||||
converge_by("try-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("try-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload_or_restart
|
||||
converge_by("reload-or-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("reload-or-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def action_reload_or_try_restart
|
||||
converge_by("reload-or-try-restarting unit: #{new_resource.name}") do
|
||||
systemctl_execute!("reload-or-try-restart", new_resource.name)
|
||||
end
|
||||
end
|
||||
|
||||
def active?
|
||||
systemctl_execute("is-active", new_resource.name).exitstatus == 0
|
||||
end
|
||||
|
||||
def enabled?
|
||||
systemctl_execute("is-enabled", new_resource.name).exitstatus == 0
|
||||
end
|
||||
|
||||
def masked?
|
||||
systemctl_execute(:status, new_resource.name).stdout.include?("masked")
|
||||
end
|
||||
|
||||
def static?
|
||||
systemctl_execute("is-enabled", new_resource.name).stdout.include?("static")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unit_path
|
||||
if new_resource.user
|
||||
"/etc/systemd/user/#{new_resource.name}"
|
||||
else
|
||||
"/etc/systemd/system/#{new_resource.name}"
|
||||
end
|
||||
end
|
||||
|
||||
def manage_unit_file(action = :nothing)
|
||||
Chef::Resource::File.new(unit_path, run_context).tap do |f|
|
||||
f.owner "root"
|
||||
f.group "root"
|
||||
f.mode "0644"
|
||||
f.content new_resource.to_ini
|
||||
end.run_action(action)
|
||||
end
|
||||
|
||||
def daemon_reload
|
||||
shell_out_with_systems_locale!("#{systemctl_path} daemon-reload")
|
||||
end
|
||||
|
||||
def systemctl_execute!(action, unit)
|
||||
shell_out_with_systems_locale!("#{systemctl_cmd} #{action} #{unit}", systemctl_opts)
|
||||
end
|
||||
|
||||
def systemctl_execute(action, unit)
|
||||
shell_out("#{systemctl_cmd} #{action} #{unit}", systemctl_opts)
|
||||
end
|
||||
|
||||
def systemctl_cmd
|
||||
@systemctl_cmd ||= "#{systemctl_path} #{systemctl_args}"
|
||||
end
|
||||
|
||||
def systemctl_path
|
||||
@systemctl_path ||= which("systemctl")
|
||||
end
|
||||
|
||||
def systemctl_args
|
||||
@systemctl_args ||= new_resource.user ? "--user" : "--system"
|
||||
end
|
||||
|
||||
def systemctl_opts
|
||||
@systemctl_opts ||=
|
||||
if new_resource.user
|
||||
{
|
||||
:user => new_resource.user,
|
||||
:environment => {
|
||||
"DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{node['etc']['passwd'][new_resource.user]['uid']}/bus",
|
||||
},
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,137 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/provider/yum_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/declare_resource"
|
||||
require "chef_compat/copied_from_chef/chef/provider/noop"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object)
|
||||
class YumRepository < (defined?(::Chef::Provider::YumRepository) ? ::Chef::Provider::YumRepository : Chef::Provider)
|
||||
use_inline_resources
|
||||
|
||||
extend Chef::Mixin::Which
|
||||
|
||||
provides :yum_repository do
|
||||
which "yum"
|
||||
end
|
||||
|
||||
def whyrun_supported?; true; end
|
||||
|
||||
def load_current_resource; end
|
||||
|
||||
action :create do
|
||||
declare_resource(:template, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do
|
||||
if template_available?(new_resource.source)
|
||||
source new_resource.source
|
||||
else
|
||||
source ::File.expand_path("../support/yum_repo.erb", __FILE__)
|
||||
local true
|
||||
end
|
||||
sensitive new_resource.sensitive
|
||||
variables(config: new_resource)
|
||||
mode new_resource.mode
|
||||
if new_resource.make_cache
|
||||
notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers
|
||||
notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
|
||||
notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately
|
||||
end
|
||||
end
|
||||
|
||||
declare_resource(:execute, "yum clean metadata #{new_resource.repositoryid}") do
|
||||
command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# get the metadata for this repo only
|
||||
declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
|
||||
command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :nothing
|
||||
only_if { new_resource.enabled }
|
||||
end
|
||||
|
||||
# reload internal Chef yum cache
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
declare_resource(:file, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do
|
||||
action :delete
|
||||
notifies :run, "execute[yum clean all #{new_resource.repositoryid}]", :immediately
|
||||
notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately
|
||||
end
|
||||
|
||||
declare_resource(:execute, "yum clean all #{new_resource.repositoryid}") do
|
||||
command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
only_if "yum repolist | grep -P '^#{new_resource.repositoryid}([ \t]|$)'"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
action :makecache do
|
||||
declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
|
||||
command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
|
||||
action :run
|
||||
only_if { new_resource.enabled }
|
||||
end
|
||||
|
||||
declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do
|
||||
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
|
||||
action :run
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :action_add, :action_create
|
||||
alias_method :action_remove, :action_delete
|
||||
|
||||
def template_available?(path)
|
||||
!path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Provider::Noop.provides :yum_repository
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,214 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
require "chef_compat/copied_from_chef/chef/resource/action_class"
|
||||
require "chef_compat/copied_from_chef/chef/provider"
|
||||
require "chef_compat/copied_from_chef/chef/mixin/properties"
|
||||
require "chef_compat/copied_from_chef/chef/dsl/universal"
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
include Chef::Mixin::Properties
|
||||
property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(", ") : v.to_s }, desired_state: false
|
||||
def initialize(name, run_context = nil)
|
||||
super if defined?(::Chef::Resource)
|
||||
name(name) unless name.nil?
|
||||
@run_context = run_context
|
||||
@noop = nil
|
||||
@before = nil
|
||||
@params = Hash.new
|
||||
@provider = nil
|
||||
@allowed_actions = self.class.allowed_actions.to_a
|
||||
@action = self.class.default_action
|
||||
@updated = false
|
||||
@updated_by_last_action = false
|
||||
@supports = {}
|
||||
@ignore_failure = false
|
||||
@retries = 0
|
||||
@retry_delay = 2
|
||||
@not_if = []
|
||||
@only_if = []
|
||||
@source_line = nil
|
||||
# We would like to raise an error when the user gives us a guard
|
||||
# interpreter and a ruby_block to the guard. In order to achieve this
|
||||
# we need to understand when the user overrides the default guard
|
||||
# interpreter. Therefore we store the default separately in a different
|
||||
# attribute.
|
||||
@guard_interpreter = nil
|
||||
@default_guard_interpreter = :default
|
||||
@elapsed_time = 0
|
||||
@sensitive = false
|
||||
end
|
||||
def action(arg = nil)
|
||||
if arg
|
||||
arg = Array(arg).map(&:to_sym)
|
||||
arg.each do |action|
|
||||
validate(
|
||||
{ action: action },
|
||||
{ action: { kind_of: Symbol, equal_to: allowed_actions } }
|
||||
)
|
||||
end
|
||||
@action = arg
|
||||
else
|
||||
@action
|
||||
end
|
||||
end
|
||||
alias_method :action=, :action
|
||||
class UnresolvedSubscribes < (defined?(::Chef::Resource::UnresolvedSubscribes) ? ::Chef::Resource::UnresolvedSubscribes : self)
|
||||
alias_method :to_s, :name
|
||||
alias_method :declared_key, :name
|
||||
end
|
||||
def state_for_resource_reporter
|
||||
state = {}
|
||||
state_properties = self.class.state_properties
|
||||
state_properties.each do |property|
|
||||
if property.identity? || property.is_set?(self)
|
||||
state[property.name] = property.sensitive? ? "*sensitive value suppressed*" : send(property.name)
|
||||
end
|
||||
end
|
||||
state
|
||||
end
|
||||
alias_method :state, :state_for_resource_reporter
|
||||
def identity
|
||||
result = {}
|
||||
identity_properties = self.class.identity_properties
|
||||
identity_properties.each do |property|
|
||||
result[property.name] = send(property.name)
|
||||
end
|
||||
return result.values.first if identity_properties.size == 1
|
||||
result
|
||||
end
|
||||
attr_reader :resource_initializing
|
||||
def resource_initializing=(value)
|
||||
if value
|
||||
@resource_initializing = true
|
||||
else
|
||||
remove_instance_variable(:@resource_initializing)
|
||||
end
|
||||
end
|
||||
def to_hash
|
||||
# Grab all current state, then any other ivars (backcompat)
|
||||
result = {}
|
||||
self.class.state_properties.each do |p|
|
||||
result[p.name] = p.get(self)
|
||||
end
|
||||
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
||||
safe_ivars.each do |iv|
|
||||
key = iv.to_s.sub(/^@/, "").to_sym
|
||||
next if result.has_key?(key)
|
||||
result[key] = instance_variable_get(iv)
|
||||
end
|
||||
result
|
||||
end
|
||||
def self.identity_property(name = nil)
|
||||
result = identity_properties(*Array(name))
|
||||
if result.size > 1
|
||||
raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map { |r| r.name }.join(", ")})."
|
||||
end
|
||||
result.first
|
||||
end
|
||||
attr_accessor :allowed_actions
|
||||
def allowed_actions(value = NOT_PASSED)
|
||||
if value != NOT_PASSED
|
||||
self.allowed_actions = value
|
||||
end
|
||||
@allowed_actions
|
||||
end
|
||||
def resource_name
|
||||
@resource_name || self.class.resource_name
|
||||
end
|
||||
def self.use_automatic_resource_name
|
||||
automatic_name = convert_to_snake_case(self.name.split("::")[-1])
|
||||
resource_name automatic_name
|
||||
end
|
||||
def self.allowed_actions(*actions)
|
||||
@allowed_actions ||=
|
||||
if superclass.respond_to?(:allowed_actions)
|
||||
superclass.allowed_actions.dup
|
||||
else
|
||||
[ :nothing ]
|
||||
end
|
||||
@allowed_actions |= actions.flatten
|
||||
end
|
||||
def self.allowed_actions=(value)
|
||||
@allowed_actions = value.uniq
|
||||
end
|
||||
def self.default_action(action_name = NOT_PASSED)
|
||||
unless action_name.equal?(NOT_PASSED)
|
||||
@default_action = Array(action_name).map(&:to_sym)
|
||||
self.allowed_actions |= @default_action
|
||||
end
|
||||
|
||||
if @default_action
|
||||
@default_action
|
||||
elsif superclass.respond_to?(:default_action)
|
||||
superclass.default_action
|
||||
else
|
||||
[:nothing]
|
||||
end
|
||||
end
|
||||
def self.default_action=(action_name)
|
||||
default_action action_name
|
||||
end
|
||||
def self.action(action, &recipe_block)
|
||||
action = action.to_sym
|
||||
declare_action_class
|
||||
action_class.action(action, &recipe_block)
|
||||
self.allowed_actions += [ action ]
|
||||
default_action action if Array(default_action) == [:nothing]
|
||||
end
|
||||
def self.load_current_value(&load_block)
|
||||
define_method(:load_current_value!, &load_block)
|
||||
end
|
||||
def current_value_does_not_exist!
|
||||
raise Chef::Exceptions::CurrentValueDoesNotExist
|
||||
end
|
||||
def self.action_class(&block)
|
||||
return @action_class if @action_class && !block
|
||||
# If the superclass needed one, then we need one as well.
|
||||
if block || (superclass.respond_to?(:action_class) && superclass.action_class)
|
||||
@action_class = declare_action_class(&block)
|
||||
end
|
||||
@action_class
|
||||
end
|
||||
def self.declare_action_class(&block)
|
||||
@action_class ||= begin
|
||||
if superclass.respond_to?(:action_class)
|
||||
base_provider = superclass.action_class
|
||||
end
|
||||
base_provider ||= Chef::Provider
|
||||
|
||||
resource_class = self
|
||||
Class.new(base_provider) do
|
||||
include ActionClass
|
||||
self.resource_class = resource_class
|
||||
end
|
||||
end
|
||||
@action_class.class_eval(&block) if block
|
||||
@action_class
|
||||
end
|
||||
FORBIDDEN_IVARS = [:@run_context, :@not_if, :@only_if, :@enclosing_provider]
|
||||
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider]
|
||||
class << self
|
||||
end
|
||||
@@sorted_descendants = nil
|
||||
module DeprecatedLWRPClass
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::DeprecatedLWRPClass, self) if defined?(::Chef::Resource::DeprecatedLWRPClass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,114 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/action_class'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: John Keiser (<jkeiser@chef.io)
|
||||
# Copyright:: Copyright 2015-2016, Chef Software Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/dsl/recipe"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
module ActionClass
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::ActionClass, self) if defined?(::Chef::Resource::ActionClass)
|
||||
include Chef::DSL::Recipe
|
||||
|
||||
def to_s
|
||||
"#{new_resource || "<no resource>"} action #{action ? action.inspect : "<no action>"}"
|
||||
end
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
#
|
||||
# If load_current_value! is defined on the resource, use that.
|
||||
#
|
||||
def load_current_resource
|
||||
if new_resource.respond_to?(:load_current_value!)
|
||||
# dup the resource and then reset desired-state properties.
|
||||
current_resource = new_resource.dup
|
||||
|
||||
# We clear desired state in the copy, because it is supposed to be actual state.
|
||||
# We keep identity properties and non-desired-state, which are assumed to be
|
||||
# "control" values like `recurse: true`
|
||||
current_resource.class.properties.each do |name, property|
|
||||
if property.desired_state? && !property.identity? && !property.name_property?
|
||||
property.reset(current_resource)
|
||||
end
|
||||
end
|
||||
|
||||
# Call the actual load_current_value! method. If it raises
|
||||
# CurrentValueDoesNotExist, set current_resource to `nil`.
|
||||
begin
|
||||
# If the user specifies load_current_value do |desired_resource|, we
|
||||
# pass in the desired resource as well as the current one.
|
||||
if current_resource.method(:load_current_value!).arity > 0
|
||||
current_resource.load_current_value!(new_resource)
|
||||
else
|
||||
current_resource.load_current_value!
|
||||
end
|
||||
rescue Chef::Exceptions::CurrentValueDoesNotExist
|
||||
current_resource = nil
|
||||
end
|
||||
end
|
||||
|
||||
@current_resource = current_resource
|
||||
end
|
||||
|
||||
def self.included(other)
|
||||
other.extend(ClassMethods)
|
||||
other.use_inline_resources
|
||||
other.include_resource_dsl true
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
CopiedFromChef.extend_chef_module(::Chef::Resource::ActionClass::ClassMethods, self) if defined?(::Chef::Resource::ActionClass::ClassMethods)
|
||||
#
|
||||
# The Chef::Resource class this ActionClass was declared against.
|
||||
#
|
||||
# @return [Class] The Chef::Resource class this ActionClass was declared against.
|
||||
#
|
||||
attr_accessor :resource_class
|
||||
|
||||
def to_s
|
||||
"#{resource_class} action provider"
|
||||
end
|
||||
|
||||
def inspect
|
||||
to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,66 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/apt_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class AptRepository < (defined?(::Chef::Resource::AptRepository) ? ::Chef::Resource::AptRepository : Chef::Resource)
|
||||
resource_name :apt_repository
|
||||
provides :apt_repository
|
||||
|
||||
property :repo_name, String, name_property: true
|
||||
property :uri, String
|
||||
property :distribution, [ String, nil, false ], default: lazy { node["lsb"]["codename"] }, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :components, Array, default: []
|
||||
property :arch, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :trusted, [TrueClass, FalseClass], default: false
|
||||
# whether or not to add the repository as a source repo, too
|
||||
property :deb_src, [TrueClass, FalseClass], default: false
|
||||
property :keyserver, [String, nil, false], default: "keyserver.ubuntu.com", nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :key, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :key_proxy, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
|
||||
property :cookbook, [String, nil, false], default: nil, desired_state: false, nillable: true, coerce: proc { |x| x ? x : nil }
|
||||
property :cache_rebuild, [TrueClass, FalseClass], default: true, desired_state: false
|
||||
property :sensitive, [TrueClass, FalseClass], default: false, desired_state: false
|
||||
|
||||
default_action :add
|
||||
allowed_actions :add, :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,52 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/apt_update'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class AptUpdate < (defined?(::Chef::Resource::AptUpdate) ? ::Chef::Resource::AptUpdate : Chef::Resource)
|
||||
resource_name :apt_update
|
||||
provides :apt_update, os: "linux"
|
||||
|
||||
property :frequency, Integer, default: 86_400
|
||||
|
||||
default_action :periodic
|
||||
allowed_actions :update, :periodic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,81 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/systemd_unit'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Nathan Williams (<nath.e.will@gmail.com>)
|
||||
# Copyright:: Copyright 2016, Nathan Williams
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class SystemdUnit < (defined?(::Chef::Resource::SystemdUnit) ? ::Chef::Resource::SystemdUnit : Chef::Resource)
|
||||
resource_name :systemd_unit
|
||||
|
||||
default_action :nothing
|
||||
allowed_actions :create, :delete,
|
||||
:enable, :disable,
|
||||
:mask, :unmask,
|
||||
:start, :stop,
|
||||
:restart, :reload,
|
||||
:try_restart, :reload_or_restart,
|
||||
:reload_or_try_restart
|
||||
|
||||
property :enabled, [TrueClass, FalseClass]
|
||||
property :active, [TrueClass, FalseClass]
|
||||
property :masked, [TrueClass, FalseClass]
|
||||
property :static, [TrueClass, FalseClass]
|
||||
property :user, String, desired_state: false
|
||||
property :content, [String, Hash]
|
||||
property :triggers_reload, [TrueClass, FalseClass],
|
||||
default: true, desired_state: false
|
||||
|
||||
def to_ini
|
||||
case content
|
||||
when Hash
|
||||
IniParse.gen do |doc|
|
||||
content.each_pair do |sect, opts|
|
||||
doc.section(sect) do |section|
|
||||
opts.each_pair do |opt, val|
|
||||
section.option(opt, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
end.to_s
|
||||
else
|
||||
content.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,98 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource/yum_repository'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Thom May (<thom@chef.io>)
|
||||
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
||||
class YumRepository < (defined?(::Chef::Resource::YumRepository) ? ::Chef::Resource::YumRepository : Chef::Resource)
|
||||
resource_name :yum_repository
|
||||
provides :yum_repository
|
||||
|
||||
# http://linux.die.net/man/5/yum.conf
|
||||
property :baseurl, String, regex: /.*/
|
||||
property :cost, String, regex: /^\d+$/
|
||||
property :clean_headers, [TrueClass, FalseClass], default: false # deprecated
|
||||
property :clean_metadata, [TrueClass, FalseClass], default: true
|
||||
property :description, String, regex: /.*/, default: "Yum Repository"
|
||||
property :enabled, [TrueClass, FalseClass], default: true
|
||||
property :enablegroups, [TrueClass, FalseClass]
|
||||
property :exclude, String, regex: /.*/
|
||||
property :failovermethod, String, equal_to: %w{priority roundrobin}
|
||||
property :fastestmirror_enabled, [TrueClass, FalseClass]
|
||||
property :gpgcheck, [TrueClass, FalseClass], default: true
|
||||
property :gpgkey, [String, Array], regex: /.*/
|
||||
property :http_caching, String, equal_to: %w{packages all none}
|
||||
property :include_config, String, regex: /.*/
|
||||
property :includepkgs, String, regex: /.*/
|
||||
property :keepalive, [TrueClass, FalseClass]
|
||||
property :make_cache, [TrueClass, FalseClass], default: true
|
||||
property :max_retries, [String, Integer]
|
||||
property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/]
|
||||
property :mirrorexpire, String, regex: /.*/
|
||||
property :mirrorlist, String, regex: /.*/
|
||||
property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
|
||||
property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/]
|
||||
property :mode, default: "0644"
|
||||
property :priority, String, regex: /^(\d?[0-9]|[0-9][0-9])$/
|
||||
property :proxy, String, regex: /.*/
|
||||
property :proxy_username, String, regex: /.*/
|
||||
property :proxy_password, String, regex: /.*/
|
||||
property :username, String, regex: /.*/
|
||||
property :password, String, regex: /.*/
|
||||
property :repo_gpgcheck, [TrueClass, FalseClass]
|
||||
property :report_instanceid, [TrueClass, FalseClass]
|
||||
property :repositoryid, String, regex: /.*/, name_property: true
|
||||
property :sensitive, [TrueClass, FalseClass], default: false
|
||||
property :skip_if_unavailable, [TrueClass, FalseClass]
|
||||
property :source, String, regex: /.*/
|
||||
property :sslcacert, String, regex: /.*/
|
||||
property :sslclientcert, String, regex: /.*/
|
||||
property :sslclientkey, String, regex: /.*/
|
||||
property :sslverify, [TrueClass, FalseClass]
|
||||
property :timeout, String, regex: /^\d+$/
|
||||
property :options, Hash
|
||||
|
||||
default_action :create
|
||||
allowed_actions :create, :remove, :makecache, :add, :delete
|
||||
|
||||
# provide compatibility with the yum cookbook < 3.0 properties
|
||||
alias_method :url, :baseurl
|
||||
alias_method :keyurl, :gpgkey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,174 @@
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!!
|
||||
#
|
||||
# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
|
||||
#
|
||||
|
||||
begin
|
||||
require 'chef/resource_builder'
|
||||
rescue LoadError; end
|
||||
|
||||
require 'chef_compat/copied_from_chef'
|
||||
class Chef
|
||||
module ::ChefCompat
|
||||
module CopiedFromChef
|
||||
#
|
||||
# Author:: Lamont Granquist (<lamont@chef.io>)
|
||||
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
|
||||
|
||||
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
||||
class ResourceBuilder < (defined?(::Chef::ResourceBuilder) ? ::Chef::ResourceBuilder : Object)
|
||||
attr_reader :type
|
||||
attr_reader :name
|
||||
attr_reader :created_at
|
||||
attr_reader :params
|
||||
attr_reader :run_context
|
||||
attr_reader :cookbook_name
|
||||
attr_reader :recipe_name
|
||||
attr_reader :enclosing_provider
|
||||
attr_reader :resource
|
||||
|
||||
# FIXME (ruby-2.1 syntax): most of these are mandatory
|
||||
def initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil)
|
||||
super if defined?(::Chef::ResourceBuilder)
|
||||
@type = type
|
||||
@name = name
|
||||
@created_at = created_at
|
||||
@params = params
|
||||
@run_context = run_context
|
||||
@cookbook_name = cookbook_name
|
||||
@recipe_name = recipe_name
|
||||
@enclosing_provider = enclosing_provider
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
|
||||
|
||||
@resource = resource_class.new(name, run_context)
|
||||
if resource.resource_name.nil?
|
||||
raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
|
||||
end
|
||||
resource.source_line = created_at
|
||||
resource.declared_type = type
|
||||
|
||||
# If we have a resource like this one, we want to steal its state
|
||||
# This behavior is very counter-intuitive and should be removed.
|
||||
# See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694
|
||||
# Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052
|
||||
if prior_resource
|
||||
resource.load_from(prior_resource)
|
||||
end
|
||||
|
||||
resource.cookbook_name = cookbook_name
|
||||
resource.recipe_name = recipe_name
|
||||
# Determine whether this resource is being created in the context of an enclosing Provider
|
||||
resource.enclosing_provider = enclosing_provider
|
||||
|
||||
# XXX: this is required for definition params inside of the scope of a
|
||||
# subresource to work correctly.
|
||||
resource.params = params
|
||||
|
||||
# Evaluate resource attribute DSL
|
||||
if block_given?
|
||||
resource.resource_initializing = true
|
||||
begin
|
||||
resource.instance_eval(&block)
|
||||
ensure
|
||||
resource.resource_initializing = false
|
||||
end
|
||||
end
|
||||
|
||||
# emit a cloned resource warning if it is warranted
|
||||
if prior_resource
|
||||
if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource)
|
||||
emit_harmless_cloning_debug
|
||||
else
|
||||
emit_cloned_resource_warning
|
||||
end
|
||||
end
|
||||
|
||||
# Run optional resource hook
|
||||
resource.after_created
|
||||
|
||||
resource
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resource_class
|
||||
# Checks the new platform => short_name => resource mapping initially
|
||||
# then fall back to the older approach (Chef::Resource.const_get) for
|
||||
# backward compatibility
|
||||
@resource_class ||= Chef::Resource.resource_for_node(type, run_context.node)
|
||||
end
|
||||
|
||||
def is_trivial_resource?(resource)
|
||||
trivial_resource = resource_class.new(name, run_context)
|
||||
# force un-lazy the name property on the created trivial resource
|
||||
name_property = resource_class.properties.find { |sym, p| p.name_property? }
|
||||
trivial_resource.send(name_property[0]) unless name_property.nil?
|
||||
identicalish_resources?(trivial_resource, resource)
|
||||
end
|
||||
|
||||
# this is an equality test specific to checking for 3694 cloning warnings
|
||||
def identicalish_resources?(first, second)
|
||||
skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ]
|
||||
checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars
|
||||
non_matching_ivars = checked_ivars.reject do |iv|
|
||||
if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] )
|
||||
# :nothing action on either side of the comparison always matches
|
||||
true
|
||||
else
|
||||
first.instance_variable_get(iv) == second.instance_variable_get(iv)
|
||||
end
|
||||
end
|
||||
Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}")
|
||||
non_matching_ivars.empty?
|
||||
end
|
||||
|
||||
def emit_cloned_resource_warning
|
||||
message = "Cloning resource attributes for #{resource} from prior resource (CHEF-3694)"
|
||||
message << "\nPrevious #{prior_resource}: #{prior_resource.source_line}" if prior_resource.source_line
|
||||
message << "\nCurrent #{resource}: #{resource.source_line}" if resource.source_line
|
||||
Chef.log_deprecation(message)
|
||||
end
|
||||
|
||||
def emit_harmless_cloning_debug
|
||||
Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}")
|
||||
end
|
||||
|
||||
def prior_resource
|
||||
@prior_resource ||=
|
||||
begin
|
||||
key = "#{type}[#{name}]"
|
||||
run_context.resource_collection.lookup_local(key)
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
require "chef_compat/copied_from_chef/chef/resource"
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user