@@ -54,6 +54,7 @@ const (
54
54
errUpdateUser = "cannot update user"
55
55
errGetPasswordSecretFailed = "cannot get password secret"
56
56
errCompareResourceOptions = "cannot compare desired and observed resource options"
57
+ errAuthPluginNotSupported = "auth plugin not supported"
57
58
58
59
maxConcurrency = 5
59
60
)
@@ -238,20 +239,39 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
238
239
cr .SetConditions (xpv1 .Creating ())
239
240
240
241
username , host := mysql .SplitUserHost (meta .GetExternalName (cr ))
241
- pw , _ , err := c .getPassword (ctx , cr )
242
- if err != nil {
243
- return managed.ExternalCreation {}, err
242
+
243
+ var auth string
244
+
245
+ var authplugin string
246
+
247
+ if cr .Spec .ForProvider .AuthPlugin != "" {
248
+ authplugin = cr .Spec .ForProvider .AuthPlugin
244
249
}
250
+ var pw string
245
251
246
- if pw == "" {
247
- pw , err = password .Generate ()
252
+ switch authplugin {
253
+ case "" :
254
+ var err error
255
+ pw , _ , err = c .getPassword (ctx , cr )
248
256
if err != nil {
249
257
return managed.ExternalCreation {}, err
250
258
}
259
+
260
+ if pw == "" {
261
+ pw , err = password .Generate ()
262
+ if err != nil {
263
+ return managed.ExternalCreation {}, err
264
+ }
265
+ }
266
+ auth = fmt .Sprintf ("BY %s" , mysql .QuoteValue (pw ))
267
+ case "AWSAuthenticationPlugin" :
268
+ auth = fmt .Sprintf ("WITH %s AS %s" , authplugin , mysql .QuoteValue ("RDS" ))
269
+ default :
270
+ return managed.ExternalCreation {}, errors .New (errAuthPluginNotSupported )
251
271
}
252
272
253
273
ro := resourceOptionsToClauses (cr .Spec .ForProvider .ResourceOptions )
254
- if err := c .executeCreateUserQuery (ctx , username , host , ro , pw ); err != nil {
274
+ if err := c .executeCreateUserQuery (ctx , username , host , ro , auth ); err != nil {
255
275
return managed.ExternalCreation {}, err
256
276
}
257
277
@@ -264,17 +284,17 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
264
284
}, nil
265
285
}
266
286
267
- func (c * external ) executeCreateUserQuery (ctx context.Context , username string , host string , resourceOptionsClauses []string , pw string ) error {
287
+ func (c * external ) executeCreateUserQuery (ctx context.Context , username string , host string , resourceOptionsClauses []string , auth string ) error {
268
288
resourceOptions := ""
269
289
if len (resourceOptionsClauses ) != 0 {
270
290
resourceOptions = fmt .Sprintf (" WITH %s" , strings .Join (resourceOptionsClauses , " " ))
271
291
}
272
292
273
293
query := fmt .Sprintf (
274
- "CREATE USER %s@%s IDENTIFIED BY %s%s" ,
294
+ "CREATE USER %s@%s IDENTIFIED %s%s" ,
275
295
mysql .QuoteValue (username ),
276
296
mysql .QuoteValue (host ),
277
- mysql . QuoteValue ( pw ) ,
297
+ auth ,
278
298
resourceOptions ,
279
299
)
280
300
0 commit comments