-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
57 lines (50 loc) · 1.28 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"strings"
)
func main() {
action := Action{
Action: os.Getenv("ACTION"),
Bucket: os.Getenv("BUCKET"),
S3Class: os.Getenv("S3_CLASS"),
Key: fmt.Sprintf("%s.zip", os.Getenv("KEY")),
Artifacts: strings.Split(strings.TrimSpace(os.Getenv("ARTIFACTS")), "\n"),
}
switch act := action.Action; act {
case PutAction:
if len(action.Artifacts[0]) <= 0 {
log.Fatal("No artifacts patterns provided")
}
if err := Zip(action.Key, action.Artifacts); err != nil {
log.Fatal(err)
}
if err := PutObject(action.Key, action.Bucket, action.S3Class); err != nil {
log.Fatal(err)
}
case GetAction:
exists, err := ObjectExists(action.Key, action.Bucket)
if err != nil {
log.Fatal(err)
}
// Get and and unzip if object exists
if exists {
if err := GetObject(action.Key, action.Bucket); err != nil {
log.Fatal(err)
}
if err := Unzip(action.Key); err != nil {
log.Fatal(err)
}
} else {
log.Printf("No caches found for the following key: %s", action.Key)
}
case DeleteAction:
if err := DeleteObject(action.Key, action.Bucket); err != nil {
log.Fatal(err)
}
default:
log.Fatalf("Action \"%s\" is not allowed. Valid options are: [%s, %s, %s]", act, PutAction, DeleteAction, GetAction)
}
}