|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "github.com/harness/harness-mcp/client/dto" |
| 7 | +) |
| 8 | +const ( |
| 9 | + ccmRecommendationsListPath = ccmBasePath + "/recommendation/overview/list?accountIdentifier=%s" |
| 10 | + ccmRecommendationsByResourceTypeListPath = ccmBasePath + "/recommendation/overview/resource-type/stats?accountIdentifier=%s" |
| 11 | + ccmRecommendationsStatsPath = ccmBasePath + "/recommendation/overview/stats?accountIdentifier=%s" |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +func (r *CloudCostManagementService) ListRecommendations(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) { |
| 16 | + |
| 17 | + return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsListPath) |
| 18 | +} |
| 19 | + |
| 20 | +func (r *CloudCostManagementService) ListRecommendationsByResourceType(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) { |
| 21 | + |
| 22 | + return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsByResourceTypeListPath) |
| 23 | +} |
| 24 | + |
| 25 | +func (r *CloudCostManagementService) GetRecommendationsStats(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) { |
| 26 | + |
| 27 | + return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsStatsPath) |
| 28 | +} |
| 29 | + |
| 30 | +func (r *CloudCostManagementService) getRecommendations( |
| 31 | + ctx context.Context, |
| 32 | + scope dto.Scope, |
| 33 | + accountId string, |
| 34 | + options map[string]any, |
| 35 | + url string, |
| 36 | +) (*map[string]any, error) { |
| 37 | + |
| 38 | + path := fmt.Sprintf(url, accountId) |
| 39 | + params := make(map[string]string) |
| 40 | + addScope(scope, params) |
| 41 | + |
| 42 | + items := new(map[string]any) |
| 43 | + |
| 44 | + err := r.Client.Post(ctx, path, params, options, &items) |
| 45 | + if err != nil { |
| 46 | + return nil, fmt.Errorf("Failed to list cloud cost management recommendations: %w", err) |
| 47 | + } |
| 48 | + |
| 49 | + return items, nil |
| 50 | +} |
0 commit comments