Skip to content

Commit c729b44

Browse files
chore(fixtures): DSPX-4607 drop stale nolint directives and reuse keycloakBoolTrue
golangci-lint v2.13.2 reports 26 findings in lib/fixtures: - 25 //nolint:sloglint directives that no longer suppress anything. sloglint stopped flagging the emoji log messages they were added for, so nolintlint now reports each as unused. - 6 raw "true" map values that duplicate the existing keycloakBoolTrue constant. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
1 parent 3052b2a commit c729b44

1 file changed

Lines changed: 7 additions & 32 deletions

File tree

lib/fixtures/keycloak.go

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
165165
if _, err := client.CreateRealm(ctx, token.AccessToken, realm); err != nil {
166166
return err
167167
}
168-
//nolint:sloglint // allow existing emojis
169168
slog.Info("✅ realm created", slog.String("realm", kcConnectParams.Realm))
170169

171170
// update realm users profile via upconfig
@@ -184,10 +183,8 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
184183
if err != nil {
185184
return err
186185
}
187-
//nolint:sloglint // allow existing emojis
188186
slog.Info("✅ realm users profile updated", slog.String("realm", kcConnectParams.Realm))
189187
} else {
190-
//nolint:sloglint // allow existing emojis
191188
slog.Info("⏭️ realm already exists", slog.String("realm", kcConnectParams.Realm))
192189
}
193190

@@ -211,13 +208,11 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
211208
if err != nil {
212209
switch kcErrCode(err) {
213210
case http.StatusConflict:
214-
//nolint:sloglint // allow existing emojis
215211
slog.Warn("⏭️ role already exists", slog.String("role", role))
216212
default:
217213
return err
218214
}
219215
} else {
220-
//nolint:sloglint // allow existing emojis
221216
slog.Info("✅ role created", slog.String("role", role))
222217
}
223218
}
@@ -233,7 +228,6 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
233228
return err
234229
}
235230

236-
//nolint:sloglint // allow existing emojis
237231
slog.Info("✅ roles found", slog.Int("count", len(realmRoles)))
238232
for _, role := range realmRoles {
239233
switch *role.Name {
@@ -277,7 +271,7 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
277271
Name: gocloak.StringP("testscope"),
278272
Description: gocloak.StringP("a scope for testing"),
279273
Protocol: gocloak.StringP("openid-connect"),
280-
ClientScopeAttributes: &gocloak.ClientScopeAttributes{IncludeInTokenScope: gocloak.StringP("true")},
274+
ClientScopeAttributes: &gocloak.ClientScopeAttributes{IncludeInTokenScope: gocloak.StringP(keycloakBoolTrue)},
281275
}
282276

283277
testScopeID, err = client.CreateClientScope(ctx, token.AccessToken, kcConnectParams.Realm, *testScope)
@@ -402,8 +396,8 @@ func defaultProtocolMappers(audience string, includeCustomDPoPMapper bool) []goc
402396
Config: &map[string]string{
403397
"included.client.audience": audience,
404398
"included.custom.audience": "custom_audience",
405-
"access.token.claim": "true",
406-
"id.token.claim": "true",
399+
"access.token.claim": keycloakBoolTrue,
400+
"id.token.claim": keycloakBoolTrue,
407401
},
408402
},
409403
}
@@ -414,9 +408,9 @@ func defaultProtocolMappers(audience string, includeCustomDPoPMapper bool) []goc
414408
ProtocolMapper: gocloak.StringP("virtru-oidc-protocolmapper"),
415409
Config: &map[string]string{
416410
"claim.name": "tdf_claims",
417-
"client.dpop": "true",
418-
"tdf_claims.enabled": "true",
419-
"access.token.claim": "true",
411+
"client.dpop": keycloakBoolTrue,
412+
"tdf_claims.enabled": keycloakBoolTrue,
413+
"access.token.claim": keycloakBoolTrue,
420414
"client.publickey": "X-VirtruPubKey",
421415
},
422416
})
@@ -713,10 +707,8 @@ func createRealmWithTokenManager(ctx context.Context, kcConnectParams KeycloakCo
713707
if _, err := client.CreateRealm(ctx, token.AccessToken, realm); err != nil {
714708
return err
715709
}
716-
//nolint:sloglint // allow existing emojis
717710
slog.Info("✅ realm created", slog.String("realm", *realm.Realm))
718711
} else {
719-
//nolint:sloglint // allow existing emojis
720712
slog.Info("⏭️ realm already exists", slog.String("realm", *realm.Realm))
721713
}
722714

