Skip to content

Commit 6ed2caf

Browse files
authored
Use Resource Partials (#302)
- Add resource partials for git and common (users and root path helper) - Bump Chef version to 16 for partials
1 parent 839cbe9 commit 6ed2caf

18 files changed

+241
-129
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- Add resource partials for git and common (users and root path helper)
8+
- Bump Chef version to 16 for partials
9+
710
## 4.0.1 - *2021-08-30*
811

912
- Standardise files with files in sous-chefs/repo-management

documentation/resources/rbenv_gem.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ Used to install a gem into the selected rbenv environment.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| ---------------------- | ----------------- | -------------------- | ------------------------------------------ |
9-
| clear_sources | `true', 'false` | `true, false` | |
10-
| include_default_source | `true', 'false` | `true` | |
11-
| ignore_failure | `true', 'false` | `false` | |
12-
| options | `String`, `Hash` | | Options to pass to the gem command. |
13-
| package_name | `String`, `Array` | | |
14-
| source | `String`, `Array` | | Source URL/location for gem. |
15-
| timeout | `Integer` | `300` | Gem install timeout. |
16-
| version | `String` | | Gem version to install. |
17-
| response_file | `String` | | Response file to reconfigure a gem. |
18-
| user | `String` | | Which user to install gem to. |
19-
| rbenv_version | `String` | | Which rbenv version to install the gem to. |
20-
| root_path | `String` | See root_path helper | |
7+
| Name | Type | Default | Description |
8+
| ---------------------- | ----------------- | -------------------- | ----------------------------------------------------------------------- |
9+
| clear_sources | `true', 'false` | `true, false` | |
10+
| include_default_source | `true', 'false` | `true` | Set to false to not include Chef::Config[:rubygems_url] in the sources. |
11+
| ignore_failure | `true', 'false` | `false` | Continue running a recipe if a resource fails for any reason. |
12+
| options | `String`, `Hash` | | Options to pass to the gem command. |
13+
| package_name | `String`, `Array` | | The Gem package name to install. |
14+
| source | `String`, `Array` | | Source URL/location for gem. |
15+
| timeout | `Integer` | `300` | Timeout in seconds to wait for Gem installation. |
16+
| version | `String` | | Gem version to install. |
17+
| response_file | `String` | | Response file to reconfigure a gem. |
18+
| rbenv_version | `String` | | Which rbenv version to install the Gem to. |
19+
| user | `String` | | Which user to install gem to. |
20+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
2121

2222
## Example
2323

documentation/resources/rbenv_global.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Sets the global ruby version. The name of the resource is the version to set.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| ------------- | -------- | -------------------- | ----------- |
9-
| rbenv_version | `String` | | |
10-
| user | `String` | | |
11-
| root_path | `String` | See root_path helper | |
7+
| Name | Type | Default | Description |
8+
| ------------- | -------- | -------------------- | ---------------------------------- |
9+
| rbenv_version | `String` | | Version to set as the global Ruby. |
10+
| user | `String` | | Username to run the script as. |
11+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
1212

1313
## Examples
1414

documentation/resources/rbenv_plugin.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ If user is passed in, the plugin is installed to the users install of rbenv.
55

66
## Properties
77

8-
| Name | Type | Default | Description |
9-
| --------- | -------- | -------------------- | ----------- |
10-
| git_url | `String` | | |
11-
| git_ref | `String` | `master` | |
12-
| user | `String` | | |
13-
| root_path | `String` | See root_path helper | |
8+
| Name | Type | Default | Description |
9+
| --------- | -------- | -------------------- | ------------------------------------------------------------ |
10+
| git_url | `String` | | Git URL to download the plugin from. |
11+
| git_ref | `String` | `master` | Git reference to download, can be a SHA, tag or branch name. |
12+
| user | `String` | | Username to run the script as. |
13+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
1414

1515
## Example
1616

documentation/resources/rbenv_rehash.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ If user is passed in, the user Ruby is rehashed rather than the system Ruby.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| --------- | -------- | -------------------- | ----------- |
9-
| user | `String` | | |
10-
| root_path | `String` | See root_path helper | |
7+
| Name | Type | Default | Description |
8+
| --------- | -------- | -------------------- | ------------------------------ |
9+
| user | `String` | | Username to run the script as. |
10+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
1111

1212
## Example
1313

documentation/resources/rbenv_ruby.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ Installs a given Ruby version to the system or user location.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| ------------------ | --------------- | ------------------------------------------ | ----------- |
9-
| user | `String` | | |
10-
| version | `String` | | |
11-
| version_file | `String` | | |
12-
| user | `String` | | |
13-
| environment | `Hash` | | |
14-
| rbenv_action | `String` | `install` | |
15-
| verbose | `true`, `false` | `false` | |
16-
| ruby_build_git_url | `String` | `https://github.com/rbenv/ruby-build.git>` |
17-
| root_path | `String` | See root_path helper | |
7+
| Name | Type | Default | Description |
8+
| ------------------ | --------------- | ----------------------------------------- | --------------------------------------- |
9+
| version | `String` | | Ruby version to install. |
10+
| environment | `Hash` | | Environment to pass to the Ruby script. |
11+
| rbenv_action | `String` | `install` | Action to pass to rbenv. |
12+
| verbose | `true`, `false` | `false` | Build Ruby with verbose output. |
13+
| ruby_build_git_url | `String` | `https://github.com/rbenv/ruby-build.git` | Git URL for Ruby build. |
14+
| user | `String` | | Username to run the script as. |
15+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
1816

1917
## Examples
2018

documentation/resources/rbenv_script.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ Runs a rbenv aware script.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| ------------- | ------------------- | -------------------- | ----------- |
9-
| user | `String` | | |
10-
| root_path | `String` | See root_path helper | |
11-
| rbenv_version | `String` | | |
12-
| code | `String` | | |
13-
| creates | `String` | | |
14-
| cwd | `String` | | |
15-
| environment | `Hash` | | |
16-
| group | `String` | | |
17-
| path | `Array` | | |
18-
| returns | `Array` | `[0]` | |
19-
| timeout | `Integer` | | |
20-
| umask | `String`, `Integer` | | |
21-
| live_stream | `true`, `false` | `false` |
7+
| Name | Type | Default | Description |
8+
| ------------- | ------------------- | -------------------- | ---------------------------------------------------------------------------- |
9+
| rbenv_version | `String` | | Ruby version to run the script on. |
10+
| code | `String` | | Script code to run. |
11+
| creates | `String` | | Prevent the script from creating a file when that file already exists. |
12+
| cwd | `String` | | The current working directory from which the command will be run. |
13+
| environment | `Hash` | | A Hash of environment variables in the form of ({"ENV_VARIABLE" => "VALUE"}) |
14+
| group | `String` | | The group ID to run the command as. |
15+
| path | `Array` | | Path to add to environment. |
16+
| returns | `Array` | `[0]` | The return value for a command. This may be an array of accepted values. |
17+
| timeout | `Integer` | | The amount of time (in seconds) to wait for the script to complete. |
18+
| umask | `String`, `Integer` | | The file mode creation mask, or umask. |
19+
| live_stream | `true`, `false` | `false` | Live stream the output from the script to the console. |
20+
| user | `String` | | Username to run the script as. |
21+
| root_path | `String` | See root_path helper | Path to install Ruby to. |
2222

2323
## Examples
2424

documentation/resources/rbenv_user_install.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Installs rbenv to the user path, making rbenv available to that user only.
44

55
## Properties
66

7-
| Name | Type | Default | Description |
8-
| ------------ | --------------- | ------------------------------------ | ----------- |
9-
| git_url | `String` | `https://github.com/rbenv/rbenv.git` | |
10-
| git_ref | `String` | `master` | |
11-
| user | `String` | | |
12-
| group | `String` | user | |
13-
| home_dir | `String` | `::File.expand_path("~#{user}")` | |
14-
| user_prefix | `String` | `::File.join(home_dir, '.rbenv')` | |
15-
| update_rbenv | `true`, `false` | `true` | |
7+
| Name | Type | Default | Description |
8+
| ------------ | --------------- | ------------------------------------ | ------------------------------------------------------------ |
9+
| git_url | `String` | `https://github.com/rbenv/rbenv.git` | Git URL to rbenv from. |
10+
| git_ref | `String` | `master` | Git reference to download, can be a SHA, tag or branch name. |
11+
| user | `String` | | User to install the Ruby to. |
12+
| group | `String` | user | Group to create the resources with. |
13+
| home_dir | `String` | `::File.expand_path("~#{user}")` | Directory to point user_prefix to. |
14+
| user_prefix | `String` | `::File.join(home_dir, '.rbenv')` | Location to install Ruby. |
15+
| update_rbenv | `true`, `false` | `true` | Update rbenv definitions. |
1616

1717
## Examples
1818

metadata.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
license 'Apache-2.0'
77
description 'Manages rbenv and installs Rbenv based Rubies'
88
version '4.0.1'
9-
chef_version '>= 15.3'
9+
chef_version '>= 16.0'
1010

1111
supports 'amazon'
1212
supports 'centos'

resources/_partial/_git.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
property :git_url,
2+
String,
3+
default: 'https://github.com/rbenv/rbenv.git',
4+
description: 'Git URL to download the plugin from.'
5+
6+
property :git_ref,
7+
String,
8+
default: 'master',
9+
description: 'Git reference to download, can be a SHA, tag or branch name.'

resources/gem.rb

+45-12
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,53 @@
2323

2424
provides :rbenv_gem
2525
unified_mode true
26+
use '_partial/_common'
2627
# Standard Gem Package Options
2728
# https://docs.chef.io/resource_gem_package.html#properties
28-
property :clear_sources, [true, false]
29-
property :include_default_source, [true, false], default: true
30-
property :ignore_failure, [true, false], default: false
31-
property :options, [String, Hash]
32-
property :package_name, [String, Array], name_property: true
33-
property :source, [String, Array]
34-
property :timeout, Integer, default: 300
35-
property :version, String
36-
property :response_file, String # Only used to reconfigure
37-
property :rbenv_version, String, required: true
38-
property :user, String
39-
property :root_path, String, default: lazy { Chef::Rbenv::Helpers.root_path(node, user) }
29+
property :clear_sources,
30+
[true, false],
31+
description: 'Clear the gem sources.'
32+
33+
property :include_default_source,
34+
[true, false],
35+
default: true,
36+
description: 'Set to false to not include Chef::Config[:rubygems_url] in the sources.'
37+
38+
property :ignore_failure,
39+
[true, false],
40+
default: false,
41+
description: 'Continue running a recipe if a resource fails for any reason.'
42+
43+
property :options,
44+
[String, Hash],
45+
description: 'Options to pass to the gem command.'
46+
47+
property :package_name,
48+
[String, Array],
49+
name_property: true,
50+
description: 'The Gem package name to install.'
51+
52+
property :source,
53+
[String, Array],
54+
description: 'Source URL/location for gem.'
55+
56+
property :timeout,
57+
Integer,
58+
default: 300,
59+
description: 'Timeout in seconds to wait for Gem installation.'
60+
61+
property :version,
62+
String,
63+
description: 'Gem version to install.'
64+
65+
property :response_file,
66+
String,
67+
description: 'Response file to reconfigure a gem.'
68+
69+
property :rbenv_version,
70+
String,
71+
required: true,
72+
description: 'Which rbenv version to install the Gem to.'
4073

4174
default_action :install
4275

resources/global.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@
2020
# See the License for the specific language governing permissions and
2121
# limitations under the License.
2222
#
23-
24-
# Check for the user or system global verison
25-
# If we pass in a user check that users global
26-
2723
provides :rbenv_global
2824
unified_mode true
29-
# use '_partial/_common'
25+
use '_partial/_common'
3026

31-
property :rbenv_version, String, name_property: true
32-
property :user, String
33-
property :root_path, String, default: lazy { Chef::Rbenv::Helpers.root_path(node, user) }
27+
property :rbenv_version,
28+
String,
29+
name_property: true,
30+
description: 'Version to set as the global Ruby.'
3431

3532
# This sets the Global rbenv version
3633
# e.g. "rbenv global" should return the version we set

resources/plugin.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
#
2121
provides :rbenv_plugin
2222
unified_mode true
23-
# use '_partial/_common'
23+
use '_partial/_common'
2424

25-
property :git_url, String, required: true
26-
property :git_ref, String, default: 'master'
27-
property :user, String
28-
property :root_path, String, default: lazy { Chef::Rbenv::Helpers.root_path(node, user) }
25+
property :git_url,
26+
String,
27+
required: true,
28+
description: 'Git URL to download the plugin from'
29+
30+
property :git_ref,
31+
String,
32+
default: 'master',
33+
description: 'Git reference to download, can be a SHA, tag or branch name'
2934

3035
# https://github.com/rbenv/rbenv/wiki/Plugins
3136
action :install do

resources/rehash.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
#
2323
provides :rbenv_rehash
2424
unified_mode true
25-
# use '_partial/_common'
26-
27-
property :user, String
28-
property :root_path, String, default: lazy { Chef::Rbenv::Helpers.root_path(node, user) }
25+
use '_partial/_common'
2926

3027
action :run do
3128
rbenv_script "rbenv rehash #{which_rbenv}" do

0 commit comments

Comments
 (0)