-
Notifications
You must be signed in to change notification settings - Fork 2
/
osCommand.go
97 lines (83 loc) · 2.32 KB
/
osCommand.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package command
import (
"strings"
"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// OSCommand defines the commands which are OS specifics
type OSCommand interface {
GetTemporaryDirectory() string
GetHomeDirectory() string
CreateDirectory(
runner *Runner,
resourceName string,
remotePath pulumi.StringInput,
useSudo bool,
opts ...pulumi.ResourceOption) (*remote.Command, error)
CopyInlineFile(
runner *Runner,
fileContent pulumi.StringInput,
remotePath string,
useSudo bool,
opts ...pulumi.ResourceOption) (*remote.Command, error)
BuildCommandString(
command pulumi.StringInput,
env pulumi.StringMap,
sudo bool,
passwordFromStdin bool,
user string) pulumi.StringInput
IsPathAbsolute(path string) bool
}
// ------------------------------
// Helpers to implement osCommand
// ------------------------------
const backupExtension = "pulumi.backup"
func createDirectory(
runner *Runner,
name string,
createCmd string,
deleteCmd string,
useSudo bool,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
// If the folder was previously created, make sure to delete it before creating it.
opts = append(opts, pulumi.DeleteBeforeReplace(true))
return runner.Command(name,
&Args{
Create: pulumi.String(createCmd),
Delete: pulumi.String(deleteCmd),
Sudo: useSudo,
Triggers: pulumi.Array{pulumi.String(createCmd), pulumi.BoolPtr(useSudo)},
}, opts...)
}
func copyInlineFile(
name string,
runner *Runner,
fileContent pulumi.StringInput,
useSudo bool,
createCmd string,
deleteCmd string,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
return runner.Command(runner.namer.ResourceName("copy-file", name),
&Args{
Create: pulumi.String(createCmd),
Delete: pulumi.String(deleteCmd),
Stdin: fileContent,
Sudo: useSudo,
Triggers: pulumi.Array{pulumi.String(createCmd), fileContent, pulumi.BoolPtr(useSudo)},
}, opts...)
}
func buildCommandString(
command pulumi.StringInput,
envVars pulumi.StringArray,
fct func(envVarsStr pulumi.StringOutput) pulumi.StringInput,
) pulumi.StringInput {
if command == nil {
return nil
}
envVarsStr := envVars.ToStringArrayOutput().ApplyT(func(inputs []string) string {
return strings.Join(inputs, " ")
}).(pulumi.StringOutput)
return fct(envVarsStr)
}