Skip to content

Commit a0f75d3

Browse files
David-KreinerHarness
authored andcommitted
feat: add internal paths (#12)
* feat: add internal paths
1 parent ed0b11c commit a0f75d3

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

client/pipelines.go

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

1010
const (
11-
pipelinePath = "pipeline/api/pipelines/%s"
12-
pipelineListPath = "pipeline/api/pipelines/list"
13-
pipelineExecutionPath = "pipeline/api/pipelines/execution/url"
14-
pipelineExecutionGetPath = "pipeline/api/pipelines/execution/v2/%s"
15-
pipelineExecutionSummaryPath = "pipeline/api/pipelines/execution/summary"
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/"
1620
)
1721

1822
type PipelineService struct {
1923
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
2032
}
2133

2234
func (p *PipelineService) Get(ctx context.Context, scope dto.Scope, pipelineID string) (
2335
*dto.Entity[dto.PipelineData],
2436
error,
2537
) {
26-
path := fmt.Sprintf(pipelinePath, pipelineID)
38+
pathTemplate := p.buildPath(pipelinePath)
39+
path := fmt.Sprintf(pathTemplate, pipelineID)
2740

2841
// Prepare query parameters
2942
params := make(map[string]string)
@@ -46,6 +59,7 @@ func (p *PipelineService) List(
4659
scope dto.Scope,
4760
opts *dto.PipelineListOptions,
4861
) (*dto.ListOutput[dto.PipelineListItem], error) {
62+
path := p.buildPath(pipelineListPath)
4963
// Prepare query parameters
5064
params := make(map[string]string)
5165
addScope(scope, params)
@@ -76,7 +90,7 @@ func (p *PipelineService) List(
7690
response := &dto.ListOutput[dto.PipelineListItem]{}
7791

7892
// Make the POST request
79-
err := p.Client.Post(ctx, pipelineListPath, params, requestBody, response)
93+
err := p.Client.Post(ctx, path, params, requestBody, response)
8094
if err != nil {
8195
return nil, err
8296
}
@@ -89,6 +103,7 @@ func (p *PipelineService) ListExecutions(
89103
scope dto.Scope,
90104
opts *dto.PipelineExecutionOptions,
91105
) (*dto.ListOutput[dto.PipelineExecution], error) {
106+
path := p.buildPath(pipelineExecutionSummaryPath)
92107
// Prepare query parameters
93108
params := make(map[string]string)
94109
addScope(scope, params)
@@ -132,7 +147,7 @@ func (p *PipelineService) ListExecutions(
132147
response := &dto.ListOutput[dto.PipelineExecution]{}
133148

134149
// Make the POST request
135-
err := p.Client.Post(ctx, pipelineExecutionSummaryPath, params, requestBody, response)
150+
err := p.Client.Post(ctx, path, params, requestBody, response)
136151
if err != nil {
137152
return nil, fmt.Errorf("failed to list pipeline executions: %w", err)
138153
}
@@ -146,7 +161,8 @@ func (p *PipelineService) GetExecution(
146161
scope dto.Scope,
147162
planExecutionID string,
148163
) (*dto.Entity[dto.PipelineExecution], error) {
149-
path := fmt.Sprintf(pipelineExecutionGetPath, planExecutionID)
164+
pathTemplate := p.buildPath(pipelineExecutionGetPath)
165+
path := fmt.Sprintf(pathTemplate, planExecutionID)
150166

151167
// Prepare query parameters
152168
params := make(map[string]string)
@@ -175,7 +191,7 @@ func (p *PipelineService) FetchExecutionURL(
175191
scope dto.Scope,
176192
pipelineID, planExecutionID string,
177193
) (string, error) {
178-
path := pipelineExecutionPath
194+
path := p.buildPath(pipelineExecutionPath)
179195

180196
// Prepare query parameters
181197
params := make(map[string]string)

pkg/harness/tools.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ func registerPipelines(config *config.Config, tsg *toolsets.ToolsetGroup) error
100100
return err
101101
}
102102

103-
pipelineClient := &client.PipelineService{Client: c}
103+
pipelineClient := &client.PipelineService{
104+
Client: c,
105+
UseInternalPaths: config.Internal,
106+
}
104107

105108
// Create the pipelines toolset
106109
pipelines := toolsets.NewToolset("pipelines", "Harness Pipeline related tools").

0 commit comments

Comments
 (0)