Skip to content

Commit bba5e93

Browse files
harjas27Harness
authored andcommitted
[feat]:[IDP-6019]: Add headers in POST request (#126)
* [feat]:[IDP-6019]: Add headers in POST request
1 parent 9dceed1 commit bba5e93

17 files changed

+118
-114
lines changed

client/accesscontrol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (u *PrincipalService) GetAllUsers(ctx context.Context, scope dto.Scope, sea
4040
addScope(scope, params)
4141

4242
resp := &dto.AccessControlOutput[dto.UsersOutput]{}
43-
err := u.Client.Post(ctx, getUsersPath, params, opts, resp)
43+
err := u.Client.Post(ctx, getUsersPath, params, opts, map[string]string{}, resp)
4444
if err != nil {
4545
return nil, fmt.Errorf("failed to list the users: %w", err)
4646
}
@@ -152,7 +152,7 @@ func (ra *RBACService) ListRoleAssignmentsTool(ctx context.Context, scope dto.Sc
152152
}
153153

154154
resp := &dto.AccessControlOutput[dto.RoleAssignmentsOutputData]{}
155-
err := ra.Client.Post(ctx, listRoleAssignmentsPath, params, opts, resp)
155+
err := ra.Client.Post(ctx, listRoleAssignmentsPath, params, opts, map[string]string{}, resp)
156156
if err != nil {
157157
optsJSON, _ := json.MarshalIndent(opts, "", " ")
158158
return nil, fmt.Errorf("failed to list the role assignments: %w\nRequest body: %s", err, string(optsJSON))

client/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (a *AuditService) ListUserAuditTrail(ctx context.Context, scope dto.Scope,
8181
opts.EndTime = endTime
8282

8383
resp := &dto.AuditOutput[dto.AuditListItem]{}
84-
err := a.Client.Post(ctx, auditPath, params, opts, resp)
84+
err := a.Client.Post(ctx, auditPath, params, opts, map[string]string{}, resp)
8585
if err != nil {
8686
return nil, fmt.Errorf("failed to list the audit trail: %w", err)
8787
}

client/ccmcommitments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *CloudCostManagementService) getEstimatedSavingsResponse(ctx context.Con
7979
// Temporary slice to hold the strings
8080
baseResponse := new(dto.CCMCommitmentBaseResponse)
8181

82-
err := r.Client.Post(ctx, path, params, requestPayload, baseResponse)
82+
err := r.Client.Post(ctx, path, params, requestPayload, map[string]string{}, baseResponse)
8383
if err != nil {
8484
return nil, fmt.Errorf("failed to get cloud cost managment estimated savings response with path %s: %w", path, err)
8585
}

client/ccmcosts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (r *CloudCostManagementService) GetComputeCoverage(ctx context.Context, sco
183183
// Temporary slice to hold the strings
184184
coverageRespone := new(dto.CCMCommitmentBaseResponse)
185185

186-
err := r.Client.Post(ctx, path, params, requestPayload, coverageRespone)
186+
err := r.Client.Post(ctx, path, params, requestPayload, map[string]string{}, coverageRespone)
187187
if err != nil {
188188
return nil, fmt.Errorf("failed to get cloud cost managment compute coverage with path %s: %w", path, err)
189189
}
@@ -234,7 +234,7 @@ func (r *CloudCostManagementService) GetCommitmentSavings(ctx context.Context, s
234234

235235
savingsResponse := new(dto.CCMCommitmentBaseResponse)
236236

237-
err := r.Client.Post(ctx, path, params, requestPayload, savingsResponse)
237+
err := r.Client.Post(ctx, path, params, requestPayload, map[string]string{}, savingsResponse)
238238
if err != nil {
239239
return nil, fmt.Errorf("failed to get cloud cost management compute savings with path %s: %w", path, err)
240240
}
@@ -281,7 +281,7 @@ func (r *CloudCostManagementService) GetCommitmentUtilisation(ctx context.Contex
281281
// Temporary slice to hold the strings
282282
utilisationResponse := new(dto.CCMCommitmentBaseResponse)
283283

284-
err := r.Client.Post(ctx, path, params, requestPayload, utilisationResponse)
284+
err := r.Client.Post(ctx, path, params, requestPayload, map[string]string{}, utilisationResponse)
285285
if err != nil {
286286
return nil, fmt.Errorf("failed to get cloud cost managment compute utilisation with path %s: %w", path, err)
287287
}

client/ccmgraphqlperspectives.go

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@ import (
44
"context"
55
"fmt"
66
"log/slog"
7-
"github.com/harness/harness-mcp/client/dto"
7+
88
"github.com/harness/harness-mcp/client/ccmcommons"
9+
"github.com/harness/harness-mcp/client/dto"
910
)
1011

1112
const (
12-
ccmGraphQLBasePath = ccmBasePath + "/graphql"
13+
ccmGraphQLBasePath = ccmBasePath + "/graphql"
1314
ccmPerspectiveGraphQLPath = ccmGraphQLBasePath + "?accountIdentifier=%s&routingId=%s"
1415
)
1516

1617
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)
1819

1920
gqlQuery := ccmcommons.CCMPerspectiveGridQuery
2021
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(),
2930
}
3031

3132
payload := map[string]any{
@@ -36,36 +37,35 @@ func (r *CloudCostManagementService) PerspectiveGrid(ctx context.Context, scope
3637

3738
ccmcommons.DebugPayload("PerspectiveGrid", payload)
3839
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)
4041
if err != nil {
4142
return nil, fmt.Errorf("failed to get perspective grid: %w", err)
4243
}
4344
return result, nil
4445
}
4546

4647
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)
4849

4950
gqlQuery := ccmcommons.CCMPerspectiveTimeSeriesQuery
5051
timeTruncGroupBy := map[string]any{
5152
"timeTruncGroupBy": map[string]any{"resolution": options.TimeGroupBy},
5253
}
5354

54-
5555
entityGroupBy := ccmcommons.BuildGroupBy(options.GroupBy, ccmcommons.OutputFields, ccmcommons.OutputKeyValueFields)
5656
if len(entityGroupBy) == 0 {
5757
return nil, fmt.Errorf("Missing Group by entity clause")
5858
}
5959

6060
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(),
6969
}
7070

7171
payload := map[string]any{
@@ -76,26 +76,26 @@ func (r *CloudCostManagementService) PerspectiveTimeSeries(ctx context.Context,
7676

7777
slog.Debug("PerspectiveTimeSeries", "Payload", payload)
7878
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)
8080
if err != nil {
8181
return nil, fmt.Errorf("failed to get perspective grid: %w", err)
8282
}
8383
return result, nil
8484
}
8585

8686
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)
8888

8989
gqlQuery := ccmcommons.CCMPerspectiveSummaryWithBudgetQuery
9090
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(),
9999
}
100100

101101
payload := map[string]any{
@@ -106,19 +106,19 @@ func (r *CloudCostManagementService) PerspectiveSummaryWithBudget(ctx context.Co
106106

107107
ccmcommons.DebugPayload("PerspectiveSummaryWithBudget", payload)
108108
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)
110110
if err != nil {
111111
return nil, fmt.Errorf("failed to get perspective grid: %w", err)
112112
}
113113
return result, nil
114114
}
115115

116116
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)
118118

