Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
#10: Exclude built-in users from retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
laingsimon committed Oct 28, 2021
1 parent dbe90a5 commit 2832e78
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions vcdb.MySql/SchemaBuilding/MySqlUserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ namespace vcdb.MySql.SchemaBuilding
{
public class MySqlUserRepository : IUserRepository
{
private static readonly string[] ExcludedMySqlUserNames = new[]
{
"root@localhost",
"mysql.session@localhost",
"mysql.sys@localhost",
"root@%",
};

private readonly Options options;

public MySqlUserRepository(Options options)
Expand All @@ -26,9 +34,15 @@ public async Task<Dictionary<string, UserDetails>> GetUsers(DbConnection connect
$@"select * from mysql.user",
new { databaseName = options.Database });

return users.ToDictionary(
GetUserName,
CreateUserDetails);
return users
.Where(UserNotExcluded)
.ToDictionary(GetUserName, CreateUserDetails);
}

private static bool UserNotExcluded(MySqlUserDetails user)
{
var currentUserName = GetUserName(user);
return !ExcludedMySqlUserNames.Contains(currentUserName);
}

private static string GetUserName(MySqlUserDetails user)
Expand Down

0 comments on commit 2832e78

Please sign in to comment.