|
1 | 1 | # Chef Cookbook
|
2 | 2 | [](https://github.com/codenamephp/chef.cookbook.gitClient/actions/workflows/ci.yml)
|
| 3 | + |
| 4 | +## Usage |
| 5 | + |
| 6 | +Just include this cookbook in a wrapper cookbook and use the resources as you see fit. Just make sure you install git before you use any of the resources that use it |
| 7 | +since they assume it is installed. You can of course use the `codenamephp_git_client_package` resource for this. |
| 8 | + |
| 9 | +## Resources |
| 10 | +### package |
| 11 | +The `codenamephp_git_client_package` resource installs the package using a package manager. |
| 12 | + |
| 13 | +#### Actions |
| 14 | +- `:install`: Installs the git client using a package manager. |
| 15 | + |
| 16 | +#### Properties |
| 17 | +- `package_name`: The name of the package to install, defaults to `'git'` |
| 18 | + |
| 19 | +#### Examples |
| 20 | +```ruby |
| 21 | +# Minimal properties |
| 22 | +codenamephp_git_client_package 'Install git' |
| 23 | + |
| 24 | +# With custom package name |
| 25 | +codenamephp_git_client_package 'Install git' do |
| 26 | + package_name 'some package' |
| 27 | +end |
| 28 | +``` |
| 29 | + |
| 30 | +### config |
| 31 | +The `codenamephp_git_client_config` resource is used to set configurations through `git config`. It supports system wide, user global and per-repo configurations. |
| 32 | + |
| 33 | +#### Actions |
| 34 | +- `set`: Sets the given config |
| 35 | + |
| 36 | +#### Properties |
| 37 | +- `key`: The key of config to set, e.g. user.full_name, defaults to the resource name |
| 38 | +- `value`: The config value to set |
| 39 | +- `user`: The user to run the command as |
| 40 | +- `scope`: The scope to set the config for, one of `local global system`, defaults to global |
| 41 | +- `path`: The path to run the command in, needed when setting per-repo settings, defaults to empty string |
| 42 | +- `options`: Additional options that will be appended to the command, defaults to empty string |
| 43 | + |
| 44 | +#### Exmaples |
| 45 | +```ruby |
| 46 | +# Minimal properties |
| 47 | +codenamephp_git_client_config 'user.full_name' do |
| 48 | + value 'Some User' |
| 49 | + user 'someuser' |
| 50 | +end |
| 51 | + |
| 52 | +# All properties |
| 53 | +codenamephp_git_client_config 'Set some config' do |
| 54 | + key 'some config' |
| 55 | + value 'some value' |
| 56 | + user 'someuser' |
| 57 | + scope 'local' |
| 58 | + path '/some/path' |
| 59 | + options '--some-options' |
| 60 | +end |
| 61 | +``` |
| 62 | + |
| 63 | +### config_user |
| 64 | +The `codenamephp_git_client_config_user` is used to configure multiple values for a single user using a hash where the keys are the config keys and values the configs to be set for their keys. |
| 65 | +The configs are all set in the --global scope. |
| 66 | +Uses `codenamephp_git_client_config` internally. |
| 67 | + |
| 68 | +#### Actions |
| 69 | +- `:set`: Sets the given configs for the given user |
| 70 | + |
| 71 | +#### Properties |
| 72 | +- `user`: The user to execute the command as and to set the configs for |
| 73 | +- `configs`: A hash with the config keys and their values |
| 74 | + |
| 75 | +#### Examples |
| 76 | +```ruby |
| 77 | +# Minimal properties |
| 78 | +codenamephp_git_client_config_user 'Set configs for user' do |
| 79 | + user 'some user' |
| 80 | + configs lazy { { 'user.full_name' => 'Test User', 'user.email' => 'test@test.de' } } |
| 81 | +end |
| 82 | +``` |
| 83 | + |
| 84 | +### config_users |
| 85 | +The `codenamephp_git_client_config_users` is used to configure multiple configs for multiple users at once. The configs are passed as a Hash with the username as key and another Hash with config name => config value pairs. |
| 86 | +Uses `codenamephp_git_client_config_user` internally. |
| 87 | + |
| 88 | +#### Actions |
| 89 | +- `:set`: Sets the given configs for the given users |
| 90 | + |
| 91 | +#### Properties |
| 92 | +- `users_configs`: A Hash with the username as key and another Hash with config name => config value pairs. |
| 93 | + |
| 94 | +#### Examples |
| 95 | +```ruby |
| 96 | +# Minimal properties |
| 97 | +codenamephp_git_client_config_users 'Config user' do |
| 98 | + users_configs lazy { |
| 99 | + { |
| 100 | + 'user1' => { :config1_user1 => 'value1_user1', 'config2_user1' => 'value2_user1' }, |
| 101 | + 'user2' => { :config1_user2 => 'value1_user2', 'config2_user2' => 'value2_user2' }, |
| 102 | + } |
| 103 | + } |
| 104 | +end |
| 105 | +``` |
| 106 | + |
| 107 | +### config_users_from_data_bag |
| 108 | +The `config_users_from_data_bag` resource can be used to set git configurations from data bags. The configs have to be set in the user item. Example: |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "id": "user", |
| 113 | + "codenamephp": { |
| 114 | + "git_client": { |
| 115 | + "config": { |
| 116 | + "user.full_name": "Test User", |
| 117 | + "user.email": "test@test.de" |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +Only users that have a non-empty config set are used. |
| 125 | + |
| 126 | +#### Actions |
| 127 | +- `manage`: Manages the configs from the data bag |
| 128 | + |
| 129 | +#### Properties |
| 130 | +- `data_bag_name`: The name of the data bag to search for users, defaults to `users` |
| 131 | + |
| 132 | +#### Examples |
| 133 | + |
| 134 | +```ruby |
| 135 | +# Minimal properties |
| 136 | +codenamephp_git_client_config_users_from_data_bag 'Manage git users' |
| 137 | + |
| 138 | +# With custom data_bag_name |
| 139 | +codenamephp_git_client_config_users_from_data_bag 'Manage git users' do |
| 140 | + data_bag_name 'some_data_bag' |
| 141 | +end |
| 142 | +``` |
0 commit comments