The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/auth-config/index.ts

49 lines
1.6 KiB

import { AuthProviderStatus, Settings, SettingsSection } from 'app/types';
import { AuthProviderInfo, GetStatusHook } from './types';
export * from './types';
const registeredAuthProviders: AuthProviderInfo[] = [];
const authProvidersConfigHooks: Record<string, GetStatusHook> = {};
export function registerAuthProvider(provider: AuthProviderInfo, getConfigHook?: GetStatusHook) {
if (!registeredAuthProviders.find((p) => p.id === provider.id)) {
registeredAuthProviders.push(provider);
if (getConfigHook) {
authProvidersConfigHooks[provider.id] = getConfigHook;
}
}
}
export function getRegisteredAuthProviders(): AuthProviderInfo[] {
return registeredAuthProviders;
}
export function getAuthProviderInfo(provider: string) {
return registeredAuthProviders.find((p) => p.id === provider);
}
export function getAuthProviders(cfg: Settings): SettingsSection[] {
const providers: SettingsSection[] = [];
for (const [section, sectionConfig] of Object.entries(cfg)) {
const provider = registeredAuthProviders.find((provider) => `auth.${provider.id}` === section);
if (provider) {
const providerData = {
...sectionConfig,
providerId: provider.id,
displayName: sectionConfig.name || provider.displayName,
};
providers.push(providerData);
}
}
return providers;
}
export async function getAuthProviderStatus(providerId: string): Promise<AuthProviderStatus> {
if (authProvidersConfigHooks[providerId]) {
const getStatusHook = authProvidersConfigHooks[providerId];
return getStatusHook();
}
return { configured: false, enabled: false };
}