From eef1c0c213842533e3869355421f4da8aa717ae0 Mon Sep 17 00:00:00 2001 From: Jan Sebastian Siwy Date: Wed, 18 Mar 2020 13:19:47 +0100 Subject: [PATCH] Add support to retrieve information about the currently authenticated user Copy https://github.com/terraform-providers/terraform-provider-github/pull/261 as the original repository behind this PR has been deleted --- github/data_source_github_user.go | 4 ++-- ...urce_github_repository_vulnerability_alerts.go | 12 ++++++------ ...github_repository_vulnerability_alerts_test.go | 8 ++++---- website/docs/d/user.html.markdown | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/github/data_source_github_user.go b/github/data_source_github_user.go index 04e661326d..461fd64546 100644 --- a/github/data_source_github_user.go +++ b/github/data_source_github_user.go @@ -111,11 +111,11 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { return err } - gpg, _, err := client.Users.ListGPGKeys(ctx, username, nil) + gpg, _, err := client.Users.ListGPGKeys(ctx, user.GetLogin(), nil) if err != nil { return err } - ssh, _, err := client.Users.ListKeys(ctx, username, nil) + ssh, _, err := client.Users.ListKeys(ctx, user.GetLogin(), nil) if err != nil { return err } diff --git a/github/resource_github_repository_vulnerability_alerts.go b/github/resource_github_repository_vulnerability_alerts.go index 019afa3d93..780ffb15c1 100644 --- a/github/resource_github_repository_vulnerability_alerts.go +++ b/github/resource_github_repository_vulnerability_alerts.go @@ -30,9 +30,9 @@ func resourceGithubRepositoryVulnerabilityAlertsCreate(d *schema.ResourceData, m return err } - client := meta.(*Organization).client + client := meta.(*Owner).v3client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) log.Printf("[DEBUG] Creating repository vulnerability alerts: %s/%s", orgName, repoName) @@ -53,13 +53,13 @@ func resourceGithubRepositoryVulnerabilityAlertsRead(d *schema.ResourceData, met return err } - client := meta.(*Organization).client + client := meta.(*Owner).v3client repoName := d.Id() if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name log.Printf("[DEBUG] Reading repository vulnerability alerts: %s/%s", orgName, repoName) ctx := context.WithValue(context.Background(), ctxId, d.Id()) @@ -80,13 +80,13 @@ func resourceGithubRepositoryVulnerabilityAlertsDelete(d *schema.ResourceData, m return err } - client := meta.(*Organization).client + client := meta.(*Owner).v3client repoName := d.Id() if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Deleting repository vulnerability alerts%s/%s", orgName, repoName) _, err = client.Repositories.DisableVulnerabilityAlerts(ctx, orgName, repoName) diff --git a/github/resource_github_repository_vulnerability_alerts_test.go b/github/resource_github_repository_vulnerability_alerts_test.go index ba7d05a3e1..3a72799bbf 100644 --- a/github/resource_github_repository_vulnerability_alerts_test.go +++ b/github/resource_github_repository_vulnerability_alerts_test.go @@ -42,8 +42,8 @@ func testAccCheckGithubRepositoryVulnerabilityAlertsExists(n, id string) resourc return fmt.Errorf("Expected ID to be %v, got %v", id, rs.Primary.ID) } - conn := testAccProvider.Meta().(*Organization).client - o := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).v3client + o := testAccProvider.Meta().(*Owner).name enabled, _, err := conn.Repositories.GetVulnerabilityAlerts(context.TODO(), o, id) if err != nil { @@ -59,14 +59,14 @@ func testAccCheckGithubRepositoryVulnerabilityAlertsExists(n, id string) resourc } func testAccGithubRepositoryVulnerabilityAlertsDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).v3client for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_vulnerability_alerts" { continue } - o := testAccProvider.Meta().(*Organization).name + o := testAccProvider.Meta().(*Owner).name enabled, _, err := conn.Repositories.GetVulnerabilityAlerts(context.TODO(), o, rs.Primary.ID) if err == nil { diff --git a/website/docs/d/user.html.markdown b/website/docs/d/user.html.markdown index b3c051b0ae..467765f945 100644 --- a/website/docs/d/user.html.markdown +++ b/website/docs/d/user.html.markdown @@ -1,6 +1,7 @@ --- layout: "github" page_title: "GitHub: github_user" +sidebar_current: "docs-github-datasource-user" description: |- Get information on a GitHub user. --- @@ -12,14 +13,25 @@ Use this data source to retrieve information about a GitHub user. ## Example Usage ```hcl +# Retrieve information about a GitHub user. data "github_user" "example" { username = "example" } + +# Retrieve information about the currently authenticated user. +data "github_user" "current" { + username = "" +} + +output "current_github_login" { + value = "${data.github_user.current.login}" +} + ``` ## Argument Reference - * `username` - (Required) The username. + * `username` - (Required) The username. Use an empty string `""` to retrieve information about the currently authenticated user. ## Attributes Reference @@ -41,4 +53,3 @@ data "github_user" "example" { * `following` - the number of following users. * `created_at` - the creation date. * `updated_at` - the update date. -