Skip to content

Commit efea3f5

Browse files
David-KreinerHarness
authored andcommitted
feat: [ML-1172]: Adding support for internal mode (#33)
* feat: [ML-1172]: skip log service for now * feat: [ML-1172]: fix idp from rebase * feat: [ML-1172]: Adding better formatting for baseURLs * feat: [ML-1172]: Adding support for internal mode * feat: [ML-1172]: fix internal mode * feat: [ML-1172]: Expose more tools for internal mode
1 parent cd30e94 commit efea3f5

File tree

16 files changed

+144
-167
lines changed

16 files changed

+144
-167
lines changed

client/chaos.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/harness/harness-mcp/client/dto"
78
)
89

@@ -12,28 +13,16 @@ const (
1213
chaosGetExperimentPath = "api/rest/v2/experiments/%s"
1314
chaosGetExperimentRunPath = "api/rest/v2/experiments/%s/run"
1415
chaosExperimentRunPath = "api/rest/v2/experiments/%s/run"
15-
16-
// Prefix to prepend for external API calls
17-
externalChaosManagerPathPrefix = "chaos/manager/"
1816
)
1917

2018
type ChaosService struct {
21-
Client *Client
22-
UseInternalPaths bool
23-
}
24-
25-
func (c *ChaosService) buildPath(basePath string) string {
26-
if c.UseInternalPaths {
27-
return basePath
28-
}
29-
return externalChaosManagerPathPrefix + basePath
19+
Client *Client
3020
}
3121

