-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
107 lines (84 loc) · 2.31 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
/*
* Version 0.1.0
* Compatible with Mac OS X and linux OS ONLY
*/
/*** OPERATION WORKFLOW ***/
/*
* 1- SSM library gets AWS credentials from host machine
* 2- Makes API call to aws
* 3- Prints desired in table as output
*/
import (
"fmt"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
session "github.com/aws/aws-sdk-go/aws/session"
"github.com/warrensbox/aws-find/lib"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var version = "0.1.0\n"
var (
versionFlag *bool
helpFlag *bool
awsRegion *string
tagName *string
tagValue *string
services *string
)
func init() {
const (
cmdDesc = "Look the IP addresses and instance IDs by their tag name in AWS"
versionFlagDesc = "Displays the version of aws-find"
servicesArgDesc = "Provide service(s) to be queried. Ex: ec2,alb,rds,sg. Default: ec2"
awsRegionDesc = "Provide AWS Region. Default is us-east-1"
tagNameDesc = "Provide AWS Tag name"
tagValueDesc = "Provide AWS Tag value"
)
versionFlag = kingpin.Flag("version", versionFlagDesc).Short('v').Bool()
awsRegion = kingpin.Flag("region", awsRegionDesc).Short('r').String()
services = kingpin.Arg("services", servicesArgDesc).String()
tagName = kingpin.Flag("tag", tagNameDesc).Short('T').String()
tagValue = kingpin.Flag("value", tagValueDesc).Short('V').String()
}
func main() {
kingpin.Parse()
config := &aws.Config{Region: aws.String(*awsRegion)}
session := session.Must(session.NewSession(config))
construct := &lib.Constructor{*tagName, *tagValue, session}
profile, _ := lib.NewConstructor(construct)
ch := make(chan string)
if *versionFlag {
fmt.Printf("\nVersion: %v\n", version)
} else if *services != "" {
if strings.Contains(*services, ",") {
result := strings.Split(*services, ",")
service := make(map[string]struct{})
for _, s := range result {
service[s] = struct{}{}
}
if serviceExist(service, "ec2") {
fmt.Println("this")
time.Sleep(100000000)
}
if serviceExist(service, "rds") {
fmt.Println("this too")
time.Sleep(10000000)
}
if serviceExist(service, "alb") {
profile.FindALB(ch)
}
}
} else {
go profile.FindEC2(ch)
<-ch
}
}
func serviceExist(services map[string]struct{}, item string) bool {
exist := false
if _, ok := services[item]; ok {
exist = true
}
return exist
}