mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
fix parse token, return out in cmdexec run
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user