-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeps.go
More file actions
71 lines (62 loc) · 2.42 KB
/
Copy pathdeps.go
File metadata and controls
71 lines (62 loc) · 2.42 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
package cmd
import (
"context"
"os"
"os/exec"
"github.com/dkmnx/kairo/internal/crypto"
"github.com/dkmnx/kairo/internal/ui"
"github.com/dkmnx/kairo/internal/update"
"github.com/dkmnx/kairo/internal/wrapper"
)
// osProcessRunner delegates process operations to the os/exec and os packages.
type osProcessRunner struct{}
func (osProcessRunner) LookPath(file string) (string, error) { return exec.LookPath(file) }
func (osProcessRunner) ExecCommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd {
return exec.CommandContext(ctx, name, arg...)
}
func (osProcessRunner) ExitProcess(code int) { os.Exit(code) }
// prodWrapperService delegates wrapper operations to the wrapper package.
type prodWrapperService struct{}
func (prodWrapperService) CreateTempAuthDir() (string, error) {
return wrapper.CreateTempAuthDir()
}
func (prodWrapperService) WriteTempTokenFile(authDir, token string) (string, error) {
return wrapper.WriteTempTokenFile(authDir, token)
}
func (prodWrapperService) GenerateWrapperScript(cfg wrapper.ScriptConfig) (string, bool, error) {
return wrapper.GenerateWrapperScript(cfg)
}
// prodUpdateService delegates update operations to the update and ui packages.
type prodUpdateService struct {
client *update.Client
}
func (s *prodUpdateService) FetchLatestRelease(ctx context.Context) (*update.Release, error) {
return s.client.FetchLatestRelease(ctx)
}
func (prodUpdateService) ConfirmUpdate(message string) (bool, error) {
return ui.Confirm(message)
}
func (s *prodUpdateService) DownloadToTempFile(ctx context.Context, url string) (string, error) {
return s.client.DownloadToTempFile(ctx, url)
}
func (s *prodUpdateService) DownloadAndParseChecksums(ctx context.Context, url string) (map[string]string, error) {
return s.client.DownloadAndParseChecksums(ctx, url)
}
func (prodUpdateService) VerifyChecksum(scriptPath, expectedHash string) error {
return update.VerifyChecksum(scriptPath, expectedHash)
}
func (prodUpdateService) RunInstallScript(scriptPath string) error {
return update.RunInstallScript(scriptPath)
}
func (s *prodUpdateService) VerifyCosignBundle(ctx context.Context, tag string) error {
return s.client.VerifyCosignBundle(ctx, tag)
}
// NewDeps returns a Deps with production implementations.
func NewDeps() *Deps {
return &Deps{
Process: osProcessRunner{},
Wrapper: prodWrapperService{},
Update: &prodUpdateService{client: update.NewClient()},
Crypto: crypto.DefaultService{},
}
}