diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b42514..23d3a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [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) + \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 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