fix parse token, return out in cmdexec run

This commit is contained in:
Pavel Sviderski
2024-09-06 15:52:27 +10:00
parent cfa2105684
commit f49e91b41f
2 changed files with 5 additions and 8 deletions
+3 -6
View File
@@ -30,19 +30,16 @@ func (r *Remote) Run(ctx context.Context, cmd string) (string, error) {
done := make(chan result)
go func() {
outBytes, outErr := session.CombinedOutput(cmd)
res := result{
done <- result{
out: strings.TrimSpace(string(outBytes)),
err: outErr,
}
if outErr == nil {
res.out = strings.TrimSpace(string(outBytes))
}
done <- res
}()
select {
case res := <-done:
if res.err != nil {
return "", fmt.Errorf("run command on remote host: %w", res.err)
return res.out, fmt.Errorf("run command on remote host: %w: %s", res.err, res.out)
}
return res.out, nil
case <-ctx.Done():
+2 -2
View File
@@ -29,8 +29,8 @@ func NewToken(publicKey secret.Secret, endpoints []netip.AddrPort) Token {
// ParseToken decodes a machine token from the given string.
func ParseToken(s string) (Token, error) {
if strings.HasPrefix(s, TokenPrefix) {
return Token{}, fmt.Errorf("invalid token prefix")
if !strings.HasPrefix(s, TokenPrefix) {
return Token{}, fmt.Errorf("invalid token prefix: %s", s)
}
decoded, err := base64.StdEncoding.DecodeString(s[len(TokenPrefix):])
if err != nil {