@@ -737,7 +729,6 @@ func createRealmWithTokenManager(ctx context.Context, kcConnectParams KeycloakCo
737729
if err != nil {
738730
return err
739731
}
740-
//nolint:sloglint // allow existing emojis
741732
slog.Info("✅ realm users profile updated", slog.String("realm", *realm.Realm))
742733

743734
return nil
@@ -759,13 +750,11 @@ func createGroup(ctx context.Context, tm *TokenManager, realmName string, group
759750
if err != nil {
760751
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
761752
if kcErr.Code == http.StatusConflict {
762-
//nolint:sloglint // allow existing emojis
763753
slog.Warn("⏭️ group already exists", slog.String("group", *group.Name))
764754
} else {
765755
return err
766756
}
767757
} else {
768-
//nolint:sloglint // allow existing emojis
769758
slog.Info("✅ group created", slog.String("group", *group.Name))
770759
}
771760
return nil
@@ -787,13 +776,11 @@ func createRealmRole(ctx context.Context, tm *TokenManager, realmName string, ro
787776
if err != nil {
788777
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
789778
if kcErr.Code == http.StatusConflict {
790-
//nolint:sloglint // allow existing emojis
791779
slog.Warn("⏭️ role already exists", slog.String("role", *role.Name))
792780
} else {
793781
return err
794782
}
795783
} else {
796-
//nolint:sloglint // allow existing emojis
797784
slog.Info("✅ role created", slog.String("role", *role.Name))
798785
}
799786
return nil
@@ -824,15 +811,13 @@ func createClientRole(ctx context.Context, tm *TokenManager, realmName string, c
824811
if err != nil {
825812
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
826813
if kcErr.Code == http.StatusConflict {
827-
//nolint:sloglint // allow existing emojis
828814
slog.Warn("⏭️ role already exists for client",
829815
slog.String("role", *role.Name),
830816
slog.String("client_id", clientID))
831817
} else {
832818
return err
833819
}
834820
} else {
835-
//nolint:sloglint // allow existing emojis
836821
slog.Info("✅ client role created",
837822
slog.String("client_id", clientID),
838823
slog.String("role", *role.Name))
@@ -855,7 +840,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
855840
if err != nil {
856841
switch kcErrCode(err) {
857842
case http.StatusConflict:
858-
//nolint:sloglint // allow existing emojis
859843
slog.Warn("⏭️ client already exists", slog.String("client_id", clientID))
860844
clients, err := client.GetClients(ctx, token.AccessToken, connectParams.Realm, gocloak.GetClientsParams{ClientID: newClient.ClientID})
861845
if err != nil {
@@ -874,7 +858,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
874858
return "", err
875859
}
876860
} else {
877-
//nolint:sloglint // allow existing emojis
878861
slog.Info("✅ client created",
879862
slog.String("client_id", clientID),
880863
slog.String("client_identifier", longClientID))
@@ -895,7 +878,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
895878
slog.String("username", *user.Username))
896879

897880
if realmRoles != nil {
898-
//nolint:sloglint // allow existing emojis
899881
slog.Info("⏭️ adding realm roles to client via service account",
900882
slog.String("client_id", longClientID),
901883
slog.String("username", *user.Username))
@@ -906,14 +888,12 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
906888
return "", err
907889
}
908890
for _, role := range realmRoles {
909-
//nolint:sloglint // allow existing emojis
910891
slog.Info("✅ realm role added to client",
911892
slog.String("role", *role.Name),
912893
slog.String("client_id", longClientID))
913894
}
914895
}
915896
if clientRoles != nil {
916-
//nolint:sloglint // allow existing emojis
917897
slog.Info("⏭️ adding client roles to client via service account",
918898
slog.String("client_id", longClientID),
919899
slog.String("username", *user.Username))
@@ -925,7 +905,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
925905
return "", err
926906
}
927907
for _, role := range roles {
928-
//nolint:sloglint // allow existing emojis
929908
slog.Info("✅ client role added to client",
930909
slog.String("role", *role.Name),
931910
slog.String("client_id", longClientID))
@@ -971,7 +950,6 @@ func createUser(ctx context.Context, tm *TokenManager, connectParams *KeycloakCo
971950
return nil, fmt.Errorf("error, multiple users found with username %s", username)
972951
}
973952
} else {
974-
//nolint:sloglint // allow existing emojis
975953
slog.Info("✅ user created",
976954
slog.String("username", username),
977955
slog.String("user_identifier", longUserID))
@@ -1016,7 +994,6 @@ func createUser(ctx context.Context, tm *TokenManager, connectParams *KeycloakCo
1016994
return nil, err
1017995
}
1018996
for _, role := range clientRoles {
1019-
//nolint:sloglint // allow existing emojis
1020997
slog.Info("✅ client role added to user",
1021998
slog.String("role", *role.Name),
1022999
slog.String("user_id", longUserID))
@@ -1195,7 +1172,7 @@ func withClientAudienceMapper(client gocloak.Client, audience string) gocloak.Cl
11951172
ProtocolMapper: gocloak.StringP(oidcAudienceMapper),
11961173
Config: &map[string]string{
11971174
"included.client.audience": audience,
1198-
"access.token.claim": "true",
1175+
"access.token.claim": keycloakBoolTrue,
11991176
},
12001177
})
12011178
client.ProtocolMappers = &mappers
@@ -1235,7 +1212,6 @@ func createCertExchange(ctx context.Context, connectParams *KeycloakConnectParam
12351212
}); err != nil {
12361213
switch kcErrCode(err) {
12371214
case http.StatusConflict:
1238-
//nolint:sloglint // allow existing emojis
12391215
slog.Warn("⏭️ authentication flow already exists; skipping remainder of cert exchange creation", slog.String("flow_name", topLevelFlowName))
12401216
return nil
12411217
default:
@@ -1340,7 +1316,6 @@ func createCertExchange(ctx context.Context, connectParams *KeycloakConnectParam
13401316
return err
13411317
}
13421318

1343-
//nolint:sloglint // allow existing emojis
13441319
slog.Info("✅ created Cert Exchange Authentication",
13451320
slog.String("flow_id", *flowID),
13461321
)

0 commit comments

Comments
 (0)