-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolkit_service.go
64 lines (54 loc) · 1.68 KB
/
toolkit_service.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
// Copyright 2022 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package factory
import (
"context"
"sync"
"google.golang.org/grpc"
"chromiumos/tast/local/bundles/cros/factory/toolkit"
factoryservice "chromiumos/tast/services/cros/factory"
"chromiumos/tast/testing"
)
func init() {
testing.AddService(&testing.Service{
Register: func(srv *grpc.Server, s *testing.ServiceState) {
factoryservice.RegisterToolkitServer(srv, &ToolkitService{
serviceState: s,
cmdExecLock: &sync.Mutex{},
})
},
})
}
// ToolkitService implements tast.cros.factory.Toolkit gRPC service.
type ToolkitService struct {
serviceState *testing.ServiceState
cmdExecLock *sync.Mutex
}
// Install installs the factory toolkit with the arguments specified in the
// request.
func (t *ToolkitService) Install(ctx context.Context, req *factoryservice.InstallRequest) (*factoryservice.InstallResponse, error) {
t.cmdExecLock.Lock()
defer t.cmdExecLock.Unlock()
installer := toolkit.Installer{
InstallerPath: toolkit.ToolkitInstallerPath,
NoEnable: req.NoEnable,
}
version, err := installer.InstallFactoryToolKit(ctx)
if err != nil {
return nil, err
}
return &factoryservice.InstallResponse{
Version: version,
}, nil
}
// Uninstall calls the command factory_uninstall.
func (t *ToolkitService) Uninstall(ctx context.Context, _ *factoryservice.UninstallRequest) (*factoryservice.UninstallResponse, error) {
t.cmdExecLock.Lock()
defer t.cmdExecLock.Unlock()
err := toolkit.UninstallFactoryToolKit(ctx)
if err != nil {
return nil, err
}
return &factoryservice.UninstallResponse{}, nil
}