Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added GPG and SSH key to GitHub user data source #15212

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FEATURES:
IMPROVEMENTS:

* provider/rancher: Move to Rancher V2 API [GH-13908]
* provider/github: Added SSH and GPG key to user data source [GH-15211]



Expand Down
10 changes: 5 additions & 5 deletions builtin/providers/github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
return err
}

d.SetId(strconv.Itoa(*team.ID))
d.Set("name", *team.Name)
d.Set("description", *team.Description)
d.Set("privacy", *team.Privacy)
d.Set("permission", *team.Permission)
d.SetId(strconv.Itoa(team.GetID()))
d.Set("name", team.GetName())
d.Set("description", team.GetDescription())
d.Set("privacy", team.GetPrivacy())
d.Set("permission", team.GetPermission())

return nil
}
Expand Down
57 changes: 39 additions & 18 deletions builtin/providers/github/data_source_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func dataSourceGithubUser() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"gpg_key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"ssh_key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"bio": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -90,29 +98,42 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Refreshing Gitub User: %s", username)

client := meta.(*Organization).client
ctx := context.Background()

user, _, err := client.Users.Get(ctx, username)
if err != nil {
return err
}

gpg, _, err := client.Users.ListGPGKeys(ctx, username, nil)
if err != nil {
return err
}

user, _, err := client.Users.Get(context.TODO(), username)
ssh, _, err := client.Users.ListKeys(ctx, username, nil)
if err != nil {
return err
}

d.SetId(strconv.Itoa(*user.ID))
d.Set("login", *user.Login)
d.Set("avatar_url", *user.AvatarURL)
d.Set("gravatar_id", *user.GravatarID)
d.Set("site_admin", *user.SiteAdmin)
d.Set("company", *user.Company)
d.Set("blog", *user.Blog)
d.Set("location", *user.Location)
d.Set("name", *user.Name)
d.Set("email", *user.Email)
d.Set("bio", *user.Bio)
d.Set("public_repos", *user.PublicRepos)
d.Set("public_gists", *user.PublicGists)
d.Set("followers", *user.Followers)
d.Set("following", *user.Following)
d.Set("created_at", *user.CreatedAt)
d.Set("updated_at", *user.UpdatedAt)
d.SetId(strconv.Itoa(user.GetID()))
d.Set("login", user.GetLogin())
d.Set("avatar_url", user.GetAvatarURL())
d.Set("gravatar_id", user.GetGravatarID())
d.Set("site_admin", user.GetSiteAdmin())
d.Set("company", user.GetCompany())
d.Set("blog", user.GetBlog())
d.Set("location", user.GetLocation())
d.Set("name", user.GetName())
d.Set("email", user.GetEmail())
d.Set("gpg_key", gpg[0].GetPublicKey())
d.Set("ssh_key", ssh[0].GetKey())
d.Set("bio", user.GetBio())
d.Set("public_repos", user.GetPublicRepos())
d.Set("public_gists", user.GetPublicGists())
d.Set("followers", user.GetFollowers())
d.Set("following", user.GetFollowing())
d.Set("created_at", user.GetCreatedAt())
d.Set("updated_at", user.GetUpdatedAt())

return nil
}
12 changes: 8 additions & 4 deletions vendor/github.com/google/go-github/github/activity_events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 34 additions & 6 deletions vendor/github.com/google/go-github/github/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 70 additions & 13 deletions vendor/github.com/google/go-github/github/event_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading