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

Implement upload/download for connections #664

Merged
merged 2 commits into from
Feb 22, 2021

Conversation

thheinen
Copy link
Contributor

Adds default upload/download methods to transfer files. Also adds a content= method for remote file manipulation.

Description

While the SSH and the WinRM transport plugin already implemented the upload/download methods, those were not part of the general plugin API.

Offering these two methods and general file manipulation capabilities greatly extends any tool built on Train (e.g. Chef Target Mode).

On base_connection, the upload method iterates using the new content= method which uses base64 en-/decoding on Unix/Windows platforms. The local transport got simple local file manipulations for this, the cisco_ios_connectionwill throw an error. Can't test QNX/AIX, sorry.

I actually prepared both a Test Kitchen "train" transport and a remote shell utility based on this and it's working fine with my Linux/Windows systems. So I suppose the same goes for any other transport (AWS Systems Manager, VMware GOM etc).

Related Issue

none

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

@thheinen thheinen requested a review from a team as a code owner February 11, 2021 10:12
@chef-expeditor
Copy link
Contributor

Hello tecracer-theinen! Thanks for the pull request!

Here is what will happen next:

  1. Your PR will be reviewed by the maintainers.
  2. Possible Outcomes
    a. If everything looks good, one of them will approve it, and your PR will be merged.
    b. The maintainer may request follow-on work (e.g. code fix, linting, etc). We would encourage you to address this work in 2-3 business days to keep the conversation going and to get your contribution in sooner.
    c. Cases exist where a PR is neither aligned to Chef InSpec's product roadmap, or something the team can own or maintain long-term. In these cases, the maintainer will provide justification and close out the PR.

Thank you for contributing!

@thheinen
Copy link
Contributor Author

thheinen commented Feb 11, 2021

Definitively need help with the content= test in lib/train/transports/mock.rb - I don't understand that one 😅

@@ -24,7 +24,7 @@ def sanitize_filename(_path)
# interface methods: these fields should be implemented by every
# backend File
DATA_FIELDS = %w{
exist? mode owner group uid gid content mtime size selinux_label path
exist? mode owner group uid gid content content= mtime size selinux_label path
Copy link
Contributor

Choose a reason for hiding this comment

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

I found that if you rename the method to be set_content, you can avoid the name issue, but then you encounter arity issues in that all of the other data fields are expected to be called with no arguments. If the new method is omitted from the DATA_FIELDS list - it is not really a data field, it is a setter - and instead treated as an abstract method, the tests pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was an easy fix. Thank you!

Signed-off-by: Thomas Heinen <[email protected]>
@clintoncwolfe clintoncwolfe merged commit 702ea32 into inspec:master Feb 22, 2021
@thheinen thheinen deleted the feature/file-write branch February 23, 2021 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants