@@ -245,15 +245,15 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
245245 ro := resourceOptionsToClauses (cr .Spec .ForProvider .ResourceOptions )
246246 binlog := cr .Spec .ForProvider .BinLog
247247
248- var authplugin string
248+ var authplugin string
249+
249250 if cr .Spec .ForProvider .AuthPlugin != "" {
250251 authplugin = cr .Spec .ForProvider .AuthPlugin
251- } else {
252- authplugin = "mysql_native_password"
253252 }
254253 var pw string
255254
256- if authplugin == "mysql_native_password" {
255+ switch authplugin {
256+ case "" :
257257 var err error
258258 pw , _ , err = c .getPassword (ctx , cr )
259259 if err != nil {
@@ -266,11 +266,11 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
266266 return managed.ExternalCreation {}, err
267267 }
268268 }
269- auth = fmt .Sprintf ("%s BY %s" , authplugin , mysql .QuoteValue (pw ))
270- } else if authplugin == "AWSAuthenticationPlugin" {
271- auth = fmt .Sprintf ("%s AS %s" , authplugin , mysql .QuoteValue ("RDS" ))
272- } else {
273- return managed.ExternalCreation {}, errors .New (errAuthPluginNotSupported )
269+ auth = fmt .Sprintf ("BY %s" , mysql .QuoteValue (pw ))
270+ case "AWSAuthenticationPlugin" :
271+ auth = fmt .Sprintf ("WITH %s AS %s" , authplugin , mysql .QuoteValue ("RDS" ))
272+ default :
273+ return managed.ExternalCreation {}, errors .New (errAuthPluginNotSupported )
274274 }
275275
276276 if err := c .executeCreateUserQuery (ctx , username , host , ro , auth , binlog ); err != nil {
@@ -293,13 +293,12 @@ func (c *external) executeCreateUserQuery(ctx context.Context, username string,
293293 }
294294
295295 query := fmt .Sprintf (
296- "CREATE USER %s@%s IDENTIFIED WITH %s%s" ,
296+ "CREATE USER %s@%s IDENTIFIED %s%s" ,
297297 mysql .QuoteValue (username ),
298298 mysql .QuoteValue (host ),
299299 auth ,
300300 resourceOptions ,
301301 )
302- fmt .Println (query )
303302
304303 if err := mysql .ExecWithBinlogAndFlush (ctx , c .db , mysql.ExecQuery {Query : query , ErrorValue : errCreateUser }, mysql.ExecOptions {Binlog : binlog }); err != nil {
305304 return err
0 commit comments