From 08901ec62a4a86c8cc397ac3f70b677a6ad47775 Mon Sep 17 00:00:00 2001 From: David Schmidt <43894937+DavidSchmidt00@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:04:55 +0200 Subject: [PATCH] Allow group and owner attributes of s3_file to be String or Integer (#476) * Allow group attribute of s3_file to be String or Integer As the resource remote_file allows type String or Integer for the group attribute, s3_file should do the same. (https://docs.chef.io/resources/remote_file/) Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: David Schmidt * Update dead link * Allow owner attribute of s3_file to be String or Integer As the resource remote_file allows type String or Integer for the owner attribute, s3_file should do the same. (https://docs.chef.io/resources/remote_file/) Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: David Schmidt --------- Signed-off-by: David Schmidt --- CHANGELOG.md | 4 ++- resources/s3_file.rb | 4 +-- .../cookbooks/aws_test/recipes/s3_file.rb | 26 +++++++++++++++++++ test/integration/s3_file/default_spec.rb | 9 +++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e11d415..96ea3c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the aws cookbook. ## Unreleased +Allow attributes group and owner of s3_file to be String or Integer + ## 9.0.16 - *2023-07-10* ## 9.0.15 - *2023-05-17* @@ -88,7 +90,7 @@ Update checkout to v3 in ci.yml ## 8.3.1 (2020-12-04) -- Resolve cookstyle warnings - [@cookstyle](https://github.com/cookstyle) +- Resolve cookstyle warnings - [@cookstyle](https://github.com/chef/cookstyle) - Update AWS S3 gem dependency - [@arothian](https://github.com/arothian) ## 8.3.0 (2020-08-06) diff --git a/resources/s3_file.rb b/resources/s3_file.rb index 11f49d4c..235ea2f7 100644 --- a/resources/s3_file.rb +++ b/resources/s3_file.rb @@ -4,8 +4,8 @@ property :region, String, default: lazy { fallback_region } property :bucket, String property :requester_pays, [true, false], default: false -property :owner, String, regex: Chef::Config[:user_valid_regex] -property :group, String, regex: Chef::Config[:group_valid_regex] +property :owner, [String, Integer], regex: Chef::Config[:user_valid_regex] +property :group, [String, Integer], regex: Chef::Config[:group_valid_regex] property :mode, [String, nil] property :checksum, [String, nil] property :backup, [Integer, false], default: 5 diff --git a/test/fixtures/cookbooks/aws_test/recipes/s3_file.rb b/test/fixtures/cookbooks/aws_test/recipes/s3_file.rb index 2b7bafb8..806c0ad2 100644 --- a/test/fixtures/cookbooks/aws_test/recipes/s3_file.rb +++ b/test/fixtures/cookbooks/aws_test/recipes/s3_file.rb @@ -50,3 +50,29 @@ aws_session_token node['aws_test']['session_token'] region 'us-west-2' end + +# create group to test if group property works +group 'testgroup' do + gid 4711 + action :create +end + +# create a s3_file with a group specified by its name +aws_s3_file '/tmp/file_with_group_by_name' do + bucket node['aws_test']['bucket'] + remote_path node['aws_test']['s3key'] + aws_access_key node['aws_test']['key_id'] + aws_secret_access_key node['aws_test']['access_key'] + aws_session_token node['aws_test']['session_token'] + group 'testgroup' +end + +# create a s3_file with a group specified by its gid +aws_s3_file '/tmp/file_with_group_by_gid' do + bucket node['aws_test']['bucket'] + remote_path node['aws_test']['s3key'] + aws_access_key node['aws_test']['key_id'] + aws_secret_access_key node['aws_test']['access_key'] + aws_session_token node['aws_test']['session_token'] + group 4712 +end diff --git a/test/integration/s3_file/default_spec.rb b/test/integration/s3_file/default_spec.rb index 58885623..28b13c14 100644 --- a/test/integration/s3_file/default_spec.rb +++ b/test/integration/s3_file/default_spec.rb @@ -9,3 +9,12 @@ describe file('/tmp/a_file') do it { should be_file } end + +describe file('/tmp/file_with_group_by_name') do + it { should be_file } + its('group') { should eq 'testgroup' } +end + +describe file('/tmp/file_with_group_by_gid') do + it { should be_file } +end