Skip to content

Commit

Permalink
Config file scope (#151)
Browse files Browse the repository at this point in the history
* feat(config_file): Add the 'file' scope
* test(config_file): Add test for the new 'file' scope feature
* test(config_file): Add integration test for 'config_file'
* doc(config_file): Update the changelog to add 'config_file' feature
---------

Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
Co-authored-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
jmauro and damacus committed May 18, 2023
1 parent 633fe1d commit dde143d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add the 'file' scope

## 12.0.0 - *2023-05-18*

- Remove service resource
Expand Down
7 changes: 4 additions & 3 deletions resources/config.rb
Expand Up @@ -2,7 +2,8 @@

property :key, String, name_property: true
property :value, String
property :scope, String, equal_to: %w(local global system), default: 'global', desired_state: false
property :scope, String, equal_to: %w(local global system file), default: 'global', desired_state: false
property :config_file, String, desired_state: false
property :path, String, desired_state: false
property :user, String, desired_state: false
property :group, String, desired_state: false
Expand All @@ -18,7 +19,7 @@

cmd_env = user ? { 'USER' => user, 'HOME' => home_dir } : nil
config_vals = Mixlib::ShellOut.new(
"git config --get --#{scope} #{key}",
"git config --get --#{scope} #{config_file} #{key}",
user: user,
group: group,
password: password,
Expand Down Expand Up @@ -47,7 +48,7 @@

action_class do
def config_cmd
"git config --#{new_resource.scope}"
"git config --#{new_resource.scope} #{new_resource.config_file}"
end

def cmd_env
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/cookbooks/test/recipes/default.rb
Expand Up @@ -49,3 +49,9 @@
scope 'system'
options '--add'
end

git_config 'user.signingkey' do
value 'FA2D8E280A6DD5'
scope 'file'
config_file '~/.gitconfig.key'
end
4 changes: 4 additions & 0 deletions test/integration/resources/git_installed_spec.rb
Expand Up @@ -45,3 +45,7 @@
its(%w(user name)) { should eq 'John Doe system' }
its(['url "https://github.com/"', 'insteadOf']) { should eq 'git://github.com/' }
end

describe ini('/root/.gitconfig.key') do
its(%w(user signingkey)) { should eq 'FA2D8E280A6DD5' }
end

0 comments on commit dde143d

Please sign in to comment.