Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knife client create should check file permissions #11241

Merged
merged 12 commits into from
Jul 28, 2021

Conversation

snehaldwivedi
Copy link
Contributor

Description

Support user-friendly error checking on file permissions for knife client create
knife user create is already covered in PR

Related Issue

#3514
#3517

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@snehaldwivedi snehaldwivedi requested review from a team as code owners March 25, 2021 13:45
@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch 3 times, most recently from 2db12b6 to 3b66e32 Compare March 26, 2021 04:50
if config[:file]
file = config[:file]
unless File.exist?(file) ? File.writable?(file) : File.writable?(File.dirname(file))
ui.fatal "File #{config[:file]} is not writable. Check permissions."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be two different conditionals with two different error messages. When the file does not exist and the directory is not writable the error message should be separate and there should really be two different conditionals here for readability.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch from aad0550 to e103941 Compare March 31, 2021 13:49
@tas50
Copy link
Contributor

tas50 commented Apr 1, 2021

@snehaldwivedi This will need to get rebased for the recent refactoring we did to knife.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch from e103941 to 944aee7 Compare April 5, 2021 06:01
@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch 2 times, most recently from 1a55a98 to 7e46d2a Compare May 7, 2021 12:29
exit 1
end

unless File.writable?(file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file does not exist, the File.writable? will return false:

capture_036

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if the file is writable then only it will return true else false. You can also go through documentation here. Now as per your example:

  1. File.writable?("does-not-exist") it has checked if the given file is writable or not and returns false as it doesn't exist.
  2. File.write("does-not-exist", "blah") it returns 4. Here it will create a new file "does-not-exist" and add a content "blah" can returns length of the content.
  3. File.writable?("does-not-exist") now after 2nd point where the file is not created now File.writable? is return true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is less functional, and more user experience - it is correct that the directory is not writable and the action should fail.

But in the case where the directory for /tmp/test/afile.out does not exist, we will report an error that Dir '/tmp/test/' is not writable. Check permissions. This is misleading, and we could provide more actionable feedback than "check permissions". It would be better to specifically verify that the directory exists and report that error independently of permissions-related errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcparadise Got your point. I Will update the condition accordingly.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch 3 times, most recently from f466976 to 7edc105 Compare June 24, 2021 08:08
@snehaldwivedi snehaldwivedi self-assigned this Jul 6, 2021
exit 1
end
else
ui.fatal "#{type} #{file} dose not exist."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "does not exist."

Copy link
Member

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This good and will be ready to merge once the typo (dose -> does) is fixed.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch 2 times, most recently from 7cac3b5 to 2bf5fb8 Compare July 9, 2021 08:03
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch from 2bf5fb8 to 6ea8158 Compare July 16, 2021 05:01
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
@snehaldwivedi snehaldwivedi force-pushed the snehal/Knife_client_create_should_check_file_permissions branch from 6ea8158 to fb087a1 Compare July 16, 2021 05:03
@tas50 tas50 changed the title Snehal/knife client create should check file permissions knife client create should check file permissions Jul 28, 2021
@tas50 tas50 merged commit 96e5907 into master Jul 28, 2021
@tas50 tas50 deleted the snehal/Knife_client_create_should_check_file_permissions branch July 28, 2021 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants