/
login.go
52 lines (41 loc) · 1.28 KB
/
login.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
package edge
import (
"errors"
"github.com/openziti/fablab/kernel/model"
"github.com/openziti/ziti/ziti/cmd/common"
"github.com/openziti/ziti/zititest/zitilab/cli"
"path/filepath"
)
func Login(componentSelector string) model.Action {
return &login{
componentSelector: componentSelector,
}
}
func (l *login) Execute(run model.Run) error {
m := run.GetModel()
ctrl, err := m.SelectComponent(l.componentSelector)
if err != nil {
return err
}
username := m.MustStringVariable("credentials.edge.username")
password := m.MustStringVariable("credentials.edge.password")
edgeApiBaseUrl := ctrl.Host.PublicIp + ":1280"
caChain := filepath.Join(model.KitBuild(), model.BuildPkiDir, ctrl.Id, "certs", ctrl.Id+".cert")
if username == "" {
return errors.New("variable credentials/edge/username must be a string")
}
if password == "" {
return errors.New("variable credentials/edge/password must be a string")
}
if _, err = cli.Exec(m, "edge", "login", edgeApiBaseUrl, "-i", model.ActiveInstanceId(), "--ca", caChain, "-u", username, "-p", password); err != nil {
return err
}
if _, err = cli.Exec(m, "edge", "use", model.ActiveInstanceId()); err != nil {
return err
}
common.CliIdentity = model.ActiveInstanceId()
return nil
}
type login struct {
componentSelector string
}