@@ -80,96 +80,6 @@ func (p *quayProvider) Configure(ctx context.Context, req provider.ConfigureRequ
8080 return
8181 }
8282
83- url := os .Getenv ("QUAY_URL" )
84- token := os .Getenv ("QUAY_TOKEN" )
85- oauth2Username := os .Getenv ("QUAY_OAUTH2_USERNAME" )
86- oauth2Password := os .Getenv ("QUAY_OAUTH2_PASSWORD" )
87- oauth2ClientID := os .Getenv ("QUAY_OAUTH2_CLIENT_ID" )
88- oauth2TokenURL := os .Getenv ("QUAY_OAUTH2_TOKEN_URL" )
89-
90- if ! config .Url .IsNull () {
91- url = config .Url .ValueString ()
92- }
93-
94- if ! config .Token .IsNull () {
95- token = config .Token .ValueString ()
96- }
97-
98- if ! config .OAuth2Username .IsNull () {
99- oauth2Username = config .OAuth2Username .ValueString ()
100- }
101-
102- if ! config .OAuth2Password .IsNull () {
103- oauth2Password = config .OAuth2Password .ValueString ()
104- }
105-
106- if ! config .OAuth2ClientID .IsNull () {
107- oauth2ClientID = config .OAuth2ClientID .ValueString ()
108- }
109-
110- if ! config .OAuth2TokenURL .IsNull () {
111- oauth2TokenURL = config .OAuth2TokenURL .ValueString ()
112- }
113-
114- ctx = tflog .SetField (ctx , "url" , url )
115- ctx = tflog .SetField (ctx , "token" , token )
116- ctx = tflog .SetField (ctx , "oauth2_username" , oauth2Username )
117- ctx = tflog .SetField (ctx , "oauth2_password" , oauth2Password )
118- ctx = tflog .SetField (ctx , "oauth2_client_id" , oauth2ClientID )
119- ctx = tflog .SetField (ctx , "oauth2_token_url" , oauth2TokenURL )
120- ctx = tflog .MaskFieldValuesWithFieldKeys (ctx , "token" )
121- ctx = tflog .MaskFieldValuesWithFieldKeys (ctx , "oauth2_password" )
122-
123- tflog .Debug (ctx , "Creating Quay client" )
124-
125- configuration := & quay_api.Configuration {
126- DefaultHeader : make (map [string ]string ),
127- UserAgent : "OpenAPI-Generator/1.0.0/go" ,
128- Debug : false ,
129- Servers : quay_api.ServerConfigurations {
130- {
131- URL : url ,
132- Description : "No description provided" ,
133- },
134- },
135- OperationServers : map [string ]quay_api.ServerConfigurations {},
136- }
137-
138- if token == "" {
139- oauth2Config := & oauth2.Config {
140- ClientID : oauth2ClientID ,
141- Endpoint : oauth2.Endpoint {
142- TokenURL : oauth2TokenURL ,
143- },
144- }
145-
146- oauth2Token , err := oauth2Config .PasswordCredentialsToken (ctx , oauth2Username , oauth2Password )
147- if err != nil {
148- resp .Diagnostics .AddError ("Error retrieving OAuth2 access token" ,
149- "Error retrieving OAuth2 access token: " + err .Error ())
150- return
151- }
152-
153- token = oauth2Token .AccessToken
154- }
155-
156- configuration .AddDefaultHeader ("Authorization" , "Bearer " + token )
157- client := quay_api .NewAPIClient (configuration )
158-
159- resp .DataSourceData = client
160- resp .ResourceData = client
161-
162- tflog .Info (ctx , "Configured Quay client" , map [string ]any {"success" : true })
163- }
164-
165- func (p * quayProvider ) ValidateConfig (ctx context.Context , req provider.ValidateConfigRequest , resp * provider.ValidateConfigResponse ) {
166- var config quayProviderModel
167- diags := req .Config .Get (ctx , & config )
168- resp .Diagnostics .Append (diags ... )
169- if resp .Diagnostics .HasError () {
170- return
171- }
172-
17383 if config .Url .IsUnknown () || config .Token .IsUnknown () || config .OAuth2Username .IsUnknown () || config .OAuth2Password .IsUnknown () ||
17484 config .OAuth2ClientID .IsUnknown () || config .OAuth2TokenURL .IsUnknown () {
17585 resp .Diagnostics .AddError (
@@ -284,6 +194,56 @@ func (p *quayProvider) ValidateConfig(ctx context.Context, req provider.Validate
284194 )
285195 return
286196 }
197+
198+ ctx = tflog .SetField (ctx , "url" , url )
199+ ctx = tflog .SetField (ctx , "token" , token )
200+ ctx = tflog .SetField (ctx , "oauth2_username" , oauth2Username )
201+ ctx = tflog .SetField (ctx , "oauth2_password" , oauth2Password )
202+ ctx = tflog .SetField (ctx , "oauth2_client_id" , oauth2ClientID )
203+ ctx = tflog .SetField (ctx , "oauth2_token_url" , oauth2TokenURL )
204+ ctx = tflog .MaskFieldValuesWithFieldKeys (ctx , "token" )
205+ ctx = tflog .MaskFieldValuesWithFieldKeys (ctx , "oauth2_password" )
206+
207+ tflog .Debug (ctx , "Creating Quay client" )
208+
209+ configuration := & quay_api.Configuration {
210+ DefaultHeader : make (map [string ]string ),
211+ UserAgent : "OpenAPI-Generator/1.0.0/go" ,
212+ Debug : false ,
213+ Servers : quay_api.ServerConfigurations {
214+ {
215+ URL : url ,
216+ Description : "No description provided" ,
217+ },
218+ },
219+ OperationServers : map [string ]quay_api.ServerConfigurations {},
220+ }
221+
222+ if token == "" {
223+ oauth2Config := & oauth2.Config {
224+ ClientID : oauth2ClientID ,
225+ Endpoint : oauth2.Endpoint {
226+ TokenURL : oauth2TokenURL ,
227+ },
228+ }
229+
230+ oauth2Token , err := oauth2Config .PasswordCredentialsToken (ctx , oauth2Username , oauth2Password )
231+ if err != nil {
232+ resp .Diagnostics .AddError ("Error retrieving OAuth2 access token" ,
233+ "Error retrieving OAuth2 access token: " + err .Error ())
234+ return
235+ }
236+
237+ token = oauth2Token .AccessToken
238+ }
239+
240+ configuration .AddDefaultHeader ("Authorization" , "Bearer " + token )
241+ client := quay_api .NewAPIClient (configuration )
242+
243+ resp .DataSourceData = client
244+ resp .ResourceData = client
245+
246+ tflog .Info (ctx , "Configured Quay client" , map [string ]any {"success" : true })
287247}
288248
289249func (p * quayProvider ) Metadata (_ context.Context , _ provider.MetadataRequest , resp * provider.MetadataResponse ) {
0 commit comments