Skip to content

Commit 0254dd0

Browse files
authored
refactor: speed up audience mapper validation (#961)
Do not load all clients when validating client audience for audience mappers. Instead, try to fetch the client in question directly. Signed-off-by: Simon Engmann <[email protected]>
1 parent 5fcefb5 commit 0254dd0

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

keycloak/openid_audience_protocol_mapper.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,10 @@ func (keycloakClient *KeycloakClient) ValidateOpenIdAudienceProtocolMapper(ctx c
124124
}
125125

126126
if mapper.IncludedClientAudience != "" {
127-
clients, err := keycloakClient.listGenericClients(ctx, mapper.RealmId)
127+
_, err = keycloakClient.GetGenericClientByClientId(ctx, mapper.RealmId, mapper.IncludedClientAudience)
128128
if err != nil {
129-
return err
129+
return fmt.Errorf("validation error: %w", err)
130130
}
131-
132-
for _, client := range clients {
133-
if client.ClientId == mapper.IncludedClientAudience {
134-
return nil
135-
}
136-
}
137-
138-
return fmt.Errorf("validation error: client %s does not exist", mapper.IncludedClientAudience)
139131
}
140132

141133
return nil

provider/resource_keycloak_openid_audience_protocol_mapper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestAccKeycloakOpenIdAudienceProtocolMapper_validateClientAudienceExists(t
233233
Steps: []resource.TestStep{
234234
{
235235
Config: testKeycloakOpenIdAudienceProtocolMapper_validateClientAudienceExists(clientId, mapperName),
236-
ExpectError: regexp.MustCompile("validation error: client .+ does not exist"),
236+
ExpectError: regexp.MustCompile("validation error: generic client with name \\S+ does not exist"),
237237
},
238238
},
239239
})

0 commit comments

Comments
 (0)