/
config.go
120 lines (112 loc) · 4.84 KB
/
config.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
108
109
110
111
112
113
114
115
116
117
118
119
120
package KINESIS
import (
"fmt"
"github.com/Appkube-awsx/awsx-common/authenticate"
"github.com/Appkube-awsx/awsx-common/awsclient"
"github.com/Appkube-awsx/awsx-common/model"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kinesis"
"github.com/spf13/cobra"
)
var AwsxKinesisConfigCmd = &cobra.Command{
Use: "getKinesisConfig",
Short: "getKinesisConfig command gets kinesis configuration",
Long: `getKinesisConfig command gets kinesis configuration`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("executing getKinesisConfig command")
var authFlag, clientAuth, err = authenticate.AuthenticateCommand(cmd)
if err != nil {
log.Printf("error during authentication: %v\n", err)
err := cmd.Help()
if err != nil {
return
}
return
}
if authFlag {
streamName, _ := cmd.Flags().GetString("streamName")
if streamName == "" {
log.Printf("kinesis stream name missing")
err := cmd.Help()
if err != nil {
return
}
return
}
if streamName != "" {
instances, err := GetKinesisInstanceByStreamName(streamName, clientAuth, nil)
if err != nil {
log.Println("error getting getKinesisConfig by instance id: ", err)
return
}
fmt.Println(instances)
}
}
},
}
func GetKinesisInstanceByStreamName(streamName string, clientAuth *model.Auth, client *kinesis.Kinesis) (*kinesis.DescribeStreamOutput, error) {
log.Println("getting aws kinesis instance of given stream name: ", streamName)
if streamName == "" {
log.Println("stream name missing")
return nil, fmt.Errorf("stream name missing")
}
if client == nil {
client = awsclient.GetClient(*clientAuth, awsclient.KINESIS_CLIENT).(*kinesis.Kinesis)
}
input := &kinesis.DescribeStreamInput{
StreamName: aws.String(streamName),
}
kinesisData, err := client.DescribeStream(input)
if err != nil {
log.Println("error: ", err)
return nil, err
}
return kinesisData, nil
}
func GetKinesisStreamList(clientAuth *model.Auth, client *kinesis.Kinesis) (*kinesis.ListStreamsOutput, error) {
log.Println("getting kinesis streams")
if client == nil {
client = awsclient.GetClient(*clientAuth, awsclient.KINESIS_CLIENT).(*kinesis.Kinesis)
}
input := &kinesis.ListStreamsInput{}
streamList, err := client.ListStreams(input)
if err != nil {
log.Println("Error: in getting kinesis streams", err)
return nil, err
}
log.Println(streamList)
return streamList, err
}
func init() {
AwsxKinesisConfigCmd.PersistentFlags().String("rootVolumeId", "", "root volume id")
AwsxKinesisConfigCmd.PersistentFlags().String("ebsVolume1Id", "", "ebs volume 1 id")
AwsxKinesisConfigCmd.PersistentFlags().String("ebsVolume2Id", "", "ebs volume 2 id")
AwsxKinesisConfigCmd.PersistentFlags().String("elementId", "", "element id")
AwsxKinesisConfigCmd.PersistentFlags().String("cmdbApiUrl", "", "cmdb api")
AwsxKinesisConfigCmd.PersistentFlags().String("vaultUrl", "", "vault end point")
AwsxKinesisConfigCmd.PersistentFlags().String("vaultToken", "", "vault token")
AwsxKinesisConfigCmd.PersistentFlags().String("landingZoneId", "", "aws landingZoneId")
AwsxKinesisConfigCmd.PersistentFlags().String("zone", "", "aws region")
AwsxKinesisConfigCmd.PersistentFlags().String("accessKey", "", "aws access key")
AwsxKinesisConfigCmd.PersistentFlags().String("secretKey", "", "aws secret key")
AwsxKinesisConfigCmd.PersistentFlags().String("crossAccountRoleArn", "", "aws cross account role arn")
AwsxKinesisConfigCmd.PersistentFlags().String("externalId", "", "aws external id")
AwsxKinesisConfigCmd.PersistentFlags().String("cloudWatchQueries", "", "aws cloudwatch metric queries")
AwsxKinesisConfigCmd.PersistentFlags().String("serviceName", "", "service name")
AwsxKinesisConfigCmd.PersistentFlags().String("elementType", "", "element type")
AwsxKinesisConfigCmd.PersistentFlags().String("instanceId", "", "instance id")
AwsxKinesisConfigCmd.PersistentFlags().String("tagName", "", "tag name")
AwsxKinesisConfigCmd.PersistentFlags().String("apiKey", "", "api gateway key/id")
AwsxKinesisConfigCmd.PersistentFlags().String("clusterName", "", "cluster name")
AwsxKinesisConfigCmd.PersistentFlags().String("tableName", "", "dynamo-db table name")
AwsxKinesisConfigCmd.PersistentFlags().String("streamName", "", "kinesis stream name")
AwsxKinesisConfigCmd.PersistentFlags().String("keyId", "", "kms key id")
AwsxKinesisConfigCmd.PersistentFlags().String("functionName", "", "lambda function name")
AwsxKinesisConfigCmd.PersistentFlags().String("bucketName", "", "s3 bucket name")
AwsxKinesisConfigCmd.PersistentFlags().String("arn", "", "arn")
AwsxKinesisConfigCmd.PersistentFlags().String("query", "", "query")
AwsxKinesisConfigCmd.PersistentFlags().String("startTime", "", "start time")
AwsxKinesisConfigCmd.PersistentFlags().String("endTime", "", "end time")
AwsxKinesisConfigCmd.PersistentFlags().String("responseType", "", "response type. json/frame")
}