-
Notifications
You must be signed in to change notification settings - Fork 3
/
jobs.go
55 lines (51 loc) · 1.49 KB
/
jobs.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
package library
import (
"encoding/json"
"fmt"
"strconv"
sess "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/glacier"
glacierService "github.com/eschizoid/flixctl/aws/glacier"
slackService "github.com/eschizoid/flixctl/slack/library"
"github.com/spf13/cobra"
)
var JobsLibraryCmd = &cobra.Command{
Use: "jobs",
Short: "To List Library Jobs",
Long: "to list library jobs.",
Run: func(cmd *cobra.Command, args []string) {
var awsSession = sess.Must(sess.NewSessionWithOptions(sess.Options{
SharedConfigState: sess.SharedConfigEnable,
}))
svc := glacier.New(awsSession)
jobList := glacierService.ListJobs(svc)
var jobs []*glacier.JobDescription
switch jobFilter {
case "all": //nolint:goconst
jobs = jobList.JobList
case "archive":
jobs = filterJobs(jobList.JobList, func(filter string) bool {
return filter == "ArchiveRetrieval"
})
case "inventory":
jobs = filterJobs(jobList.JobList, func(filter string) bool {
return filter == "InventoryRetrieval"
})
default:
jobs = jobList.JobList
}
json, _ := json.Marshal(jobs)
if notify, _ := strconv.ParseBool(slackNotification); notify {
slackService.SendJobs(jobs, slackIncomingHookURL)
}
fmt.Println(string(json))
},
}
func filterJobs(jobDescriptions []*glacier.JobDescription, test func(string) bool) (filteredJobs []*glacier.JobDescription) {
for _, job := range jobDescriptions {
if test(*job.Action) {
filteredJobs = append(filteredJobs, job)
}
}
return
}