From dde143dc66f9657996440f9474e4e34173d24e1e Mon Sep 17 00:00:00 2001 From: Jeremy MAURO Date: Thu, 18 May 2023 15:39:45 +0200 Subject: [PATCH] Config file scope (#151) * 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 Co-authored-by: Dan Webb --- CHANGELOG.md | 2 ++ resources/config.rb | 7 ++++--- test/fixtures/cookbooks/test/recipes/default.rb | 6 ++++++ test/integration/resources/git_installed_spec.rb | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b57a203..c0d4a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/resources/config.rb b/resources/config.rb index 9bbb3a6..1ff0f7f 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -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 @@ -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, @@ -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 diff --git a/test/fixtures/cookbooks/test/recipes/default.rb b/test/fixtures/cookbooks/test/recipes/default.rb index fc6f89c..a8b17eb 100644 --- a/test/fixtures/cookbooks/test/recipes/default.rb +++ b/test/fixtures/cookbooks/test/recipes/default.rb @@ -49,3 +49,9 @@ scope 'system' options '--add' end + +git_config 'user.signingkey' do + value 'FA2D8E280A6DD5' + scope 'file' + config_file '~/.gitconfig.key' +end diff --git a/test/integration/resources/git_installed_spec.rb b/test/integration/resources/git_installed_spec.rb index 32f2621..4922aba 100644 --- a/test/integration/resources/git_installed_spec.rb +++ b/test/integration/resources/git_installed_spec.rb @@ -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