-
Notifications
You must be signed in to change notification settings - Fork 34
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
New module: SSH client #115
Comments
Hi @runsisi, probably so. I would guess you're most interested in having Risor be an SSH client, right? Looks like we should just be able to wrap Any chance you want to take a stab at the implementation? I could provide guidance as needed :-) |
I can look into this, if no one else is, @runsisi do you have any specific use cases in mind? |
hi @myzie i'm so sorry for delayed response, really busy these days :( hi @luisdavim , my use case is simple enough:
something like the code snippet: scpimport "github.com/bramvdbogaerde/go-scp"
func ScpFile(ctx context.Context, sshc *ssh.Client, r io.Reader, p string, perm os.FileMode) error {
scpc, err := scp.NewClientBySSH(sshc)
if err != nil {
return errors.New(err)
}
defer scpc.Close()
if err := scpc.CopyFile(ctx, r, p, "0"+strconv.FormatUint(uint64(perm), 8)); err != nil {
return errors.New(err)
}
return nil
}
func ScpContent(ctx context.Context, sshc *ssh.Client, r io.Reader, p string, perm os.FileMode, len int) error {
scpc, err := scp.NewClientBySSH(sshc)
if err != nil {
return errors.New(err)
}
defer scpc.Close()
if err := scpc.Copy(ctx, r, p, "0"+strconv.FormatUint(uint64(perm), 8), int64(len)); err != nil {
return errors.New(err)
}
return nil
} run commandfunc SshRunCommand(sshc *ssh.Client, cmdline string, out io.Writer) (string, string, error) {
sess, err := sshc.NewSession()
if err != nil {
return "", "", errors.New(err)
}
defer sess.Close()
if out == nil {
out = io.Discard
}
sob := &bytes.Buffer{}
seb := &bytes.Buffer{}
var sow io.Writer = sob
var sew io.Writer = seb
if out != nil {
sw := &singleWriter{
w: out,
}
sow = io.MultiWriter(sob, sw)
sew = io.MultiWriter(seb, sw)
}
sess.Stdout = sow
sess.Stderr = sew
if err := sess.Start(cmdline); err != nil {
return "", "", errors.New(err)
}
if err := sess.Wait(); err != nil {
return "", "", errors.New(err)
}
return strings.TrimSpace(sob.String()), strings.TrimSpace(sob.String()), nil
} |
Hi! I am using Risor for myself and would like to work on this issue. |
Hi @roopeshsn, to my knowledge no one has started on this yet. Go ahead and take a stab at it and I'm sure a couple of us will help with reviews. It seems like the main two cases are 1) an |
Thanks! I'll take a look at the code and reach back for queries. |
Hi @myzie! For SCP, there is a package called |
It's ok to depend on another library. When we do that, it needs to be a Risor module that has its own go.mod file. For example this would make it like the K8s module. https://github.com/risor-io/risor/blob/main/modules/kubernetes/go.mod |
i think ssh support is a must for devops, it is possible for risor?
thank you for your amazing work :)
The text was updated successfully, but these errors were encountered: