Skip to content

Commit

Permalink
fix sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Sep 16, 2024
1 parent 40e9aa0 commit 150ea76
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/framework/Framework.Linq/NullableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static class NullableExtensions
public static bool IsNullOrEmpty<T>(this IEnumerable<T>? collection) =>
collection == null || !collection.Any();

public static IEnumerable<KeyValuePair<TKey, TValue>> FilterNotNullValues<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue?>> source) =>
source.Where(x => x.Value != null).Cast<KeyValuePair<TKey, TValue>>();
public static IEnumerable<KeyValuePair<TKey, TValue>> FilterNotNullValues<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue?>> source) where TValue : notnull =>
source.Where(x => x.Value is not null).Cast<KeyValuePair<TKey, TValue>>();

public static IEnumerable<T> FilterNotNull<T>(this IEnumerable<T?> source) =>
source.Where(x => x != null).Cast<T>();
public static IEnumerable<T> FilterNotNull<T>(this IEnumerable<T?> source) where T : notnull =>
source.Where(x => x is not null).Cast<T>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ await _keycloak.CreateAuthenticationExecutionConfigurationAsync(
new AuthenticatorConfig
{
Alias = update.AuthenticatorConfig,
Config = _seedData.GetAuthenticatorConfig(update.AuthenticatorConfig).Config?.FilterNotNullValues()?.ToDictionary()
Config = _seedData.GetAuthenticatorConfig(update.AuthenticatorConfig).Config?.FilterNotNullValues().ToDictionary()
},
cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
break;
Expand All @@ -292,7 +292,7 @@ await _keycloak.DeleteAuthenticatorConfigurationAsync(
if (config == null)
throw new UnexpectedConditionException("authenticatorConfig is null");
config.Alias = update.AuthenticatorConfig;
config.Config = updateConfig.Config?.FilterNotNullValues()?.ToDictionary();
config.Config = updateConfig.Config?.FilterNotNullValues().ToDictionary();
await _keycloak.UpdateAuthenticatorConfigurationAsync(_realm, execution.AuthenticationConfig, config, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/keycloak/Keycloak.Seeding/BusinessLogic/ClientsUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ private static async Task UpdateDefaultClientScopes(KeycloakClient keycloak, str
PublicClient = update.PublicClient,
FrontChannelLogout = update.FrontchannelLogout,
Protocol = update.Protocol,
Attributes = update.Attributes?.FilterNotNullValues()?.ToDictionary(),
AuthenticationFlowBindingOverrides = update.AuthenticationFlowBindingOverrides?.FilterNotNullValues()?.ToDictionary(),
Attributes = update.Attributes?.FilterNotNullValues().ToDictionary(),
AuthenticationFlowBindingOverrides = update.AuthenticationFlowBindingOverrides?.FilterNotNullValues().ToDictionary(),
FullScopeAllowed = update.FullScopeAllowed,
NodeReregistrationTimeout = update.NodeReRegistrationTimeout,
Access = update.Access == null
Expand Down Expand Up @@ -299,8 +299,8 @@ private static PartialImport CreatePartialImportClient(ClientModel update) =>
PublicClient = update.PublicClient,
FrontChannelLogout = update.FrontchannelLogout,
Protocol = update.Protocol,
Attributes = update.Attributes?.FilterNotNullValues()?.ToDictionary(),
AuthenticationFlowBindingOverrides = update.AuthenticationFlowBindingOverrides?.FilterNotNullValues()?.ToDictionary(),
Attributes = update.Attributes?.FilterNotNullValues().ToDictionary(),
AuthenticationFlowBindingOverrides = update.AuthenticationFlowBindingOverrides?.FilterNotNullValues().ToDictionary(),
FullScopeAllowed = update.FullScopeAllowed,
NodeReregistrationTimeout = update.NodeReRegistrationTimeout,
ProtocolMappers = update.ProtocolMappers?.Select(x => ProtocolMappersUpdater.CreateProtocolMapper(x.Id, x)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static bool CompareIdentityProviderConfig(Config? config, IdentityProvid
private static IdentityProviderMapper UpdateIdentityProviderMapper(IdentityProviderMapper mapper, IdentityProviderMapperModel updateMapper)
{
mapper._IdentityProviderMapper = updateMapper.IdentityProviderMapper;
mapper.Config = updateMapper.Config?.FilterNotNullValues()?.ToDictionary();
mapper.Config = updateMapper.Config?.FilterNotNullValues().ToDictionary();
return mapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async Task UpdateRealm(string keycloakInstanceName, CancellationToken can
keycloakRealm.ResetCredentialsFlow = seedRealm.ResetCredentialsFlow;
keycloakRealm.ClientAuthenticationFlow = seedRealm.ClientAuthenticationFlow;
keycloakRealm.DockerAuthenticationFlow = seedRealm.DockerAuthenticationFlow;
keycloakRealm.Attributes = seedRealm.Attributes?.FilterNotNullValues()?.ToDictionary();
keycloakRealm.Attributes = seedRealm.Attributes?.FilterNotNullValues().ToDictionary();
keycloakRealm.UserManagedAccessAllowed = seedRealm.UserManagedAccessAllowed;
keycloakRealm.PasswordPolicy = seedRealm.PasswordPolicy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static Role CreateRole(RoleModel update) =>
Description = update.Description,
Composite = update.Composite,
ClientRole = update.ClientRole,
Attributes = update.Attributes?.FilterNotNullValues()?.ToDictionary()
Attributes = update.Attributes?.FilterNotNullValues().ToDictionary()
};

private static Role CreateUpdateRole(string id, string containerId, RoleModel update)
Expand Down
8 changes: 4 additions & 4 deletions src/keycloak/Keycloak.Seeding/BusinessLogic/UsersUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ await seed.Except(userRoles.Select(x => x.Name)).IfAnyAwait(
DisableableCredentialTypes = update.DisableableCredentialTypes,
RequiredActions = update.RequiredActions,
NotBefore = update.NotBefore,
Attributes = update.Attributes?.FilterNotNullValues()?.ToDictionary(),
Attributes = update.Attributes?.FilterNotNullValues().ToDictionary(),
Groups = update.Groups,
ServiceAccountClientId = update.ServiceAccountClientId,
Access = CreateUpdateUserAccess(update.Access),
Expand Down Expand Up @@ -282,7 +282,7 @@ private static Credentials CreateUpdateCredentials(CredentialsModel update) =>
new()
{
Algorithm = update.Algorithm,
Config = update.Config?.FilterNotNullValues()?.ToDictionary(),
Config = update.Config?.FilterNotNullValues().ToDictionary(),
Counter = update.Counter,
CreatedDate = update.CreatedDate,
Device = update.Device,
Expand Down Expand Up @@ -324,8 +324,8 @@ private static PartialImport CreatePartialImportUser(UserModel update) =>
RequiredActions = update.RequiredActions,
NotBefore = update.NotBefore,
Access = CreateUpdateUserAccess(update.Access),
Attributes = update.Attributes?.FilterNotNullValues()?.ToDictionary(),
ClientRoles = update.ClientRoles?.FilterNotNullValues()?.ToDictionary(),
Attributes = update.Attributes?.FilterNotNullValues().ToDictionary(),
ClientRoles = update.ClientRoles?.FilterNotNullValues().ToDictionary(),
Credentials = update.Credentials?.Select(CreateUpdateCredentials),
FederatedIdentities = update.FederatedIdentities?.Select(CreateUpdateFederatedIdentity),
FederationLink = update.FederationLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static KeycloakRealm ToModel(this KeycloakRealmSettings keycloakRealmSett
WebAuthnPolicyPasswordlessAcceptableAaguids = keycloakRealmSettings.WebAuthnPolicyPasswordlessAcceptableAaguids,
Users = keycloakRealmSettings.Users?.Select(ToModel),
ScopeMappings = keycloakRealmSettings.ScopeMappings?.Select(ToModel),
ClientScopeMappings = keycloakRealmSettings.ClientScopeMappings?.Select(ToModel)?.ToImmutableDictionary(),
ClientScopeMappings = keycloakRealmSettings.ClientScopeMappings?.Select(ToModel).ToImmutableDictionary(),
Clients = keycloakRealmSettings.Clients?.Select(ToModel),
ClientScopes = keycloakRealmSettings.ClientScopes?.Select(ToModel),
DefaultDefaultClientScopes = keycloakRealmSettings.DefaultDefaultClientScopes,
Expand All @@ -126,7 +126,7 @@ public static KeycloakRealm ToModel(this KeycloakRealmSettings keycloakRealmSett
AdminEventsDetailsEnabled = keycloakRealmSettings.AdminEventsDetailsEnabled,
IdentityProviders = keycloakRealmSettings.IdentityProviders?.Select(ToModel),
IdentityProviderMappers = keycloakRealmSettings.IdentityProviderMappers?.Select(ToModel),
Components = keycloakRealmSettings.Components?.Select(ToModel)?.ToImmutableDictionary(),
Components = keycloakRealmSettings.Components?.Select(ToModel).ToImmutableDictionary(),
InternationalizationEnabled = keycloakRealmSettings.InternationalizationEnabled,
SupportedLocales = keycloakRealmSettings.SupportedLocales,
DefaultLocale = keycloakRealmSettings.DefaultLocale,
Expand All @@ -139,7 +139,7 @@ public static KeycloakRealm ToModel(this KeycloakRealmSettings keycloakRealmSett
ResetCredentialsFlow = keycloakRealmSettings.ResetCredentialsFlow,
ClientAuthenticationFlow = keycloakRealmSettings.ClientAuthenticationFlow,
DockerAuthenticationFlow = keycloakRealmSettings.DockerAuthenticationFlow,
Attributes = keycloakRealmSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
Attributes = keycloakRealmSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
KeycloakVersion = keycloakRealmSettings.KeycloakVersion,
UserManagedAccessAllowed = keycloakRealmSettings.UserManagedAccessAllowed,
ClientProfiles = keycloakRealmSettings.ClientProfiles?.ToModel(),
Expand Down Expand Up @@ -177,12 +177,12 @@ private static RoleModel ToModel(this RoleSettings roleSettings) =>
roleSettings.Composite,
roleSettings.ClientRole,
roleSettings.ContainerId,
roleSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
roleSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
roleSettings.Composites?.ToModel());

private static RolesModel ToModel(this RolesSettings rolesSettings) =>
new(rolesSettings.Realm?.Select(x => x.ToModel()),
rolesSettings.Client?.Select(ToModel)?.ToImmutableDictionary());
rolesSettings.Client?.Select(ToModel).ToImmutableDictionary());

private static KeyValuePair<string, IEnumerable<string>?> ToModel(UserClientRolesSettings userClientRolesSettings) =>
KeyValuePair.Create(
Expand All @@ -193,9 +193,9 @@ private static GroupModel ToModel(GroupSettings groupSettings) =>
new(groupSettings.Id,
groupSettings.Name,
groupSettings.Path,
groupSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
groupSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
groupSettings.RealmRoles,
groupSettings.ClientRoles?.Select(ToModel)?.ToImmutableDictionary(),
groupSettings.ClientRoles?.Select(ToModel).ToImmutableDictionary(),
groupSettings.SubGroups);

public static KeyValuePair<string, string?> ToModel(CredentialsConfigSettings credentialsConfigSettings) =>
Expand All @@ -205,7 +205,7 @@ private static GroupModel ToModel(GroupSettings groupSettings) =>

private static CredentialsModel ToModel(CredentialsSettings credentialsSettings) =>
new(credentialsSettings.Algorithm,
credentialsSettings.Config?.Select(ToModel)?.ToImmutableDictionary(),
credentialsSettings.Config?.Select(ToModel).ToImmutableDictionary(),
credentialsSettings.Counter,
credentialsSettings.CreatedDate,
credentialsSettings.Device,
Expand Down Expand Up @@ -246,13 +246,13 @@ private static UserModel ToModel(UserSettings userSettings) =>
userSettings.FirstName,
userSettings.LastName,
userSettings.Email,
userSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
userSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
userSettings.Credentials?.Select(ToModel),
userSettings.DisableableCredentialTypes,
userSettings.RequiredActions,
userSettings.FederatedIdentities?.Select(ToModel),
userSettings.RealmRoles,
userSettings.ClientRoles?.Select(ToModel)?.ToImmutableDictionary(),
userSettings.ClientRoles?.Select(ToModel).ToImmutableDictionary(),
userSettings.NotBefore,
userSettings.Groups,
userSettings.ServiceAccountClientId,
Expand Down Expand Up @@ -295,7 +295,7 @@ private static ProtocolMapperModel ToModel(ProtocolMapperSettings protocolMapper
protocolMapperSettings.Protocol,
protocolMapperSettings.ProtocolMapper,
protocolMapperSettings.ConsentRequired,
protocolMapperSettings.Config?.Select(ToModel)?.ToImmutableDictionary());
protocolMapperSettings.Config?.Select(ToModel).ToImmutableDictionary());

private static ClientAccessModel ToModel(this ClientAccessSettings clientAccessSettings) =>
new(clientAccessSettings.Configure,
Expand Down Expand Up @@ -324,8 +324,8 @@ private static ClientModel ToModel(ClientSettings clientSettings) =>
clientSettings.PublicClient,
clientSettings.FrontchannelLogout,
clientSettings.Protocol,
clientSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
clientSettings.AuthenticationFlowBindingOverrides?.Select(ToModel)?.ToImmutableDictionary(),
clientSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
clientSettings.AuthenticationFlowBindingOverrides?.Select(ToModel).ToImmutableDictionary(),
clientSettings.FullScopeAllowed,
clientSettings.NodeReRegistrationTimeout,
clientSettings.DefaultClientScopes,
Expand All @@ -341,7 +341,7 @@ private static ClientScopeModel ToModel(this ClientScopeSettings clientScopeSett
new(clientScopeSettings.Id,
clientScopeSettings.Name,
clientScopeSettings.Protocol,
clientScopeSettings.Attributes?.Select(ToModel)?.ToImmutableDictionary(),
clientScopeSettings.Attributes?.Select(ToModel).ToImmutableDictionary(),
clientScopeSettings.ProtocolMappers?.Select(ToModel),
clientScopeSettings.Description);

Expand Down Expand Up @@ -431,7 +431,7 @@ private static IdentityProviderMapperModel ToModel(IdentityProviderMapperSetting
identityProviderMapperSettings.Name,
identityProviderMapperSettings.IdentityProviderAlias,
identityProviderMapperSettings.IdentityProviderMapper,
identityProviderMapperSettings.Config?.Select(ToModel)?.ToImmutableDictionary());
identityProviderMapperSettings.Config?.Select(ToModel).ToImmutableDictionary());

private static KeyValuePair<string, IEnumerable<string>?> ToModel(ComponentConfigSettings componentConfigSettings) =>
KeyValuePair.Create(
Expand All @@ -444,7 +444,7 @@ private static ComponentModel ToModel(ComponentSettings componentSettings) =>
componentSettings.ProviderId,
componentSettings.SubType,
componentSettings.SubComponents,
componentSettings.Config?.Select(ToModel)?.ToImmutableDictionary());
componentSettings.Config?.Select(ToModel).ToImmutableDictionary());

private static KeyValuePair<string, IEnumerable<ComponentModel>?> ToModel(ComponentSettingsEntry componentSettingsEntry) =>
KeyValuePair.Create(
Expand Down Expand Up @@ -478,7 +478,7 @@ private static AuthenticationFlowModel ToModel(AuthenticationFlowSettings authen
private static AuthenticatorConfigModel ToModel(AuthenticatorConfigSettings authenticatorConfigSettings) =>
new(authenticatorConfigSettings.Id,
authenticatorConfigSettings.Alias,
authenticatorConfigSettings.Config?.Select(ToModel)?.ToImmutableDictionary());
authenticatorConfigSettings.Config?.Select(ToModel).ToImmutableDictionary());

private static RequiredActionModel ToModel(this RequiredActionSettings requiredActionSettings) =>
new(requiredActionSettings.Alias,
Expand Down

0 comments on commit 150ea76

Please sign in to comment.