Skip to content

Commit

Permalink
fix github provider (GoogleCloudPlatform#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylanzman authored May 5, 2021
1 parent 0b4bf69 commit ddf071d
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ require (
github.com/digitalocean/godo v1.57.0
github.com/dollarshaveclub/new-relic-synthetics-go v0.0.0-20170605224734-4dc3dd6ae884
github.com/fastly/go-fastly v1.18.0
github.com/google/go-github/v25 v25.1.3
github.com/google/go-github/v35 v35.1.0
github.com/gophercloud/gophercloud v0.17.0
github.com/grafana/grafana-api-golang-client v0.0.0-20210218192924-9ccd2365d2a6
github.com/hashicorp/go-azure-helpers v0.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v25 v25.1.3 h1:Ht4YIQgUh4l4lc80fvGnw60khXysXvlgPxPP8uJG3EA=
github.com/google/go-github/v25 v25.1.3/go.mod h1:6z5pC69qHtrPJ0sXPsj4BLnd82b+r6sLB7qcBoRZqpw=
github.com/google/go-github/v35 v35.1.0 h1:KkwZnKWQ/0YryvXjZlCN/3EGRJNp6VCZPKo+RG9mG28=
github.com/google/go-github/v35 v35.1.0/go.mod h1:s0515YVTI+IMrDoy9Y4pHt9ShGpzHvHO8rZ7L7acgvs=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
Expand Down
2 changes: 2 additions & 0 deletions providers/github/github_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (p *GithubProvider) Init(args []string) error {
if len(args) > 2 {
if args[2] != "" {
p.baseURL = args[2]
} else {
p.baseURL = githubDefaultURL
}
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions providers/github/github_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v25/github"
"github.com/google/go-github/v35/github"
githubAPI "github.com/google/go-github/v35/github"
"golang.org/x/oauth2"
)

const githubDefaultURL = "https://api.github.com/"

type GithubService struct { //nolint
terraformutils.Service
}

func (g *GithubService) createClient() (*github.Client, error) {
if g.GetArgs()["base_url"].(string) == "" {
if g.GetArgs()["base_url"].(string) == githubDefaultURL {
return g.createRegularClient(), nil
}
return g.createEnterpriseClient()
Expand All @@ -49,6 +51,6 @@ func (g *GithubService) createEnterpriseClient() (*github.Client, error) {
&oauth2.Token{AccessToken: g.Args["token"].(string)},
)
tc := oauth2.NewClient(ctx, ts)
baseURL := g.GetArgs()["base_url"].(string) + "/api/v3/"
baseURL := g.GetArgs()["base_url"].(string)
return githubAPI.NewEnterpriseClient(baseURL, baseURL, tc)
}
2 changes: 1 addition & 1 deletion providers/github/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

// MembersGenerator holds GithubService struct of Terraform service information
Expand Down
2 changes: 1 addition & 1 deletion providers/github/organizationWebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type OrganizationWebhooksGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion providers/github/organization_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type OrganizationBlockGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion providers/github/organization_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type OrganizationProjectGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion providers/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strconv"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type RepositoriesGenerator struct {
Expand Down
6 changes: 3 additions & 3 deletions providers/github/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type TeamsGenerator struct {
Expand All @@ -48,7 +48,7 @@ func (g *TeamsGenerator) createTeamsResources(ctx context.Context, teams []*gith

func (g *TeamsGenerator) createTeamMembersResources(ctx context.Context, team *githubAPI.Team, client *githubAPI.Client) []terraformutils.Resource {
resources := []terraformutils.Resource{}
members, _, err := client.Teams.ListTeamMembers(ctx, team.GetID(), nil)
members, _, err := client.Teams.ListTeamMembersBySlug(ctx, g.Args["owner"].(string), team.GetSlug(), nil)
if err != nil {
log.Println(err)
}
Expand All @@ -66,7 +66,7 @@ func (g *TeamsGenerator) createTeamMembersResources(ctx context.Context, team *g

func (g *TeamsGenerator) createTeamRepositoriesResources(ctx context.Context, team *githubAPI.Team, client *githubAPI.Client) []terraformutils.Resource {
resources := []terraformutils.Resource{}
repos, _, err := client.Teams.ListTeamRepos(ctx, team.GetID(), nil)
repos, _, err := client.Teams.ListTeamReposBySlug(ctx, g.Args["owner"].(string), team.GetSlug(), nil)
if err != nil {
log.Println(err)
}
Expand Down
2 changes: 1 addition & 1 deletion providers/github/user_ssh_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

githubAPI "github.com/google/go-github/v25/github"
githubAPI "github.com/google/go-github/v35/github"
)

type UserSSHKeyGenerator struct {
Expand Down
1 change: 1 addition & 0 deletions terraformutils/providerwrapper/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (p *ProviderWrapper) Refresh(info *terraform.InstanceInfo, state *terraform
Private: []byte{},
})
if resp.Diagnostics.HasErrors() {
log.Println(resp.Diagnostics.Err())
log.Printf("WARN: Fail read resource from provider, wait %dms before retry\n", p.retrySleepMs)
time.Sleep(time.Duration(p.retrySleepMs) * time.Millisecond)
continue
Expand Down

0 comments on commit ddf071d

Please sign in to comment.