Skip to content

Commit

Permalink
feat: Switch to Rate Limited GH Client
Browse files Browse the repository at this point in the history
* Leveraged existing patterns/code used for the normal terraform-provider-github package which was first implimented in [this PR](integrations/terraform-provider-github#145)
  • Loading branch information
alex-bourla-form3 committed Sep 1, 2023
1 parent d04e894 commit 9da79fd
Show file tree
Hide file tree
Showing 3 changed files with 981 additions and 119 deletions.
23 changes: 12 additions & 11 deletions githubfile/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
package githubfile

import (
"context"
"encoding/base64"
"fmt"
"strings"

"github.com/google/go-github/v54/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"golang.org/x/oauth2"
tpg "github.com/integrations/terraform-provider-github/v5/github"
"strings"
)

const (
Expand Down Expand Up @@ -50,20 +48,23 @@ type providerConfiguration struct {
func Provider() *schema.Provider {
return &schema.Provider{
ConfigureFunc: func(d *schema.ResourceData) (interface{}, error) {
ts := oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: d.Get(githubTokenKey).(string),
},
)
tc := oauth2.NewClient(context.Background(), ts)
c := tpg.Config{
Token: d.Get(githubTokenKey).(string),
}

gc, err := c.NewRESTClient(c.AuthenticatedHTTPClient())
if err != nil {
return nil, fmt.Errorf("failed to create GitHub Client: %v", err)
}

// Support reading a base64-encoded GPG secret key.
sk := d.Get(gpgSecretKeyKey).(string)
if v, err := base64.StdEncoding.DecodeString(sk); err == nil {
sk = string(v)
}
return &providerConfiguration{
commitMessagePrefix: d.Get(commitMessagePrefixKey).(string),
githubClient: github.NewClient(tc),
githubClient: gc,
githubEmail: d.Get(githubEmailKey).(string),
githubUsername: d.Get(githubUsernameKey).(string),
gpgSecretKey: sk,
Expand Down
101 changes: 61 additions & 40 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,97 @@ go 1.18
require (
github.com/form3tech-oss/go-github-utils v0.0.0-20220202160928-550ce279ed0c
github.com/google/go-github/v54 v54.0.0
github.com/hashicorp/terraform-plugin-sdk v1.7.0
golang.org/x/oauth2 v0.11.0
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/integrations/terraform-provider-github/v5 v5.34.0
)

require (
cloud.google.com/go v0.45.1 // indirect
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.29.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-cidr v1.0.1 // indirect
github.com/apparentlymart/go-textseg v1.0.0 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.25.3 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-github/v42 v42.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-getter v1.4.0 // indirect
github.com/hashicorp/go-hclog v0.9.2 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/hashicorp/go-plugin v1.0.1 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.3.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f // indirect
github.com/hashicorp/hcl/v2 v2.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 // indirect
github.com/hashicorp/terraform-json v0.4.0 // indirect
github.com/hashicorp/terraform-plugin-test v1.2.0 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 // indirect
github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect
github.com/hashicorp/terraform-exec v0.13.3 // indirect
github.com/hashicorp/terraform-json v0.10.0 // indirect
github.com/hashicorp/terraform-plugin-test/v2 v2.2.1 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.5 // indirect
github.com/mitchellh/cli v1.0.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/cli v1.1.2 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/posener/complete v1.2.1 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/ulikunitz/xz v0.5.5 // indirect
github.com/vmihailenco/msgpack v4.0.1+incompatible // indirect
github.com/zclconf/go-cty v1.2.1 // indirect
github.com/zclconf/go-cty-yaml v1.0.1 // indirect
go.opencensus.io v0.22.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb // indirect
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
github.com/spf13/afero v1.4.1 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.8.2 // indirect
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/api v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.23.0 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)

// TODO: Remove this, this is a temporary measure, pointing to branch which has required updates
Expand Down
Loading

0 comments on commit 9da79fd

Please sign in to comment.