3222
func (c *ChaosService) ListExperiments(ctx context.Context, scope dto.Scope, pagination *dto.PaginationOptions) (*dto.ListExperimentResponse, error) {
3323
var (
34-
pathTemplate = c.buildPath(chaosListExperimentsPath)
35-
path = fmt.Sprintf(pathTemplate)
36-
params = make(map[string]string)
24+
path = chaosListExperimentsPath
25+
params = make(map[string]string)
3726
)
3827

3928
// Set default pagination
@@ -56,9 +45,8 @@ func (c *ChaosService) ListExperiments(ctx context.Context, scope dto.Scope, pag
5645

5746
func (c *ChaosService) GetExperiment(ctx context.Context, scope dto.Scope, experimentID string) (*dto.GetExperimentResponse, error) {
5847
var (
59-
pathTemplate = c.buildPath(chaosGetExperimentPath)
60-
path = fmt.Sprintf(pathTemplate, experimentID)
61-
params = make(map[string]string)
48+
path = fmt.Sprintf(chaosGetExperimentPath, experimentID)
49+
params = make(map[string]string)
6250
)
6351

6452
// Add scope parameters
@@ -75,9 +63,8 @@ func (c *ChaosService) GetExperiment(ctx context.Context, scope dto.Scope, exper
7563

7664
func (c *ChaosService) GetExperimentRun(ctx context.Context, scope dto.Scope, experimentID, experimentRunID string) (*dto.ChaosExperimentRun, error) {
7765
var (
78-
pathTemplate = c.buildPath(chaosGetExperimentRunPath)
79-
path = fmt.Sprintf(pathTemplate, experimentID)
80-
params = make(map[string]string)
66+
path = fmt.Sprintf(chaosGetExperimentRunPath, experimentID)
67+
params = make(map[string]string)
8168
)
8269

8370
params["experimentRunId"] = experimentRunID
@@ -95,9 +82,8 @@ func (c *ChaosService) GetExperimentRun(ctx context.Context, scope dto.Scope, ex
9582

9683
func (c *ChaosService) RunExperiment(ctx context.Context, scope dto.Scope, experimentID string) (*dto.RunChaosExperimentResponse, error) {
9784
var (
98-
pathTemplate = c.buildPath(chaosExperimentRunPath)
99-
path = fmt.Sprintf(pathTemplate, experimentID)
100-
params = make(map[string]string)
85+
path = fmt.Sprintf(chaosExperimentRunPath, experimentID)
86+
params = make(map[string]string)
10187
)
10288

10389
// Add scope parameters

client/connectors.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import (
88
pkgDTO "github.com/harness/harness-mcp/pkg/harness/dto" // Alias for the other DTOs
99
)
1010

11+
const (
12+
listConnectorCataloguePath = "/api/connectors/catalogue"
13+
getConnectorPath = "/api/connectors/%s"
14+
)
15+
1116
type ConnectorService struct {
1217
Client *Client
1318
}
1419

1520
// ListConnectorCatalogue fetches the connector catalogue.
1621
// API Documentation: https://apidocs.harness.io/tag/Connectors#operation/getConnectorCatalogue
1722
func (c *ConnectorService) ListConnectorCatalogue(ctx context.Context, scope dto.Scope) ([]pkgDTO.ConnectorCatalogueItem, error) {
18-
path := "/ng/api/connectors/catalogue"
23+
path := listConnectorCataloguePath
1924
params := make(map[string]string)
2025
params["accountIdentifier"] = scope.AccountID
2126
if scope.OrgID != "" {
@@ -61,7 +66,7 @@ func (c *ConnectorService) ListConnectorCatalogue(ctx context.Context, scope dto
6166
// GetConnector retrieves a connector by its identifier
6267
// https://apidocs.harness.io/tag/Connectors#operation/getConnector
6368
func (c *ConnectorService) GetConnector(ctx context.Context, scope dto.Scope, connectorIdentifier string) (*pkgDTO.ConnectorDetail, error) {
64-
path := fmt.Sprintf("/ng/api/connectors/%s", connectorIdentifier)
69+
path := fmt.Sprintf(getConnectorPath, connectorIdentifier)
6570
params := make(map[string]string)
6671
// Ensure accountIdentifier is always set
6772
if scope.AccountID == "" {

client/dashboard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
)
1515

1616
const (
17-
dashboardSearchPath = "dashboard/v1/search"
18-
dashboardDataPath = "dashboard/download/dashboards/%s/csv"
17+
dashboardSearchPath = "/v1/search"
18+
dashboardDataPath = "/download/dashboards/%s/csv"
1919
)
2020

2121
// DashboardService handles all dashboard-related API interactions

client/environments.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
)
99

1010
const (
11-
environmentBasePath = "ng/api/environments"
12-
environmentGetPath = environmentBasePath + "/%s"
13-
environmentListPath = environmentBasePath
14-
environmentMoveConfigsPath = environmentBasePath + "V2/move-config/%s"
11+
environmentListPath = "/api/environments"
12+
environmentGetPath = "/api/environments/%s"
13+
environmentMoveConfigsPath = "/api/environments/V2/move-config/%s"
1514
)
1615

1716
type EnvironmentClient struct {

client/idp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ const (
2727
)
2828

2929
type IDPService struct {
30-
Client *Client
31-
UseInternalPaths bool
30+
Client *Client
3231
}
3332

3433
func (i *IDPService) GetEntity(ctx context.Context, scope dto.Scope, kind string, identifier string) (*dto.EntityResponse, error) {

client/infrastructure.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
)
99

1010
const (
11-
infrastructureBasePath = "ng/api/infrastructures"
12-
infrastructureListPath = infrastructureBasePath
13-
infrastructureMoveConfigsPath = infrastructureBasePath + "/move-config/%s"
11+
infrastructureListPath = "/api/infrastructures"
12+
infrastructureMoveConfigsPath = "/api/infrastructures/move-config/%s"
1413
)
1514

1615
type InfrastructureClient struct {

client/logs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ import (
99
)
1010

1111
const (
12-
logDownloadPath = "log-service/blob/download"
12+
logDownloadPath = "/blob/download"
1313
)
1414

1515
// LogService handles operations related to pipeline logs
1616
type LogService struct {
17-
Client *Client
17+
LogServiceClient *Client
18+
PipelineClient *Client
1819
}
1920

2021
// DownloadLogs fetches a download URL for pipeline execution logs
2122
func (l *LogService) DownloadLogs(ctx context.Context, scope dto.Scope, planExecutionID string) (string, error) {
2223
// First, get the pipeline execution details to determine the prefix format
23-
pipelineService := &PipelineService{Client: l.Client} // TODO: needs to be changed for internal case, we should move this above
24+
pipelineService := &PipelineService{Client: l.PipelineClient} // TODO: needs to be changed for internal case, we should move this above
2425
execution, err := pipelineService.GetExecution(ctx, scope, planExecutionID)
2526
if err != nil {
2627
return "", fmt.Errorf("failed to get execution details: %w", err)
@@ -61,7 +62,7 @@ func (l *LogService) DownloadLogs(ctx context.Context, scope dto.Scope, planExec
6162

6263
for attempt := 1; attempt <= maxAttempts; attempt++ {
6364
response = &dto.LogDownloadResponse{}
64-
err = l.Client.Post(ctx, logDownloadPath, params, nil, response)
65+
err = l.LogServiceClient.Post(ctx, logDownloadPath, params, nil, response)
6566
if err != nil {
6667
lastErr = fmt.Errorf("failed to fetch log download URL (attempt %d): %w", attempt, err)
6768
if attempt == maxAttempts {

client/pipelines.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ import (
88
)
99

1010
const (
11-
// Base API paths
12-
pipelinePath = "api/pipelines/%s"
13-
pipelineListPath = "api/pipelines/list"
14-
pipelineExecutionPath = "api/pipelines/execution/url"
15-
pipelineExecutionGetPath = "api/pipelines/execution/v2/%s"
16-
pipelineExecutionSummaryPath = "api/pipelines/execution/summary"
17-
18-
// Prefix to prepend for external API calls
19-
externalPathPrefix = "pipeline/"
11+
pipelinePath = "/api/pipelines/%s"
12+
pipelineListPath = "/api/pipelines/list"
13+
pipelineExecutionPath = "/api/pipelines/execution/url"
14+
pipelineExecutionGetPath = "/api/pipelines/execution/v2/%s"
15+
pipelineExecutionSummaryPath = "/api/pipelines/execution/summary"
2016
)
2117

2218
type PipelineService struct {
23-
Client *Client
24-
UseInternalPaths bool
25-
}
26-
27-
func (p *PipelineService) buildPath(basePath string) string {
28-
if p.UseInternalPaths {
29-
return basePath
30-
}
31-
return externalPathPrefix + basePath
19+
Client *Client
3220
}
3321

3422
func (p *PipelineService) Get(ctx context.Context, scope dto.Scope, pipelineID string) (
3523
*dto.Entity[dto.PipelineData],
3624
error,
3725
) {
38-
pathTemplate := p.buildPath(pipelinePath)
39-
path := fmt.Sprintf(pathTemplate, pipelineID)
26+
path := fmt.Sprintf(pipelinePath, pipelineID)
4027

4128
// Prepare query parameters
4229
params := make(map[string]string)
@@ -59,7 +46,7 @@ func (p *PipelineService) List(
5946
scope dto.Scope,
6047
opts *dto.PipelineListOptions,
6148
) (*dto.ListOutput[dto.PipelineListItem], error) {
62-
path := p.buildPath(pipelineListPath)
49+
path := pipelineListPath
6350
// Prepare query parameters
6451
params := make(map[string]string)
6552
addScope(scope, params)
@@ -103,7 +90,7 @@ func (p *PipelineService) ListExecutions(
10390
scope dto.Scope,
10491
opts *dto.PipelineExecutionOptions,
10592
) (*dto.ListOutput[dto.PipelineExecution], error) {
106-
path := p.buildPath(pipelineExecutionSummaryPath)
93+
path := pipelineExecutionSummaryPath
10794
// Prepare query parameters
10895
params := make(map[string]string)
10996
addScope(scope, params)
@@ -161,8 +148,7 @@ func (p *PipelineService) GetExecution(
161148
scope dto.Scope,
162149
planExecutionID string,
163150
) (*dto.Entity[dto.PipelineExecution], error) {
164-
pathTemplate := p.buildPath(pipelineExecutionGetPath)
165-
path := fmt.Sprintf(pathTemplate, planExecutionID)
151+
path := fmt.Sprintf(pipelineExecutionGetPath, planExecutionID)
166152

167153
// Prepare query parameters
168154
params := make(map[string]string)
@@ -191,7 +177,7 @@ func (p *PipelineService) FetchExecutionURL(
191177
scope dto.Scope,
192178
pipelineID, planExecutionID string,
193179
) (string, error) {
194-
path := p.buildPath(pipelineExecutionPath)
180+
path := pipelineExecutionPath
195181

196182
// Prepare query parameters
197183
params := make(map[string]string)

client/pullrequest.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import (
99
)
1010

1111
const (
12-
pullRequestBasePath = "code/api/v1/repos"
13-
pullRequestGetPath = pullRequestBasePath + "/%s/pullreq/%d"
14-
pullRequestListPath = pullRequestBasePath + "/%s/pullreq"
15-
pullRequestCreatePath = pullRequestBasePath + "/%s/pullreq"
16-
pullRequestChecksPath = pullRequestBasePath + "/%s/pullreq/%d/checks"
17-
pullRequestActivitiesPath = pullRequestBasePath + "/%s/pullreq/%d/activities"
12+
pullRequestGetPath = "/api/v1/repos/%s/pullreq/%d"
13+
pullRequestListPath = "/api/v1/repos/%s/pullreq"
14+
pullRequestCreatePath = "/api/v1/repos/%s/pullreq"
15+
pullRequestChecksPath = "/api/v1/repos/%s/pullreq/%d/checks"
16+
pullRequestActivitiesPath = "/api/v1/repos/%s/pullreq/%d/activities"
1817
)
1918

2019
type PullRequestService struct {

client/repositories.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
)
99

1010
const (
11-
repositoryBasePath = "code/api/v1/repos"
12-
repositoryGetPath = repositoryBasePath + "/%s"
13-
repositoryListPath = repositoryBasePath
11+
repositoryBasePath = "/api/v1/repos"
12+
repositoryGetPath = "/api/v1/repos/%s"
1413
)
1514

1615
type RepositoryService struct {
@@ -48,7 +47,7 @@ func setDefaultPaginationForRepo(opts *dto.RepositoryOptions) {
4847
}
4948

5049
func (r *RepositoryService) List(ctx context.Context, scope dto.Scope, opts *dto.RepositoryOptions) ([]*dto.Repository, error) {
51-
path := repositoryListPath
50+
path := repositoryBasePath
5251
params := make(map[string]string)
5352
addScope(scope, params)
5453

0 commit comments

Comments
 (0)