/
scheduled_tasks_list.go
66 lines (53 loc) · 1.7 KB
/
scheduled_tasks_list.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
package cmd
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/eventbridge"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func scheduledTasksListRun(cmd *cobra.Command, scheduledTasks []string) {
clustersDescription, err := ecsI.DescribeClusters(&ecs.DescribeClustersInput{
Clusters: []*string{
aws.String(viper.GetString("cluster")),
},
})
t.Must(err)
if len(clustersDescription.Clusters) == 0 {
t.Exitln("Source Cluster informed not found")
}
list, err := evbI.ListRuleNamesByTarget(&eventbridge.ListRuleNamesByTargetInput{
TargetArn: clustersDescription.Clusters[0].ClusterArn,
})
for _, name := range list.RuleNames {
rule, err := evbI.DescribeRule(&eventbridge.DescribeRuleInput{Name: name})
t.Must(err)
switch state {
case "enabled":
if aws.StringValue(rule.State) != eventbridge.RuleStateEnabled {
continue
}
case "disabled":
if aws.StringValue(rule.State) != eventbridge.RuleStateDisabled {
continue
}
}
targets, err := evbI.ListTargetsByRule(&eventbridge.ListTargetsByRuleInput{Rule: name})
t.Must(err)
t.Outln(targets)
}
}
var scheduledTasksListCmd = &cobra.Command{
Use: "list",
Short: "List scheduled tasks of specified cluster",
Aliases: []string{"l"},
Run: scheduledTasksListRun,
PersistentPreRun: persistentPreRun,
}
func init() {
scheduledTasksCmd.AddCommand(scheduledTasksListCmd)
flags := scheduledTasksListCmd.Flags()
flags.StringVarP(&state, "state", "s", "enabled", stateSpec)
flags.StringP("cluster", "c", "", requiredSpec+clusterSpec)
viper.BindPFlag("cluster", scheduledTasksListCmd.Flags().Lookup("cluster"))
}