@@ -4,28 +4,29 @@ import (
4
4
"context"
5
5
"fmt"
6
6
"log/slog"
7
- "github.com/harness/harness-mcp/client/dto"
7
+
8
8
"github.com/harness/harness-mcp/client/ccmcommons"
9
+ "github.com/harness/harness-mcp/client/dto"
9
10
)
10
11
11
12
const (
12
- ccmGraphQLBasePath = ccmBasePath + "/graphql"
13
+ ccmGraphQLBasePath = ccmBasePath + "/graphql"
13
14
ccmPerspectiveGraphQLPath = ccmGraphQLBasePath + "?accountIdentifier=%s&routingId=%s"
14
15
)
15
16
16
17
func (r * CloudCostManagementService ) PerspectiveGrid (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveGridOptions ) (* dto.CCMPerspectiveGridResponse , error ) {
17
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
18
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
18
19
19
20
gqlQuery := ccmcommons .CCMPerspectiveGridQuery
20
21
variables := map [string ]any {
21
- "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
22
- "groupBy" : ccmcommons .BuildGroupBy (options .GroupBy , ccmcommons .OutputFields , ccmcommons .OutputKeyValueFields ),
23
- "limit" : options .Limit ,
24
- "offset" : options .Offset ,
25
- "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
26
- "isClusterOnly" : false ,
27
- "isClusterHourlyData" : false ,
28
- "preferences" : ccmcommons .BuildPreferences (),
22
+ "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
23
+ "groupBy" : ccmcommons .BuildGroupBy (options .GroupBy , ccmcommons .OutputFields , ccmcommons .OutputKeyValueFields ),
24
+ "limit" : options .Limit ,
25
+ "offset" : options .Offset ,
26
+ "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
27
+ "isClusterOnly" : false ,
28
+ "isClusterHourlyData" : false ,
29
+ "preferences" : ccmcommons .BuildPreferences (),
29
30
}
30
31
31
32
payload := map [string ]any {
@@ -36,36 +37,35 @@ func (r *CloudCostManagementService) PerspectiveGrid(ctx context.Context, scope
36
37
37
38
ccmcommons .DebugPayload ("PerspectiveGrid" , payload )
38
39
result := new (dto.CCMPerspectiveGridResponse )
39
- err := r .Client .Post (ctx , path , nil , payload , & result )
40
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
40
41
if err != nil {
41
42
return nil , fmt .Errorf ("failed to get perspective grid: %w" , err )
42
43
}
43
44
return result , nil
44
45
}
45
46
46
47
func (r * CloudCostManagementService ) PerspectiveTimeSeries (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveTimeSeriesOptions ) (* dto.CCMPerspectiveTimeSeriesResponse , error ) {
47
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
48
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
48
49
49
50
gqlQuery := ccmcommons .CCMPerspectiveTimeSeriesQuery
50
51
timeTruncGroupBy := map [string ]any {
51
52
"timeTruncGroupBy" : map [string ]any {"resolution" : options .TimeGroupBy },
52
53
}
53
54
54
-
55
55
entityGroupBy := ccmcommons .BuildGroupBy (options .GroupBy , ccmcommons .OutputFields , ccmcommons .OutputKeyValueFields )
56
56
if len (entityGroupBy ) == 0 {
57
57
return nil , fmt .Errorf ("Missing Group by entity clause" )
58
58
}
59
59
60
60
variables := map [string ]any {
61
- "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
62
- "groupBy" : []map [string ]any {timeTruncGroupBy , entityGroupBy [0 ]},
63
- "limit" : options .Limit ,
64
- "offset" : options .Offset ,
65
- "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
66
- "isClusterOnly" : false ,
67
- "isClusterHourlyData" : false ,
68
- "preferences" : ccmcommons .BuildPreferences (),
61
+ "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
62
+ "groupBy" : []map [string ]any {timeTruncGroupBy , entityGroupBy [0 ]},
63
+ "limit" : options .Limit ,
64
+ "offset" : options .Offset ,
65
+ "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
66
+ "isClusterOnly" : false ,
67
+ "isClusterHourlyData" : false ,
68
+ "preferences" : ccmcommons .BuildPreferences (),
69
69
}
70
70
71
71
payload := map [string ]any {
@@ -76,26 +76,26 @@ func (r *CloudCostManagementService) PerspectiveTimeSeries(ctx context.Context,
76
76
77
77
slog .Debug ("PerspectiveTimeSeries" , "Payload" , payload )
78
78
result := new (dto.CCMPerspectiveTimeSeriesResponse )
79
- err := r .Client .Post (ctx , path , nil , payload , & result )
79
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
80
80
if err != nil {
81
81
return nil , fmt .Errorf ("failed to get perspective grid: %w" , err )
82
82
}
83
83
return result , nil
84
84
}
85
85
86
86
func (r * CloudCostManagementService ) PerspectiveSummaryWithBudget (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveSummaryWithBudgetOptions ) (* dto.CCMPerspectiveSummaryWithBudgetResponse , error ) {
87
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
87
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
88
88
89
89
gqlQuery := ccmcommons .CCMPerspectiveSummaryWithBudgetQuery
90
90
variables := map [string ]any {
91
- "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
92
- "groupBy" : ccmcommons .BuildGroupBy (options .GroupBy , ccmcommons .OutputFields , ccmcommons .OutputKeyValueFields ),
93
- "limit" : options .Limit ,
94
- "offset" : options .Offset ,
95
- "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
96
- "isClusterOnly" : false ,
97
- "isClusterHourlyData" : false ,
98
- "preferences" : ccmcommons .BuildPreferences (),
91
+ "filters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
92
+ "groupBy" : ccmcommons .BuildGroupBy (options .GroupBy , ccmcommons .OutputFields , ccmcommons .OutputKeyValueFields ),
93
+ "limit" : options .Limit ,
94
+ "offset" : options .Offset ,
95
+ "aggregateFunction" : ccmcommons .BuildAggregateFunction (),
96
+ "isClusterOnly" : false ,
97
+ "isClusterHourlyData" : false ,
98
+ "preferences" : ccmcommons .BuildPreferences (),
99
99
}
100
100
101
101
payload := map [string ]any {
@@ -106,19 +106,19 @@ func (r *CloudCostManagementService) PerspectiveSummaryWithBudget(ctx context.Co
106
106
107
107
ccmcommons .DebugPayload ("PerspectiveSummaryWithBudget" , payload )
108
108
result := new (dto.CCMPerspectiveSummaryWithBudgetResponse )
109
- err := r .Client .Post (ctx , path , nil , payload , & result )
109
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
110
110
if err != nil {
111
111
return nil , fmt .Errorf ("failed to get perspective grid: %w" , err )
112
112
}
113
113
return result , nil
114
114
}
115
115
116
116
func (r * CloudCostManagementService ) PerspectiveBudget (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveBudgetOptions ) (* dto.CCMPerspectiveBudgetResponse , error ) {
117
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
117
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
118
118
119
119
gqlQuery := ccmcommons .CCMPerspectiveBudgetQuery
120
120
variables := map [string ]any {
121
- "perspectiveId" : options .PerspectiveId ,
121
+ "perspectiveId" : options .PerspectiveId ,
122
122
}
123
123
124
124
payload := map [string ]any {
@@ -129,19 +129,18 @@ func (r *CloudCostManagementService) PerspectiveBudget(ctx context.Context, scop
129
129
130
130
ccmcommons .DebugPayload ("PerspectiveBudget" , payload )
131
131
result := new (dto.CCMPerspectiveBudgetResponse )
132
- err := r .Client .Post (ctx , path , nil , payload , & result )
132
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
133
133
if err != nil {
134
134
return nil , fmt .Errorf ("failed to get perspective budget: %w" , err )
135
135
}
136
136
return result , nil
137
137
}
138
138
139
139
func (r * CloudCostManagementService ) GetCcmMetadata (ctx context.Context , scope dto.Scope , accountId string ) (* dto.CCMMetadataResponse , error ) {
140
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , accountId , accountId )
140
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , accountId , accountId )
141
141
142
142
gqlQuery := ccmcommons .CCMMetadataQuery
143
- variables := map [string ]any {
144
- }
143
+ variables := map [string ]any {}
145
144
146
145
payload := map [string ]any {
147
146
"query" : gqlQuery ,
@@ -151,24 +150,24 @@ func (r *CloudCostManagementService) GetCcmMetadata(ctx context.Context, scope d
151
150
152
151
ccmcommons .DebugPayload ("FetchCcmMetadata" , payload )
153
152
result := new (dto.CCMMetadataResponse )
154
- err := r .Client .Post (ctx , path , nil , payload , & result )
153
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
155
154
if err != nil {
156
155
return nil , fmt .Errorf ("failed to get perspective budget: %w" , err )
157
156
}
158
157
return result , nil
159
158
}
160
159
161
160
func (r * CloudCostManagementService ) PerspectiveRecommendations (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveRecommendationsOptions ) (* dto.CCMPerspectiveRecommendationsResponse , error ) {
162
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
161
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
163
162
164
163
gqlQuery := ccmcommons .CCMPerspectiveRecommendationsQuery
165
164
166
165
variables := map [string ]any {
167
166
"filter" : map [string ]any {
168
- "perspectiveFilters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
169
- "limit" : options .Limit ,
170
- "offset" : options .Offset ,
171
- "minSaving" : options .MinSaving ,
167
+ "perspectiveFilters" : ccmcommons .BuildFilters (options .ViewId , options .TimeFilter , options .Filters , options .KeyValueFilters ),
168
+ "limit" : options .Limit ,
169
+ "offset" : options .Offset ,
170
+ "minSaving" : options .MinSaving ,
172
171
"recommendationStates" : options .RecommendationStates ,
173
172
},
174
173
}
@@ -181,22 +180,22 @@ func (r *CloudCostManagementService) PerspectiveRecommendations(ctx context.Cont
181
180
182
181
ccmcommons .DebugPayload ("PerspectiveRecommendations" , payload )
183
182
result := new (dto.CCMPerspectiveRecommendationsResponse )
184
- err := r .Client .Post (ctx , path , nil , payload , & result )
183
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
185
184
if err != nil {
186
185
return nil , fmt .Errorf ("failed to get perspective recommendations: %w" , err )
187
186
}
188
187
return result , nil
189
188
}
190
189
191
190
func (r * CloudCostManagementService ) PerspectiveFilterValues (ctx context.Context , scope dto.Scope , options * dto.CCMPerspectiveFilterValuesOptions ) (* dto.CCMPerspectiveFilterValuesResponse , error ) {
192
- path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
191
+ path := fmt .Sprintf (ccmPerspectiveGraphQLPath , options .AccountId , options .AccountId )
193
192
194
193
gqlQuery := ccmcommons .CCMFetchPerspectiveFiltersValueQuery
195
194
196
195
variables := map [string ]any {
197
- "filters" : ccmcommons .BuildFilterValues (options ),
198
- "limit" : options .Limit ,
199
- "offset" : options .Offset ,
196
+ "filters" : ccmcommons .BuildFilterValues (options ),
197
+ "limit" : options .Limit ,
198
+ "offset" : options .Offset ,
200
199
"isClusterHourlyData" : options .IsClusterHourlyData ,
201
200
"sortCriteria" : []map [string ]any {
202
201
{
@@ -214,7 +213,7 @@ func (r *CloudCostManagementService) PerspectiveFilterValues(ctx context.Context
214
213
215
214
ccmcommons .DebugPayload ("FetchPerspectiveFilterValues" , payload )
216
215
result := new (dto.CCMPerspectiveFilterValuesResponse )
217
- err := r .Client .Post (ctx , path , nil , payload , & result )
216
+ err := r .Client .Post (ctx , path , nil , payload , map [ string ] string {}, & result )
218
217
if err != nil {
219
218
return nil , fmt .Errorf ("failed to get perspective filter values: %w" , err )
220
219
}
0 commit comments