-
Notifications
You must be signed in to change notification settings - Fork 11
/
types.go
88 lines (77 loc) · 2.48 KB
/
types.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
/*
* Copyright (C) 2022 Appvia Ltd <info@appvia.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"errors"
"fmt"
"strings"
"time"
)
// Step represents a stage to run
type Step struct {
// Commands is the commands and arguments to run
Commands []string
// Comment adds a banner to the stage
Comment string
// ErrorFile is the path to a file which is created when the command failed
ErrorFile string
// FailureFile is the path to a file indicating failure
FailureFile string
// Namespace is the namespace to upload any files to as a secret
Namespace string
// Shell is the shell to execute the command in
Shell string
// SuccessFile is the path to a file which is created when the command ran successfully
SuccessFile string
// Timeout is the max time to wait on file before considering the run a failure
Timeout time.Duration
// UploadFile is file to upload on success of the command
UploadFile []string
// WaitFile is the path to a file which is wait for to run
WaitFile string
}
// IsValid returns an error if the skip configuation is invalid
func (s Step) IsValid() error {
switch {
case len(s.Commands) == 0:
return errors.New("no commands specified")
case s.Timeout < 0:
return errors.New("timeout must be greater than 0")
case len(s.UploadFile) > 0 && s.Namespace == "":
return errors.New("namespace must be specified when uploading files")
case len(s.UploadFile) > 0:
for _, x := range s.UploadFile {
if e := strings.Split(x, "="); len(e) != 2 {
return fmt.Errorf("upload file must be in the format 'key=path'")
}
}
}
return nil
}
// UploadKeyPairs returns a map of key pairs to upload
func (s Step) UploadKeyPairs() map[string]string {
if len(s.UploadFile) == 0 {
return nil
}
keys := make(map[string]string)
for _, x := range s.UploadFile {
if e := strings.Split(x, "="); len(e) == 2 {
keys[e[0]] = e[1]
}
}
return keys
}