Skip to content

Commit 2d06431

Browse files
authored
Merge pull request #20 from jamestoyer/override-circle-endpoint
Ability to specify custom Circle Endpoint added
2 parents 169b672 + 728dd7b commit 2d06431

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

circleci/provider.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ func Provider() terraform.ResourceProvider {
2626
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_ORGANIZATION", nil),
2727
Description: "The CircleCI organization.",
2828
},
29+
"url": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_URL", "https://circleci.com/api/v1.1"),
33+
Description: "The URL of the Circle CI API.",
34+
},
2935
},
3036
ResourcesMap: map[string]*schema.Resource{
3137
"circleci_environment_variable": resourceCircleCIEnvironmentVariable(),
@@ -38,5 +44,6 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
3844
token := d.Get("api_token").(string)
3945
vcsType := d.Get("vcs_type").(string)
4046
organization := d.Get("organization").(string)
41-
return NewConfig(token, vcsType, organization), nil
47+
url := d.Get("url").(string)
48+
return NewConfig(token, vcsType, organization, url)
4249
}

circleci/provider_client.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package circleci
22

33
import (
4+
"net/url"
5+
46
circleciapi "github.com/jszwedko/go-circleci"
57
)
68

@@ -12,14 +14,20 @@ type ProviderClient struct {
1214
}
1315

1416
// NewConfig initialize circleci API client and returns a new config object
15-
func NewConfig(token, vscType, organization string) *ProviderClient {
17+
func NewConfig(token, vscType, organization, baseURL string) (*ProviderClient, error) {
18+
parsedUrl, err := url.Parse(baseURL)
19+
if err != nil {
20+
return nil, err
21+
}
22+
1623
return &ProviderClient{
1724
client: &circleciapi.Client{
18-
Token: token,
25+
BaseURL: parsedUrl,
26+
Token: token,
1927
},
2028
vcsType: vscType,
2129
organization: organization,
22-
}
30+
}, nil
2331
}
2432

2533
// GetEnvVar get the environment variable with given name

0 commit comments

Comments
 (0)