@@ -286,6 +286,18 @@ func (r *GlanceAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
286286 return err
287287 }
288288
289+ // index authAppCredSecretField
290+ if err := mgr .GetFieldIndexer ().IndexField (context .Background (), & glancev1.GlanceAPI {}, authAppCredSecretField , func (rawObj client.Object ) []string {
291+ // Extract the application credential secret name from the spec, if one is provided
292+ cr := rawObj .(* glancev1.GlanceAPI )
293+ if cr .Spec .Auth .ApplicationCredentialSecret == "" {
294+ return nil
295+ }
296+ return []string {cr .Spec .Auth .ApplicationCredentialSecret }
297+ }); err != nil {
298+ return err
299+ }
300+
289301 // Watch for changes to any CustomServiceConfigSecrets. Global secrets
290302 svcSecretFn := func (_ context.Context , o client.Object ) []reconcile.Request {
291303 var namespace = o .GetNamespace ()
@@ -1285,6 +1297,30 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12851297 "Wsgi" : wsgi ,
12861298 }
12871299
1300+ templateParameters ["UseApplicationCredentials" ] = false
1301+ // Try to get Application Credential from the secret specified in the CR
1302+ if instance .Spec .Auth .ApplicationCredentialSecret != "" {
1303+ acSecretObj , _ , err := secret .GetSecret (ctx , h , instance .Spec .Auth .ApplicationCredentialSecret , instance .Namespace )
1304+ if err != nil {
1305+ if k8s_errors .IsNotFound (err ) {
1306+ Log .Info ("ApplicationCredential secret not found, waiting" , "secret" , instance .Spec .Auth .ApplicationCredentialSecret )
1307+ return fmt .Errorf ("%w: %s" , ErrACSecretNotFound , instance .Spec .Auth .ApplicationCredentialSecret )
1308+ }
1309+ Log .Error (err , "Failed to get ApplicationCredential secret" , "secret" , instance .Spec .Auth .ApplicationCredentialSecret )
1310+ return err
1311+ }
1312+ acID , okID := acSecretObj .Data [keystonev1 .ACIDSecretKey ]
1313+ acSecretData , okSecret := acSecretObj .Data [keystonev1 .ACSecretSecretKey ]
1314+ if ! okID || len (acID ) == 0 || ! okSecret || len (acSecretData ) == 0 {
1315+ Log .Info ("ApplicationCredential secret missing required keys" , "secret" , instance .Spec .Auth .ApplicationCredentialSecret )
1316+ return fmt .Errorf ("%w: %s" , ErrACSecretMissingKeys , instance .Spec .Auth .ApplicationCredentialSecret )
1317+ }
1318+ templateParameters ["UseApplicationCredentials" ] = true
1319+ templateParameters ["ACID" ] = string (acID )
1320+ templateParameters ["ACSecret" ] = string (acSecretData )
1321+ Log .Info ("Using ApplicationCredentials auth" , "secret" , instance .Spec .Auth .ApplicationCredentialSecret )
1322+ }
1323+
12881324 // (OSPRH-18291)Only set EndpointID parameter when the Endpoint has been
12891325 // created and the associated ID is set in the keystoneapi CR. Because we
12901326 // have the Keystone CR, we get the Region parameter mirrored in its
0 commit comments