Skip to content

Commit

Permalink
Merge pull request #20 from jamestoyer/override-circle-endpoint
Browse files Browse the repository at this point in the history
Ability to specify custom Circle Endpoint added
  • Loading branch information
mrolla authored Jun 27, 2019
2 parents 169b672 + 728dd7b commit 2d06431
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion circleci/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_ORGANIZATION", nil),
Description: "The CircleCI organization.",
},
"url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_URL", "https://circleci.com/api/v1.1"),
Description: "The URL of the Circle CI API.",
},
},
ResourcesMap: map[string]*schema.Resource{
"circleci_environment_variable": resourceCircleCIEnvironmentVariable(),
Expand All @@ -38,5 +44,6 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
token := d.Get("api_token").(string)
vcsType := d.Get("vcs_type").(string)
organization := d.Get("organization").(string)
return NewConfig(token, vcsType, organization), nil
url := d.Get("url").(string)
return NewConfig(token, vcsType, organization, url)
}
14 changes: 11 additions & 3 deletions circleci/provider_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package circleci

import (
"net/url"

circleciapi "github.com/jszwedko/go-circleci"
)

Expand All @@ -12,14 +14,20 @@ type ProviderClient struct {
}

// NewConfig initialize circleci API client and returns a new config object
func NewConfig(token, vscType, organization string) *ProviderClient {
func NewConfig(token, vscType, organization, baseURL string) (*ProviderClient, error) {
parsedUrl, err := url.Parse(baseURL)
if err != nil {
return nil, err
}

return &ProviderClient{
client: &circleciapi.Client{
Token: token,
BaseURL: parsedUrl,
Token: token,
},
vcsType: vscType,
organization: organization,
}
}, nil
}

// GetEnvVar get the environment variable with given name
Expand Down

0 comments on commit 2d06431

Please sign in to comment.