-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.go
49 lines (42 loc) · 982 Bytes
/
import.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
package cimport
import (
"github.com/fedy2/cwq/internal/cloudwatch"
"github.com/fedy2/cwq/internal/import/format"
"github.com/fedy2/cwq/internal/import/input"
)
func Import(arguments *ImportCmd) error {
data, err := input.FromFile(arguments.File)
if err != nil {
return err
}
queryDefinitions := []cloudwatch.QueryDefinition{}
err = nil
switch arguments.Format {
case "json":
queryDefinitions, err = format.FromJson(data)
case "csv":
options := format.CsvOptions{
HasHeader: arguments.CsvHasHeader,
Delimiter: arguments.CsvDelimiter,
Comment: arguments.CsvComment,
}
queryDefinitions, err = format.FromCsv(data, options)
}
if err != nil {
return err
}
if arguments.ClearIds {
for i := range queryDefinitions {
queryDefinitions[i].QueryDefinitionId = nil
}
}
client, err := cloudwatch.NewClient()
if err != nil {
return err
}
err = client.PutQueryDefinitions(queryDefinitions)
if err != nil {
return err
}
return nil
}