forked from sst/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcert.go
60 lines (57 loc) · 1.47 KB
/
cert.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
package main
import (
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/sst/ion/cmd/sst/cli"
"github.com/sst/ion/pkg/global"
)
var CmdCert = &cli.Command{
Name: "cert",
Description: cli.Description{
Short: "Generate certificate for the Console",
Long: strings.Join([]string{
"Generate a locally-trusted certificate to connect to the Console.",
"",
"The Console can show you local logs from `sst dev` by connecting to your CLI. Certain browsers like Safari and Brave require the local connection to be running on HTTPS.",
"",
"This command uses [mkcert](https://github.com/FiloSottile/mkcert) internally to generate a locally-trusted certificate for `localhost` and `127.0.0.1`.",
"",
"You'll only need to do this once on your machine.",
}, "\n"),
},
Run: func(c *cli.Cli) error {
err := global.EnsureMkcert()
if err != nil {
return err
}
env := os.Environ()
env = append(env, "CAROOT="+global.CertPath())
cmd := exec.Command("mkcert", "-install")
cmd.Env = env
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
return err
}
cmd = exec.Command(
"mkcert",
"-key-file", filepath.Join(global.CertPath(), "key.pem"),
"-cert-file", filepath.Join(global.CertPath(), "cert.pem"),
"127.0.0.1",
"localhost",
)
cmd.Env = env
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
return err
}
return nil
},
}