Skip to content

Commit bee86ba

Browse files
committed
add a config - hardcoded account/org/project for now
1 parent 51a0e82 commit bee86ba

File tree

5 files changed

+743
-26
lines changed

5 files changed

+743
-26
lines changed

pkg/harness/config.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package harness
2+
3+
import (
4+
"os"
5+
)
6+
7+
// Config holds the configuration for the Harness API client
8+
type Config struct {
9+
BaseURL string
10+
CodeBaseURL string
11+
AccountID string
12+
OrgID string
13+
ProjectID string
14+
}
15+
16+
// NewConfig creates a new Config with default values that can be overridden by environment variables
17+
func NewConfig() *Config {
18+
// Default values
19+
defaultBaseURL := "https://harness0.harness.io/ng/api"
20+
defaultCodeBaseURL := "https://harness0.harness.io/code/api"
21+
defaultAccountID := "l7B_kbSEQD2wjrM7PShm5w"
22+
defaultOrgID := "PROD"
23+
defaultProjectID := "Harness_Commons"
24+
25+
// Environment variables override defaults
26+
baseURL := getEnv("HARNESS_BASE_URL", defaultBaseURL)
27+
codeBaseURL := getEnv("HARNESS_CODE_BASE_URL", defaultCodeBaseURL)
28+
accountID := getEnv("HARNESS_ACCOUNT_ID", defaultAccountID)
29+
orgID := getEnv("HARNESS_ORG_ID", defaultOrgID)
30+
projectID := getEnv("HARNESS_PROJECT_ID", defaultProjectID)
31+
32+
return &Config{
33+
BaseURL: baseURL,
34+
CodeBaseURL: codeBaseURL,
35+
AccountID: accountID,
36+
OrgID: orgID,
37+
ProjectID: projectID,
38+
}
39+
}
40+
41+
// getEnv retrieves an environment variable value or returns a default value if not set
42+
func getEnv(key, defaultValue string) string {
43+
value := os.Getenv(key)
44+
if value == "" {
45+
return defaultValue
46+
}
47+
return value
48+
}
49+
50+
// GetCodeBaseURL returns the base URL for code-related APIs
51+
func (c *Config) GetCodeBaseURL() string {
52+
return c.CodeBaseURL
53+
}

pkg/harness/connectors.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,10 @@ import (
1414
"github.com/mark3labs/mcp-go/server"
1515
)
1616

17-
// Base URL for Harness API
18-
const baseURL = "https://app.harness.io/ng/api"
19-
20-
// Default account, org, and project identifiers
21-
// In a real implementation, these would be configurable
22-
// TODO: remove these
23-
const (
24-
defaultAccountID = "wFHXHD0RRQWoO8tIZT5YVw"
25-
defaultOrgID = "default"
26-
defaultProjectID = "nitisha"
27-
)
28-
2917
// ConnectorClient provides methods to interact with Harness API for connectors
3018
type ConnectorClient struct {
3119
httpClient *http.Client
32-
baseURL string
20+
config *Config
3321
}
3422

3523
// NewConnectorClient creates a new connector client
@@ -38,7 +26,7 @@ func NewConnectorClient() *ConnectorClient {
3826
httpClient: &http.Client{
3927
Timeout: 30 * time.Second,
4028
},
41-
baseURL: baseURL,
29+
config: NewConfig(),
4230
}
4331
}
4432

@@ -61,9 +49,9 @@ func (c *ConnectorClient) ListConnectors(ctx context.Context, connectorNames []s
6149

6250
// Construct the query parameters
6351
params := url.Values{}
64-
params.Add("accountIdentifier", defaultAccountID)
65-
params.Add("orgIdentifier", defaultOrgID)
66-
params.Add("projectIdentifier", defaultProjectID)
52+
params.Add("accountIdentifier", c.config.AccountID)
53+
params.Add("orgIdentifier", c.config.OrgID)
54+
params.Add("projectIdentifier", c.config.ProjectID)
6755
params.Add("getDefaultFromOtherRepo", "true")
6856
params.Add("getDistinctFromBranches", "true")
6957
params.Add("onlyFavorites", "false")
@@ -87,7 +75,7 @@ func (c *ConnectorClient) ListConnectors(ctx context.Context, connectorNames []s
8775
}
8876

8977
// Create a new HTTP request
90-
url := fmt.Sprintf("%s/connectors/listV2?%s", c.baseURL, params.Encode())
78+
url := fmt.Sprintf("%s/connectors/listV2?%s", c.config.BaseURL, params.Encode())
9179
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(reqBodyBytes))
9280
if err != nil {
9381
return nil, fmt.Errorf("failed to create HTTP request: %w", err)

0 commit comments

Comments
 (0)