diff --git a/CHANGELOG.md b/CHANGELOG.md index 23d3a4b..b38d6f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.1.0](https://github.com/codenamephp/chef.cookbook.gitClient/tree/1.1.0) (2021-08-22) + +[Full Changelog](https://github.com/codenamephp/chef.cookbook.gitClient/compare/1.0.0...1.1.0) + +**Implemented enhancements:** + +- Check if user exists for data bag [\#3](https://github.com/codenamephp/chef.cookbook.gitClient/pull/3) ([bastianschwarz](https://github.com/bastianschwarz)) + ## [1.0.0](https://github.com/codenamephp/chef.cookbook.gitClient/tree/1.0.0) (2021-08-21) [Full Changelog](https://github.com/codenamephp/chef.cookbook.gitClient/compare/24fa20cfaa7dd71dc034ab6de7ea7507f79d8477...1.0.0) diff --git a/metadata.rb b/metadata.rb index 1ecea16..40b01c2 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ maintainer_email 'bastian@codename-php.de' license 'Apache-2.0' description 'Cookbook to install apache2' -version '1.0.0' +version '1.1.0' chef_version '>= 15.3' issues_url 'https://github.com/codenamephp/chef.cookbook.gitClient/issues' source_url 'https://github.com/codenamephp/chef.cookbook.gitClient' diff --git a/resources/config_users_from_data_bag.rb b/resources/config_users_from_data_bag.rb index 6b96bf2..1562ba8 100644 --- a/resources/config_users_from_data_bag.rb +++ b/resources/config_users_from_data_bag.rb @@ -6,7 +6,7 @@ begin users_configs = search(new_resource.data_bag_name, 'codenamephp_git_client_config*:*') .to_h { |user| [user[:id], user.dig(:codenamephp, :git_client, :config) || {}] } - .select { |_, configs| !configs.nil? && !configs.empty? } + .select { |username, configs| !configs.nil? && !configs.empty? && !shell_out("getent passwd #{username}").error? } codenamephp_git_client_config_users 'Config users from databag' do users_configs users_configs diff --git a/spec/resources/config_users_from_data_bag_spec.rb b/spec/resources/config_users_from_data_bag_spec.rb index cc5c228..d6d9cc5 100644 --- a/spec/resources/config_users_from_data_bag_spec.rb +++ b/spec/resources/config_users_from_data_bag_spec.rb @@ -24,7 +24,9 @@ 'id' => 'user2', 'codenamephp' => { 'git_client' => { - 'config' => {}, + 'config' => { + 'config' => { 'user2_config1' => 'user2_value1', 'user2_config2' => 'user2_value2' }, + }, }, }, }, @@ -45,6 +47,14 @@ ]) end + stubs_for_provider('codenamephp_git_client_config_users_from_data_bag[Manage git users]') do |provider| + allow(provider).to receive_shell_out() + allow(provider).to receive_shell_out('getent passwd user1', exitstatus: 0) + allow(provider).to receive_shell_out('getent passwd user2', exitstatus: 1) + allow(provider).to receive_shell_out('getent passwd user3', exitstatus: 0) + allow(provider).to receive_shell_out('getent passwd user4', exitstatus: 0) + end + recipe do codenamephp_git_client_config_users_from_data_bag 'Manage git users' end diff --git a/test/fixtures/data_bags/users/not_exist.json b/test/fixtures/data_bags/users/not_exist.json new file mode 100644 index 0000000..64fe79a --- /dev/null +++ b/test/fixtures/data_bags/users/not_exist.json @@ -0,0 +1,11 @@ +{ + "id": "not-exist", + "codenamephp": { + "git_client": { + "config": { + "user.name": "egal", + "user.email": "egal@test.de" + } + } + } +} \ No newline at end of file