-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpusher_ssh.go
More file actions
80 lines (72 loc) · 2.1 KB
/
Copy pathpusher_ssh.go
File metadata and controls
80 lines (72 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package deploy
import (
"fmt"
"github.com/tinywasm/context"
"github.com/tinywasm/wizard"
)
func init() {
RegisterPusher(&SSHPusher{})
}
type SSHPusher struct{}
func (s *SSHPusher) Name() string { return "ssh" }
func (s *SSHPusher) Run(cfg *Config, p *Puller) error {
pat, err := p.Store.Get("DEPLOY_GITHUB_PAT")
if err != nil || pat == "" {
return fmt.Errorf("deploy: GitHub PAT not configured")
}
for _, app := range cfg.Apps {
script := SSHScript(app, "", pat)
p.logger("# SSH script for", app.Name+":\n"+script)
}
return nil
}
func (s *SSHPusher) WizardSteps(store Store, log func(...any)) []*wizard.Step {
return []*wizard.Step{
{
LabelText: "Server host (e.g. myserver.com)",
OnInputFn: func(input string, ctx *context.Context) (bool, error) {
if input == "" {
return false, fmt.Errorf("host cannot be empty")
}
ctx.Set(ctxServerHost, input)
return true, store.Set("DEPLOY_SERVER_HOST", input)
},
},
{
LabelText: "SSH username (e.g. deploy)",
OnInputFn: func(input string, ctx *context.Context) (bool, error) {
if input == "" {
return false, fmt.Errorf("SSH user cannot be empty")
}
ctx.Set(ctxSSHUser, input)
return true, store.Set("DEPLOY_SSH_USER", input)
},
},
{
LabelText: "SSH private key path (e.g. ~/.ssh/id_ed25519)",
OnInputFn: func(input string, ctx *context.Context) (bool, error) {
if input == "" {
return false, fmt.Errorf("SSH key path cannot be empty")
}
ctx.Set(ctxSSHKey, input)
return true, store.Set("DEPLOY_SSH_KEY", input)
},
},
{
LabelText: "GitHub PAT (ghp_... or github_pat_... — needs repo read access)",
OnInputFn: func(input string, ctx *context.Context) (bool, error) {
if input == "" {
return false, fmt.Errorf("PAT cannot be empty")
}
ctx.Set(ctxPAT, input)
if err := store.Set("DEPLOY_GITHUB_PAT", input); err != nil {
return false, err
}
host := ctx.Value(ctxServerHost)
user := ctx.Value(ctxSSHUser)
key := ctx.Value(ctxSSHKey)
return true, writeGHAWorkflow("ssh", host, fmt.Sprintf("user=%s key=%s", user, key))
},
},
}
}