Skip to content

Commit 97229f8

Browse files
committed
feat(update): update
update Signed-off-by: ysicing <i@ysicing.me>
1 parent d323dbd commit 97229f8

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

cmd/upgrade/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (up option) DoTiGA() {
6767
up.log.Errorf("upgrade failed, reason: %v", err)
6868
return
6969
}
70-
up.log.Donef("Successfully updated tiga to version %s", lastVersion)
70+
up.log.Donef("updated tiga to version %s", lastVersion)
7171
up.log.Debugf("gen new version manifest")
7272
up.log.Infof("Release note: \n\t release %s ", lastVersion)
7373
up.log.Infof("Upgrade docs: \n\t https://github.com/ysicing/tiga/releases")

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ require (
9898
github.com/xlab/treeprint v1.1.0 // indirect
9999
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
100100
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
101-
golang.org/x/crypto v0.8.0 // indirect
101+
golang.org/x/crypto v0.9.0 // indirect
102102
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
103103
golang.org/x/mod v0.9.0 // indirect
104-
golang.org/x/net v0.9.0 // indirect
104+
golang.org/x/net v0.10.0 // indirect
105105
golang.org/x/oauth2 v0.7.0 // indirect
106106
golang.org/x/sync v0.1.0 // indirect
107107
golang.org/x/sys v0.8.0 // indirect

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
402402
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
403403
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
404404
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
405+
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
406+
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
405407
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
406408
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
407409
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
@@ -435,6 +437,7 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
435437
golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
436438
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
437439
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
440+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
438441
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
439442
golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g=
440443
golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4=

internal/pkg/ssh/ssh.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) 2023 ysicing(ysicing.me, ysicing@ysicing.cloud) All rights reserved.
2+
// Use of this source code is covered by the following dual licenses:
3+
// (1) Y PUBLIC LICENSE 1.0 (YPL 1.0)
4+
// (2) Affero General Public License 3.0 (AGPL 3.0)
5+
// License that can be found in the LICENSE file.
6+
7+
package ssh
8+
9+
import (
10+
"bytes"
11+
"context"
12+
"github.com/cockroachdb/errors"
13+
"golang.org/x/crypto/ssh"
14+
"io"
15+
"k8s.io/apimachinery/pkg/util/wait"
16+
"time"
17+
)
18+
19+
var defaultBackoff = wait.Backoff{
20+
Duration: 15 * time.Second,
21+
Factor: 1,
22+
Steps: 5,
23+
}
24+
25+
type SSH struct {
26+
SSHPort string `json:"ssh-port,omitempty" yaml:"ssh-port,omitempty" default:"22"`
27+
SSHUser string `json:"ssh-user,omitempty" yaml:"ssh-user,omitempty" default:"root"`
28+
SSHPassword string `json:"ssh-password,omitempty" yaml:"ssh-password,omitempty"`
29+
SSHKey string `json:"ssh-key,omitempty" yaml:"ssh-key,omitempty" wrangler:"writeOnly,nullable"`
30+
}
31+
32+
type Node struct {
33+
SSH `json:",inline"`
34+
PublicIPAddress []string `json:"public-ip-address,omitempty" yaml:"public-ip-address,omitempty"`
35+
}
36+
37+
// SSHDialer is a dialer that uses SSH to connect to a remote host.
38+
type SSHDialer struct {
39+
sshKey string
40+
sshCert string
41+
sshAddress string
42+
username string
43+
password string
44+
passphrase string
45+
46+
Stdin io.ReadCloser
47+
Stdout io.Writer
48+
Stderr io.Writer
49+
Writer io.Writer
50+
51+
Height int
52+
Weight int
53+
54+
Term string
55+
Modes ssh.TerminalModes
56+
57+
ctx context.Context
58+
conn *ssh.Client
59+
session *ssh.Session
60+
cmd *bytes.Buffer
61+
62+
err error
63+
}
64+
65+
func NewSSHDialer(n *Node, timeout bool) (*SSHDialer, error) {
66+
if len(n.PublicIPAddress) == 0 {
67+
return nil, errors.New("no ip address")
68+
}
69+
d := &SSHDialer{
70+
username: n.SSHUser,
71+
password: n.SSHPassword,
72+
passphrase: n.SSHPassword,
73+
sshKey: n.SSHKey,
74+
ctx: context.Background(),
75+
}
76+
return d, nil
77+
}
78+
79+
// Dial handshake with ssh address.
80+
func (d *SSHDialer) Dial(t bool) (*ssh.Client, error) {
81+
timeout := defaultBackoff.Duration
82+
if !t {
83+
timeout = 0
84+
}
85+
86+
cfg, err := utils.GetSSHConfig(d.username, d.sshKey, d.passphrase, d.sshCert, d.password, timeout, d.useSSHAgentAuth)
87+
if err != nil {
88+
return nil, err
89+
}
90+
// establish connection with SSH server.
91+
return ssh.Dial("tcp", d.sshAddress, cfg)
92+
}

0 commit comments

Comments
 (0)