-
Notifications
You must be signed in to change notification settings - Fork 23
/
request_type.go
169 lines (149 loc) · 5.14 KB
/
request_type.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package costexplorer
import (
"time"
SDK "github.com/aws/aws-sdk-go/service/costexplorer"
"github.com/evalphobia/aws-sdk-go-wrapper/private/pointers"
)
const (
GranularityMonthly = SDK.GranularityMonthly
GranularityDaily = SDK.GranularityDaily
GranularityHourly = SDK.GranularityHourly
GroupByDimension = SDK.GroupDefinitionTypeDimension
GroupByTag = SDK.GroupDefinitionTypeTag
MetricBlendedCost = SDK.MetricBlendedCost
MetricUnblendedCost = SDK.MetricUnblendedCost
MetricAmortizedCost = SDK.MetricAmortizedCost
MetricNetUnblendedCost = SDK.MetricNetUnblendedCost
MetricNetAmortizedCost = SDK.MetricNetAmortizedCost
MetricUsageQuantity = SDK.MetricUsageQuantity
MetricNormalizedUsageAmount = SDK.MetricNormalizedUsageAmount
)
// GetCostAndUsageInput is optional parameters for `GetCostAndUsage`.
type GetCostAndUsageInput struct {
NextPageToken string
TimePeriodStart time.Time
TimePeriodEnd time.Time
GranularityMonthly bool
GranularityDaily bool
GranularityHourly bool
GroupByDimensionAZ bool
GroupByDimensionInstanceType bool
GroupByDimensionLegalEntityName bool
GroupByDimensionLinkedAccount bool
GroupByDimensionOperation bool
GroupByDimensionPlatform bool
GroupByDimensionPurchaseType bool
GroupByDimensionService bool
GroupByDimensionTenancy bool
GroupByDimensionRecordType bool
GroupByDimensionUsageType bool
GroupByTagKeys []string
MetricAmortizedCost bool
MetricBlendedCost bool
MetricNetAmortizedCost bool
MetricNetUnblendedCost bool
MetricNormalizedUsageAmount bool
MetricUnblendedCost bool
MetricUsageQuantity bool
Filter *SDK.Expression
}
// ToInput converts to *SDK.GetCostAndUsageInput.
func (u GetCostAndUsageInput) ToInput() *SDK.GetCostAndUsageInput {
in := &SDK.GetCostAndUsageInput{}
// set NextPageToken
if u.NextPageToken != "" {
in.NextPageToken = pointers.String(u.NextPageToken)
}
// set TimePeriod
if u.TimePeriodEnd.IsZero() {
u.TimePeriodEnd = time.Now().AddDate(0, 0, -1)
}
if u.TimePeriodStart.IsZero() {
u.TimePeriodStart = u.TimePeriodEnd.AddDate(0, 0, -1)
}
in.TimePeriod = &SDK.DateInterval{
Start: pointers.String(u.TimePeriodStart.Format("2006-01-02")),
End: pointers.String(u.TimePeriodEnd.Format("2006-01-02")),
}
// set Granularity
switch {
case u.GranularityDaily:
in.Granularity = pointers.String(GranularityDaily)
case u.GranularityMonthly:
in.Granularity = pointers.String(GranularityMonthly)
case u.GranularityHourly:
in.Granularity = pointers.String(GranularityHourly)
default:
in.Granularity = pointers.String(GranularityDaily)
}
// set GroupBy
if u.GroupByDimensionAZ {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionAz))
}
if u.GroupByDimensionInstanceType {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionInstanceType))
}
if u.GroupByDimensionLinkedAccount {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionLinkedAccount))
}
if u.GroupByDimensionOperation {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionOperation))
}
if u.GroupByDimensionPurchaseType {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionPurchaseType))
}
if u.GroupByDimensionService {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionService))
}
if u.GroupByDimensionTenancy {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionTenancy))
}
if u.GroupByDimensionRecordType {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionRecordType))
}
if u.GroupByDimensionUsageType {
in.GroupBy = append(in.GroupBy, newGroupDefinitionDimension(SDK.DimensionUsageType))
}
for _, v := range u.GroupByTagKeys {
in.GroupBy = append(in.GroupBy, newGroupDefinitionTag(v))
}
// set Metrics
if u.MetricAmortizedCost {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricAmortizedCost))
}
if u.MetricBlendedCost {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricBlendedCost))
}
if u.MetricNetAmortizedCost {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricNetAmortizedCost))
}
if u.MetricNetUnblendedCost {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricNetUnblendedCost))
}
if u.MetricNormalizedUsageAmount {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricNormalizedUsageAmount))
}
if u.MetricUnblendedCost {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricUnblendedCost))
}
if u.MetricUsageQuantity {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricUsageQuantity))
}
if len(in.Metrics) == 0 {
in.Metrics = append(in.Metrics, pointers.String(SDK.MetricUnblendedCost))
}
in.Filter = u.Filter
return in
}
func newGroupDefinitionDimension(key string) *SDK.GroupDefinition {
return &SDK.GroupDefinition{
Type: pointers.String(GroupByDimension),
Key: pointers.String(key),
}
}
func newGroupDefinitionTag(key string) *SDK.GroupDefinition {
return &SDK.GroupDefinition{
Type: pointers.String(GroupByTag),
Key: pointers.String(key),
}
}