119119
gqlQuery := ccmcommons.CCMPerspectiveBudgetQuery
120120
variables := map[string]any{
121-
"perspectiveId": options.PerspectiveId,
121+
"perspectiveId": options.PerspectiveId,
122122
}
123123

124124
payload := map[string]any{
@@ -129,19 +129,18 @@ func (r *CloudCostManagementService) PerspectiveBudget(ctx context.Context, scop
129129

130130
ccmcommons.DebugPayload("PerspectiveBudget", payload)
131131
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)
133133
if err != nil {
134134
return nil, fmt.Errorf("failed to get perspective budget: %w", err)
135135
}
136136
return result, nil
137137
}
138138

139139
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)
141141

142142
gqlQuery := ccmcommons.CCMMetadataQuery
143-
variables := map[string]any{
144-
}
143+
variables := map[string]any{}
145144

146145
payload := map[string]any{
147146
"query": gqlQuery,
@@ -151,24 +150,24 @@ func (r *CloudCostManagementService) GetCcmMetadata(ctx context.Context, scope d
151150

152151
ccmcommons.DebugPayload("FetchCcmMetadata", payload)
153152
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)
155154
if err != nil {
156155
return nil, fmt.Errorf("failed to get perspective budget: %w", err)
157156
}
158157
return result, nil
159158
}
160159

161160
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)
163162

164163
gqlQuery := ccmcommons.CCMPerspectiveRecommendationsQuery
165164

166165
variables := map[string]any{
167166
"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,
172171
"recommendationStates": options.RecommendationStates,
173172
},
174173
}
@@ -181,22 +180,22 @@ func (r *CloudCostManagementService) PerspectiveRecommendations(ctx context.Cont
181180

182181
ccmcommons.DebugPayload("PerspectiveRecommendations", payload)
183182
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)
185184
if err != nil {
186185
return nil, fmt.Errorf("failed to get perspective recommendations: %w", err)
187186
}
188187
return result, nil
189188
}
190189

191190
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)
193192

194193
gqlQuery := ccmcommons.CCMFetchPerspectiveFiltersValueQuery
195194

196195
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,
200199
"isClusterHourlyData": options.IsClusterHourlyData,
201200
"sortCriteria": []map[string]any{
202201
{
@@ -214,7 +213,7 @@ func (r *CloudCostManagementService) PerspectiveFilterValues(ctx context.Context
214213

215214
ccmcommons.DebugPayload("FetchPerspectiveFilterValues", payload)
216215
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)
218217
if err != nil {
219218
return nil, fmt.Errorf("failed to get perspective filter values: %w", err)
220219
}

0 commit comments

Comments
 (0)