-
Notifications
You must be signed in to change notification settings - Fork 7
/
cmd_shell.go
124 lines (105 loc) · 2.82 KB
/
cmd_shell.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package domain
import (
"encoding/json"
"time"
)
type (
Cache struct {
Key string `json:"key"`
Paths []string `json:"paths"`
}
ShellIn struct {
CmdIn
ID string `json:"id"`
FlowId string `json:"flowId"`
JobId string `json:"jobId"`
AllowFailure bool `json:"allowFailure"`
Plugin string `json:"plugin"`
Cache *Cache `json:"cache"`
Dockers []*DockerOption `json:"dockers"`
Bash []string `json:"bash"`
Pwsh []string `json:"pwsh"`
Retry int `json:"retry"`
Timeout int `json:"timeout"`
Inputs Variables `json:"inputs"`
EnvFilters []string `json:"envFilters"`
Secrets []string `json:"secrets"` // secret name list
Configs []string `json:"configs"` // config name list
}
ShellOut struct {
ID string `json:"id"`
ProcessId int `json:"processId"`
Containers []string `json:"containers"` // container ids applied for shell
Status CmdStatus `json:"status"`
Code int `json:"code"`
Output Variables `json:"output"`
StartAt time.Time `json:"startAt"`
FinishAt time.Time `json:"finishAt"`
Error string `json:"error"`
LogSize int64 `json:"logSize"`
}
ShellLog struct {
JobId string `json:"jobId"`
StepId string `json:"stepId"`
Log string `json:"log"` // b64
}
)
// ===================================
// ShellIn Methods
// ===================================
func (in *ShellIn) HasSecrets() bool {
return in.Secrets != nil && len(in.Secrets) > 0
}
func (in *ShellIn) HasConfigs() bool {
return in.Configs != nil && len(in.Configs) > 0
}
func (in *ShellIn) HasCache() bool {
return in.Cache != nil
}
func (in *ShellIn) HasPlugin() bool {
return in.Plugin != ""
}
func (in *ShellIn) HasDockerOption() bool {
return in.Dockers != nil && len(in.Dockers) > 0
}
func (in *ShellIn) HasEnvFilters() bool {
if in.EnvFilters == nil {
return false
}
return len(in.EnvFilters) != 0
}
func (in *ShellIn) VarsToStringArray() []string {
if !NilOrEmpty(in.Inputs) {
return in.Inputs.ToStringArray()
}
return []string{}
}
func NewShellOutput(in *ShellIn) *ShellOut {
return &ShellOut{
ID: in.ID,
Code: CmdExitCodeUnknown,
Status: CmdStatusPending,
Output: NewVariables(),
}
}
// ===================================
// ShellOut Methods
// ===================================
func (e *ShellOut) IsFinishStatus() bool {
switch e.Status {
case CmdStatusKilled:
return true
case CmdStatusTimeout:
return true
case CmdStatusException:
return true
case CmdStatusSuccess:
return true
default:
return false
}
}
func (e *ShellOut) ToBytes() []byte {
data, _ := json.Marshal(e)
return append(shellOutInd, data...)
}