generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 16
/
tasks.go
85 lines (74 loc) · 2.13 KB
/
tasks.go
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
81
82
83
84
85
package ssh
import (
"github.com/brevdev/brev-cli/pkg/autostartconf"
"github.com/brevdev/brev-cli/pkg/entity"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/tasks"
)
type SSHConfigurerTaskStore interface {
ConfigUpdaterStore
SSHConfigurerV2Store
GetCurrentUserKeys() (*entity.UserKeys, error)
}
type SSHConfigurerTask struct {
Store SSHConfigurerTaskStore
runRemoteCMD bool
}
var _ tasks.Task = SSHConfigurerTask{}
func (sct SSHConfigurerTask) GetTaskSpec() tasks.TaskSpec {
return tasks.TaskSpec{RunCronImmediately: true, Cron: "@every 3s"}
}
func (sct SSHConfigurerTask) Run() error {
configs, err := GetSSHConfigs(sct.Store, sct.runRemoteCMD)
if err != nil {
return breverrors.WrapAndTrace(err)
}
keys, err := sct.Store.GetCurrentUserKeys()
if err != nil {
return breverrors.WrapAndTrace(err)
}
cu := NewConfigUpdater(sct.Store, configs, keys.PrivateKey)
err = tasks.RunTasks([]tasks.Task{cu})
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
}
func (sct SSHConfigurerTask) Configure() error {
daemonConfigurer := autostartconf.NewSSHConfigurer(sct.Store)
err := daemonConfigurer.Install()
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
}
func NewSSHConfigurerTask(store SSHConfigurerTaskStore, runRemoteCMD bool) SSHConfigurerTask {
return SSHConfigurerTask{
Store: store,
runRemoteCMD: runRemoteCMD,
}
}
func GetSSHConfigs(store SSHConfigurerTaskStore, runRemoteCMD bool) ([]Config, error) {
// // user, err := store.GetCurrentUser()
// if err != nil {
// return nil, breverrors.WrapAndTrace(err)
// }
configs := []Config{
NewSSHConfigurerV2(
store,
runRemoteCMD,
),
}
// if featureflag.ServiceMeshSSH(user.GlobalUserType) {
// configs = []Config{
// NewSSHConfigurerServiceMesh(store),
// }
// }
jetbrainsConfigurer, err := NewSSHConfigurerJetBrains(store)
// add jetbrainsconfigurer to configs if we can, but if we can't that
// shouldn't prevent us from setting up the other configs
if err == nil && jetbrainsConfigurer != nil {
configs = append(configs, jetbrainsConfigurer)
}
return configs, nil
}