Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Check if user exists for data bag #3

Merged
merged 3 commits into from
Aug 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)*
2 changes: 1 addition & 1 deletion resources/config_users_from_data_bag.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion spec/resources/config_users_from_data_bag_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/fixtures/data_bags/users/not_exist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "not-exist",
"codenamephp": {
"git_client": {
"config": {
"user.name": "egal",
"user.email": "egal@test.de"
}
}
}
}