// CreateUserIfNotExists creates a user if it doesn't already exist and it gives it the specified permissions
CreateUserIfNotExists creates a user if it doesn't already exist and it gives it the specified permissions
// CreateUserIfNotExists creates a user if it doesn ' t already exist and it gives it the specified permissions
func CreateUserIfNotExists(ctx context.Context, sql SQLRunner,
	user, pass string, allowedHosts []string, permissions []mysqlv1alpha1.MysqlPermission,
	resourceOptions corev1.ResourceList,
) error {
	if len(allowedHosts) == 0 {
		return errors.New("no allowedHosts specified")
	}
	queries := []Query{
		getCreateUserQuery(user, pass, allowedHosts),
		getAlterUserQuery(user, pass, allowedHosts, resourceOptions),
	}
	if len(permissions) > 0 {
		queries = append(queries, permissionsToQuery(permissions, user, allowedHosts))
	}
	query := BuildAtomicQuery(queries...)
	if err := sql.QueryExec(ctx, query); err != nil {
		return fmt.Errorf("failed to configure user (user/pass/access), err: %s", err)
	}
	return nil
}
func CreateUserIfNotExists ( ctx context . Context , sql SQLRunner , user , pass string , allowedHosts [ ] string , permissions [ ] mysqlv1alpha1 . MysqlPermission , resourceOptions corev1 . ResourceList , ) error { if len ( allowedHosts ) == 0 { return errors . New ( " " ) } queries := [ ] Query { getCreateUserQuery ( user , pass , allowedHosts ) , getAlterUserQuery ( user , pass , allowedHosts , resourceOptions ) , } if len ( permissions ) > 0 { queries = append ( queries , permissionsToQuery ( permissions , user , allowedHosts ) ) } query := BuildAtomicQuery ( queries ... ) if err := sql . QueryExec ( ctx , query ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
CreateUserIfNotExists creates a user if it doesn't already exist and it gives it the specified permissions
CreateUserIfNotExists creates a user if it doesn ' t already exist and it gives it the specified permissions
// throw error if there are no allowed hosts