Skip to content

Commit b48779a

Browse files
authored
[BUG] Revert anon auth complication (#3071)
* Change provider schema to use `ConflictsWith` to re-enable having an empty `provider` block Signed-off-by: Timo Sand <[email protected]> * Add DEBUG message to failed `gh` CLI auth Signed-off-by: Timo Sand <[email protected]> * Fix anon test to actually run anonumously Signed-off-by: Timo Sand <[email protected]> * Change GHES test to be able to run on GHES config Signed-off-by: Timo Sand <[email protected]> * Removed unnecessary skips Signed-off-by: Timo Sand <[email protected]> --------- Signed-off-by: Timo Sand <[email protected]>
1 parent f4a5b1a commit b48779a

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

github/provider.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func Provider() *schema.Provider {
1818
p := &schema.Provider{
1919
Schema: map[string]*schema.Schema{
2020
"token": {
21-
Type: schema.TypeString,
22-
Optional: true,
23-
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
24-
Description: descriptions["token"],
25-
ExactlyOneOf: []string{"app_auth"},
21+
Type: schema.TypeString,
22+
Optional: true,
23+
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
24+
Description: descriptions["token"],
25+
ConflictsWith: []string{"app_auth"},
2626
},
2727
"owner": {
2828
Type: schema.TypeString,
@@ -94,11 +94,11 @@ func Provider() *schema.Provider {
9494
Description: descriptions["parallel_requests"],
9595
},
9696
"app_auth": {
97-
Type: schema.TypeList,
98-
Optional: true,
99-
MaxItems: 1,
100-
Description: descriptions["app_auth"],
101-
ExactlyOneOf: []string{"token"},
97+
Type: schema.TypeList,
98+
Optional: true,
99+
MaxItems: 1,
100+
Description: descriptions["app_auth"],
101+
ConflictsWith: []string{"token"},
102102
Elem: &schema.Resource{
103103
Schema: map[string]*schema.Schema{
104104
"id": {
@@ -505,6 +505,7 @@ func tokenFromGHCLI(u *url.URL) string {
505505

506506
out, err := exec.Command(ghCliPath, "auth", "token", "--hostname", host).Output()
507507
if err != nil {
508+
log.Printf("[DEBUG] Error getting token from GitHub CLI: %s", err.Error())
508509
// GH CLI is either not installed or there was no `gh auth login` command issued,
509510
// which is fine. don't return the error to keep the flow going
510511
return ""

github/provider_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func TestAccProviderConfigure(t *testing.T) {
5454
t.Run("can be configured to run anonymously", func(t *testing.T) {
5555
config := `
5656
provider "github" {
57-
token = ""
5857
}
5958
data "github_ip_ranges" "test" {}
6059
`
6160

6261
resource.Test(t, resource.TestCase{
62+
PreCheck: func() { t.Setenv("GITHUB_TOKEN", ""); t.Setenv("GH_PATH", "none-existent-path") },
6363
ProviderFactories: providerFactories,
6464
Steps: []resource.TestStep{
6565
{
@@ -161,10 +161,15 @@ func TestAccProviderConfigure(t *testing.T) {
161161
provider "github" {
162162
token = "%s"
163163
base_url = "%s"
164-
}`, testAccConf.token, testAccConf.owner)
164+
}`, testAccConf.token, testAccConf.baseURL)
165165

166166
resource.Test(t, resource.TestCase{
167-
PreCheck: func() { skipUnlessMode(t, individual) },
167+
PreCheck: func() {
168+
skipUnlessMode(t, enterprise)
169+
if testAccConf.baseURL.Host != "api.github.com" {
170+
t.Skip("Skipping as test mode is not GHES")
171+
}
172+
},
168173
ProviderFactories: providerFactories,
169174
Steps: []resource.TestStep{
170175
{
@@ -187,7 +192,6 @@ func TestAccProviderConfigure(t *testing.T) {
187192
`, testAccConf.owner, testMaxRetries)
188193

189194
resource.Test(t, resource.TestCase{
190-
PreCheck: func() { skipUnauthenticated(t) },
191195
ProviderFactories: providerFactories,
192196
Steps: []resource.TestStep{
193197
{
@@ -211,7 +215,6 @@ func TestAccProviderConfigure(t *testing.T) {
211215
`, testAccConf.owner, testMaxPerPage)
212216

213217
resource.Test(t, resource.TestCase{
214-
PreCheck: func() { skipUnauthenticated(t) },
215218
ProviderFactories: providerFactories,
216219
Steps: []resource.TestStep{
217220
{
@@ -243,12 +246,11 @@ func TestAccProviderConfigure(t *testing.T) {
243246
`, testAccConf.owner, testAccConf.token)
244247

245248
resource.Test(t, resource.TestCase{
246-
PreCheck: func() { skipUnauthenticated(t) },
247249
ProviderFactories: providerFactories,
248250
Steps: []resource.TestStep{
249251
{
250252
Config: config,
251-
ExpectError: regexp.MustCompile("only one of `app_auth,token` can be specified"),
253+
ExpectError: regexp.MustCompile(`"app_auth": conflicts with token`),
252254
},
253255
},
254256
})
@@ -268,12 +270,12 @@ func TestAccProviderConfigure(t *testing.T) {
268270
`, testAccConf.owner)
269271

270272
resource.Test(t, resource.TestCase{
271-
PreCheck: func() { skipUnauthenticated(t); t.Setenv("GITHUB_TOKEN", "1234567890") },
273+
PreCheck: func() { t.Setenv("GITHUB_TOKEN", "1234567890") },
272274
ProviderFactories: providerFactories,
273275
Steps: []resource.TestStep{
274276
{
275277
Config: config,
276-
ExpectError: regexp.MustCompile("only one of `app_auth,token` can be specified"),
278+
ExpectError: regexp.MustCompile(`"token": conflicts with app_auth`),
277279
},
278280
},
279281
})

0 commit comments

Comments
 (0)