@@ -16,17 +16,23 @@ import (
1616)
1717
1818type Config struct {
19- Token string
20- Owner string
21- BaseURL * url.URL
22- IsGHES bool
23- Insecure bool
24- WriteDelay time.Duration
25- ReadDelay time.Duration
26- RetryDelay time.Duration
27- RetryableErrors map [int ]bool
28- MaxRetries int
29- ParallelRequests bool
19+ LegacyClient bool
20+ BaseURL * url.URL
21+ RESTAPIPath string
22+ GraphQLAPIPath string
23+ Owner string
24+ AppID * string
25+ AppPEM []byte
26+ AppInstallationID * string
27+ Token string
28+ ReadDelay time.Duration
29+ WriteDelay time.Duration
30+ RetryDelay time.Duration
31+ RetryableErrors map [int ]bool
32+ MaxRetries int
33+ ParallelRequests bool
34+ Insecure bool
35+ CachePath * string
3036}
3137
3238type Owner struct {
@@ -47,6 +53,8 @@ const (
4753 DotComAPIHost = "api.github.com"
4854 // GHESRESTAPISuffix is the rest api suffix for GitHub Enterprise Server.
4955 GHESRESTAPIPath = "api/v3/"
56+ // GHESGraphQLAPISuffix is the GraphQL api suffix for GitHub Enterprise Server.
57+ GHESGraphQLAPIPath = "api/graphql"
5058)
5159
5260var (
@@ -83,7 +91,7 @@ func (c *Config) AuthenticatedHTTPClient() *http.Client {
8391}
8492
8593func (c * Config ) Anonymous () bool {
86- return c .Token == ""
94+ return c .AppID == nil && c . Token == ""
8795}
8896
8997func (c * Config ) AnonymousHTTPClient () * http.Client {
@@ -92,30 +100,19 @@ func (c *Config) AnonymousHTTPClient() *http.Client {
92100}
93101
94102func (c * Config ) NewGraphQLClient (client * http.Client ) (* githubv4.Client , error ) {
95- var path string
96- if c .IsGHES {
97- path = "api/graphql"
98- } else {
99- path = "graphql"
100- }
101-
102- return githubv4 .NewEnterpriseClient (c .BaseURL .JoinPath (path ).String (), client ), nil
103+ return githubv4 .NewEnterpriseClient (c .BaseURL .JoinPath (c .GraphQLAPIPath ).String (), client ), nil
103104}
104105
105106func (c * Config ) NewRESTClient (client * http.Client ) (* github.Client , error ) {
106- path := ""
107- if c .IsGHES {
108- path = GHESRESTAPIPath
109- }
110-
111- v3client , err := github .NewClient (github .WithHTTPClient (client ), github .WithURLs (new (c.BaseURL .JoinPath (path ).String ()), nil ))
107+ v3client , err := github .NewClient (github .WithHTTPClient (client ), github .WithURLs (new (c.BaseURL .JoinPath (c .RESTAPIPath ).String ()), nil ))
112108 if err != nil {
113109 return nil , err
114110 }
115111
116112 return v3client , nil
117113}
118114
115+ // Deprecated: This is no longer required as [configureProviderMeta] is now used to configure the provider meta parameter with the necessary clients and owner information. Use [configureProviderMeta] instead.
119116func (c * Config ) ConfigureOwner (owner * Owner ) (* Owner , error ) {
120117 ctx := context .Background ()
121118 owner .name = c .Owner
@@ -144,34 +141,9 @@ func (c *Config) ConfigureOwner(owner *Owner) (*Owner, error) {
144141
145142// Meta returns the meta parameter that is passed into subsequent resources
146143// https://godoc.org/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ConfigureFunc
144+ // Deprecated: Use [configureProviderMeta] instead.
147145func (c * Config ) Meta () (any , error ) {
148- var client * http.Client
149- if c .Anonymous () {
150- client = c .AnonymousHTTPClient ()
151- } else {
152- client = c .AuthenticatedHTTPClient ()
153- }
154-
155- v3client , err := c .NewRESTClient (client )
156- if err != nil {
157- return nil , err
158- }
159-
160- v4client , err := c .NewGraphQLClient (client )
161- if err != nil {
162- return nil , err
163- }
164-
165- var owner Owner
166- owner .v4client = v4client
167- owner .v3client = v3client
168- owner .StopContext = context .Background ()
169-
170- _ , err = c .ConfigureOwner (& owner )
171- if err != nil {
172- return & owner , err
173- }
174- return & owner , nil
146+ return configureProviderMeta (context .Background (), c )
175147}
176148
177149type previewHeaderInjectorTransport struct {
0 commit comments