-
Notifications
You must be signed in to change notification settings - Fork 2
/
runner.go
77 lines (62 loc) · 1.94 KB
/
runner.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
package microvms
import (
"errors"
"github.com/DataDog/test-infra-definitions/components/command"
"github.com/pulumi/pulumi-command/sdk/go/command/local"
"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type Runner struct {
remoteRunner *command.Runner
localRunner *command.LocalRunner
}
func NewRunner(options ...func(*Runner)) *Runner {
runner := Runner{}
for _, opts := range options {
opts(&runner)
}
return &runner
}
func WithRemoteRunner(runner *command.Runner) func(*Runner) {
return func(a *Runner) {
a.remoteRunner = runner
}
}
func WithLocalRunner(runner *command.LocalRunner) func(*Runner) {
return func(a *Runner) {
a.localRunner = runner
}
}
func (a *Runner) Command(name string, args *command.Args, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
if a.remoteRunner != nil {
return a.remoteRunner.Command(name, args, opts...)
}
if a.localRunner != nil {
return a.localRunner.Command(name, args, opts...)
}
panic("no runner initialized")
}
func (a *Runner) RemoteCommand(name string, args *command.Args, opts ...pulumi.ResourceOption) (*remote.Command, error) {
if a.remoteRunner == nil {
return nil, errors.New("remote runner not initialized for Runner instance")
}
return a.remoteRunner.Command(name, args, opts...)
}
func (a *Runner) LocalCommand(name string, args *command.Args, opts ...pulumi.ResourceOption) (*local.Command, error) {
if a.localRunner == nil {
return nil, errors.New("local runner not initialized for Runner instance")
}
return a.localRunner.Command(name, args, opts...)
}
func (a *Runner) GetRemoteRunner() (*command.Runner, error) {
if a.remoteRunner == nil {
return nil, errors.New("remote runner not initialized")
}
return a.remoteRunner, nil
}
func (a *Runner) GetLocalRunner() (*command.LocalRunner, error) {
if a.localRunner == nil {
return nil, errors.New("local runner not initialized")
}
return a.localRunner, nil
}