-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Organization-level public key data sources (#1608)
Add the following new data sources: * github_actions_organization_public_key * github_dependabot_organization_public_key Co-authored-by: Keegan Campbell <me@kfcampbell.com>
- Loading branch information
1 parent
d9a763e
commit 0546397
Showing
8 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
github/data_source_github_actions_organization_public_key.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGithubActionsOrganizationPublicKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubActionsOrganizationPublicKeyRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"key_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubActionsOrganizationPublicKeyRead(d *schema.ResourceData, meta interface{}) error { | ||
err := checkOrganization(meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := meta.(*Owner).v3client | ||
owner := meta.(*Owner).name | ||
|
||
ctx := context.Background() | ||
|
||
publicKey, _, err := client.Actions.GetOrgPublicKey(ctx, owner) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(publicKey.GetKeyID()) | ||
d.Set("key_id", publicKey.GetKeyID()) | ||
d.Set("key", publicKey.GetKey()) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
github/data_source_github_actions_organization_public_key_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package github | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubActionsOrganizationPublicKeyDataSource(t *testing.T) { | ||
|
||
t.Run("queries an organization public key without error", func(t *testing.T) { | ||
|
||
config := ` | ||
data "github_actions_organization_public_key" "test" {} | ||
` | ||
|
||
check := resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet( | ||
"data.github_actions_organization_public_key.test", "key", | ||
), | ||
) | ||
|
||
testCase := func(t *testing.T, mode string) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { skipUnlessMode(t, mode) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: check, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
t.Run("with an anonymous account", func(t *testing.T) { | ||
t.Skip("anonymous account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an individual account", func(t *testing.T) { | ||
t.Skip("individual account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an organization account", func(t *testing.T) { | ||
testCase(t, organization) | ||
}) | ||
|
||
}) | ||
} |
47 changes: 47 additions & 0 deletions
47
github/data_source_github_dependabot_organization_public_key.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGithubDependabotOrganizationPublicKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubDependabotOrganizationPublicKeyRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"key_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubDependabotOrganizationPublicKeyRead(d *schema.ResourceData, meta interface{}) error { | ||
err := checkOrganization(meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := meta.(*Owner).v3client | ||
owner := meta.(*Owner).name | ||
|
||
ctx := context.Background() | ||
|
||
publicKey, _, err := client.Dependabot.GetOrgPublicKey(ctx, owner) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(publicKey.GetKeyID()) | ||
d.Set("key_id", publicKey.GetKeyID()) | ||
d.Set("key", publicKey.GetKey()) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
github/data_source_github_dependabot_organization_public_key_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package github | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubDependabotOrganizationPublicKeyDataSource(t *testing.T) { | ||
|
||
t.Run("queries an organization public key without error", func(t *testing.T) { | ||
|
||
config := ` | ||
data "github_dependabot_organization_public_key" "test" {} | ||
` | ||
|
||
check := resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet( | ||
"data.github_dependabot_organization_public_key.test", "key", | ||
), | ||
) | ||
|
||
testCase := func(t *testing.T, mode string) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { skipUnlessMode(t, mode) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: check, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
t.Run("with an anonymous account", func(t *testing.T) { | ||
t.Skip("anonymous account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an individual account", func(t *testing.T) { | ||
t.Skip("individual account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an organization account", func(t *testing.T) { | ||
testCase(t, organization) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
website/docs/d/actions_organization_public_key.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
layout: "github" | ||
page_title: "GitHub: github_actions_organization_public_key" | ||
description: |- | ||
Get information on a GitHub Actions Organization Public Key. | ||
--- | ||
|
||
# github_actions_organization_public_key | ||
|
||
Use this data source to retrieve information about a GitHub Actions Organization public key. This data source is required to be used with other GitHub secrets interactions. | ||
Note that the provider `token` must have admin rights to an organization to retrieve it's action public key. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "github_actions_organization_public_key" "example" {} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
* `key_id` - ID of the key that has been retrieved. | ||
* `key` - Actual key retrieved. |
22 changes: 22 additions & 0 deletions
22
website/docs/d/dependabot_organization_public_key.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
layout: "github" | ||
page_title: "GitHub: github_dependabot_organization_public_key" | ||
description: |- | ||
Get information on a GitHub Dependabot Organization Public Key. | ||
--- | ||
|
||
# github_dependabot_organization_public_key | ||
|
||
Use this data source to retrieve information about a GitHub Dependabot Organization public key. This data source is required to be used with other GitHub secrets interactions. | ||
Note that the provider `token` must have admin rights to an organization to retrieve it's Dependabot public key. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "github_dependabot_organization_public_key" "example" {} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
* `key_id` - ID of the key that has been retrieved. | ||
* `key` - Actual key retrieved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters