-
Notifications
You must be signed in to change notification settings - Fork 0
/
skipp3r.go
80 lines (66 loc) · 1.73 KB
/
skipp3r.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
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"io/ioutil"
"os/exec"
"strings"
)
type Skipp3r struct {
Bucket *string
Prefix *string
Version *string
Svc *s3.S3
}
// Unfortunately, the AWS SDK does not have a sync function like the AWS CLI. Rather than program
// that in, we will simply exec the cli from within this function.
func (skipp3r Skipp3r) set(srcPath *string, destPath *string, doDelete *bool) error {
cmdString := "--no-verify-ssl s3 sync " + *srcPath
cmdString += " s3://" + *skipp3r.Bucket
if skipp3r.Prefix != nil {
cmdString += "/" + *skipp3r.Prefix
}
cmdString += "/" + *skipp3r.Version
if *doDelete {
cmdString += " --delete"
}
foo := strings.Split(cmdString, " ")
return exec.Command("aws", foo...).Run()
}
func (skipp3r Skipp3r) get(pathIn *string) string {
retVal := "{"
path := ""
if skipp3r.Prefix != nil {
path += *skipp3r.Prefix
}
key := path + "/" + *skipp3r.Version + "/common/config"
// Get common config first
resp, err := skipp3r.Svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(*skipp3r.Bucket),
Key: aws.String(key),
})
if err != nil {
fmt.Println(err.Error())
return ""
}
if b, err := ioutil.ReadAll(resp.Body); err == nil {
retVal += "\"common\": " + string(b)
}
if *pathIn != "" && *pathIn != "common" {
retVal += ","
resp, err = skipp3r.Svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(*skipp3r.Bucket),
Key: aws.String(path + "/" + *skipp3r.Version + "/" + *pathIn + "/config"),
})
if err != nil {
fmt.Println(err.Error())
return ""
}
if b, err := ioutil.ReadAll(resp.Body); err == nil {
retVal += "\"" + *pathIn + "\": " + string(b)
}
}
retVal += "}"
return retVal
}