Skip to content

Commit

Permalink
Deprecate individual flag for provider configuration (#512)
Browse files Browse the repository at this point in the history
* Deprecate `anonymous` flag for provider configuration

* Add Configuration Tests

* fixup! Fix Spelling

* fixup! hard-code values for CI environment

* Deprecate `individual` flag for provider configuration
  • Loading branch information
Jeremy Udit authored Jul 14, 2020
1 parent d9623ba commit 56363f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions github/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,25 @@ func TestConfigClients(t *testing.T) {
t.Fatalf("failed to return a v3 client")
}
})

t.Run("returns clients configured as individual", func(t *testing.T) {
config := Config{
Organization: "",
Anonymous: true,
Individual: true,
}

meta, err := config.Clients()
if err != nil {
t.Fatalf("failed to return clients without error: %s", err.Error())
}

if client := meta.(*Organization).v4client; client == nil {
t.Fatalf("failed to return a v4 client")
}

if client := meta.(*Organization).v3client; client == nil {
t.Fatalf("failed to return a v3 client")
}
})
}
15 changes: 10 additions & 5 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["insecure"],
},
"individual": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: descriptions["individual"],
Type: schema.TypeBool,
Optional: true,
Default: false,
Deprecated: "For versions later than 3.0.0, absence of an organization enables this mode",
},
"anonymous": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -124,12 +124,17 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
anonymous = false
}

individual := true
if d.Get("organization").(string) != "" {
individual = false
}

config := Config{
Token: d.Get("token").(string),
Organization: d.Get("organization").(string),
BaseURL: d.Get("base_url").(string),
Insecure: d.Get("insecure").(bool),
Individual: d.Get("individual").(bool),
Individual: individual,
Anonymous: anonymous,
}

Expand Down

0 comments on commit 56363f5

Please sign in to comment.