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 CopyFromRemote for io.Reader filesink #12

Closed
wants to merge 7 commits into from

Conversation

enmand
Copy link

@enmand enmand commented Jan 23, 2019

This PR introduces CopyFromRemote (from #1) which returns an io.Reader with the file contents, the remote file permissions (as an int) and an error if it occurred.

Closes #1

return errors.New("no scp cmd found")
}

func pipes(s *ssh.Session) (io.Reader, io.Reader, io.WriteCloser, error) {
Copy link
Author

Choose a reason for hiding this comment

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

pipes probably doesn't need to return stderr, but maybe it would be useful?

@enmand enmand force-pushed the improvements/filesink branch 2 times, most recently from 2cdceae to 8f1c139 Compare January 23, 2019 02:27
@bramvdbogaerde
Copy link
Owner

This looks very interesting.
I will try to review this by the end of the week.

@bramvdbogaerde bramvdbogaerde self-requested a review January 23, 2019 19:25
Copy link
Owner

@bramvdbogaerde bramvdbogaerde left a comment

Choose a reason for hiding this comment

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

About command.go:

I very much like the idea to represent the command itself as a struct.
However I am unsure about the format of the permissions.
I think they should be in octal base right?

Futhermore, converting the integers to a string is a bit redundant as the Sprintf function would happily take integers by using "%d", the same applies to octal representation by using "%o", however it is possible that you will need to zero pad that one on the left, so that 0777 is really converted to 0777.

Copy link
Owner

@bramvdbogaerde bramvdbogaerde left a comment

Choose a reason for hiding this comment

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

About the other file:

This is quite a lot of code.
I will take a look at it later this week.

@enmand
Copy link
Author

enmand commented Jan 24, 2019

However I am unsure about the format of the permissions.
I think they should be in octal base right?

Futhermore, converting the integers to a string is a bit redundant as the Sprintf function would happily take integers by using "%d", the same applies to octal representation by using "%o", however it is possible that you will need to zero pad that one on the left, so that 0777 is really converted to 0777.

Ah yeah -- good catch! I didn't use the MarshalText() so I didn't see that. Maybe I should add some tests too! 😄

client.go Outdated

var i int
for {
i = i + 1
Copy link
Author

Choose a reason for hiding this comment

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

This was debug code that can be removed now, along with the var i int

… error)

Add a CopyFromRemote which returns an io.Reader with the
contents of the remote file
@enmand enmand force-pushed the improvements/filesink branch from 0a77f33 to 05d2de4 Compare February 3, 2019 18:57
@enmand
Copy link
Author

enmand commented Feb 3, 2019

Hello! I've cleaned up the code to deal with permissions to use os.FileMode and properly use the octal representations, and added some tests for the Command Marshal and Unmarshal

@enmand enmand force-pushed the improvements/filesink branch from 05d2de4 to 525c0b1 Compare February 3, 2019 20:13
@enmand enmand force-pushed the improvements/filesink branch 2 times, most recently from b6becfb to dcca06c Compare February 3, 2019 20:36
@enmand enmand force-pushed the improvements/filesink branch from dcca06c to cda28e9 Compare February 3, 2019 20:39
@bramvdbogaerde
Copy link
Owner

I am sorry for the late response.
Many thanks for your contributions.

I will take a look at it next week.

@clarkezone
Copy link

any chance this will get merged soon?

@bramvdbogaerde
Copy link
Owner

Yes, @clarkezone, I will try to make time to look at the changes this week.

@hungarianguy
Copy link

@bramvdbogaerde @clarkezone is this something you plan to merge sometime soon?

@bramvdbogaerde
Copy link
Owner

bramvdbogaerde commented Jun 6, 2019

Indeed, it has been a while since this pull request was first created.

I think the idea is great, I do like the implementation but I have some small issues with some parts of the code, currently I don't have much time to carefully review the code and make some changes where necessary. I will try to do that by the end of the month.

@clarkezone
Copy link

Any updates on this?

@elie-g
Copy link

elie-g commented Aug 2, 2019

@bramvdbogaerde If you don't have time to maintain the project maybe you could add a new maintainer. If you don't know anyone interested in becoming the new maintainer, you can create an issue and ask who is interested. See this issue

@bramvdbogaerde
Copy link
Owner

I am sorry for my late response @DrunkenPoney, this project is certainly not dead, as can be demonstrated by my recent commits.

I plan to work on it more frequently now, and hope to have the suggested features added soon.

@ceprateek
Copy link

when is this change going to be merged ? This is a handy functionality which is needed.

@cpanato
Copy link

cpanato commented Nov 5, 2019

Hello Any plans to get this merged?

@ChadTaljaardt
Copy link

Is this PR dead?

@bramvdbogaerde
Copy link
Owner

I am sorry to keep you all waiting for so long.

I will try to review this pull request somewhere in the next few weeks and make
some adjustments to keep up with the current code base if necessary.

@tupyy
Copy link

tupyy commented May 14, 2020

Hello,

I'm playing around with this improvement because I need to write a lambda with is reading from a remote file.
It is working fine but the final size of the copied file is one byte bigger than the original size.
Could you explained me why please?

Thanks a lot.

@bramvdbogaerde
Copy link
Owner

At last, this was merged in PR #30, that PR has taken some inspiration from this PR, so many thanks for the changes here too.

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.

Allow Go library to act as an SCP sink
9 participants