Chore: Add types for OAuth settings in config (#45247)

This commit is contained in:
kay delaney 2022-02-11 13:54:24 +00:00 committed by GitHub
parent aa6cee1072
commit 10cc2fd6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 10 deletions

View File

@ -65,6 +65,26 @@ export type PreloadPlugin = {
version: string;
};
/** Supported OAuth services
*
* @public
*/
export type OAuth =
| 'github'
| 'gitlab'
| 'google'
| 'generic_oauth'
// | 'grafananet' Deprecated. Key always changed to "grafana_com"
| 'grafana_com'
| 'azuread'
| 'okta';
/** Map of enabled OAuth services and their respective names
*
* @public
*/
export type OAuthSettings = Partial<Record<OAuth, { name: string }>>;
/**
* Describes all the different Grafana configuration values available for an instance.
*
@ -96,7 +116,7 @@ export interface GrafanaConfig {
samlEnabled: boolean;
autoAssignOrg: boolean;
verifyEmailEnabled: boolean;
oauth: any;
oauth: OAuthSettings;
disableUserSignUp: boolean;
loginHint: any;
passwordHint: any;

View File

@ -36,7 +36,7 @@ export * from './live';
export * from './variables';
export * from './geometry';
export { isUnsignedPluginSignature } from './pluginSignature';
export { GrafanaConfig, BuildInfo, LicenseInfo, PreloadPlugin } from './config';
export { OAuth, OAuthSettings, GrafanaConfig, BuildInfo, LicenseInfo, PreloadPlugin } from './config';
export { FeatureToggles } from './featureToggles.gen';
export * from './alerts';
export * from './slider';

View File

@ -9,6 +9,7 @@ import {
GrafanaTheme2,
LicenseInfo,
MapLayerOptions,
OAuthSettings,
PanelPluginMeta,
PreloadPlugin,
systemDateFormats,
@ -48,7 +49,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
samlName = '';
autoAssignOrg = true;
verifyEmailEnabled = false;
oauth: any;
oauth: OAuthSettings = {};
disableUserSignUp = false;
loginHint: any;
passwordHint: any;

View File

@ -29,44 +29,44 @@ const loginServices: () => LoginServices = () => {
},
google: {
bgColor: '#e84d3c',
enabled: oauthEnabled && config.oauth.google,
enabled: oauthEnabled && Boolean(config.oauth.google),
name: 'Google',
icon: 'google',
},
azuread: {
bgColor: '#2f2f2f',
enabled: oauthEnabled && config.oauth.azuread,
enabled: oauthEnabled && Boolean(config.oauth.azuread),
name: 'Microsoft',
icon: 'microsoft',
},
github: {
bgColor: '#464646',
enabled: oauthEnabled && config.oauth.github,
enabled: oauthEnabled && Boolean(config.oauth.github),
name: 'GitHub',
icon: 'github',
},
gitlab: {
bgColor: '#fc6d26',
enabled: oauthEnabled && config.oauth.gitlab,
enabled: oauthEnabled && Boolean(config.oauth.gitlab),
name: 'GitLab',
icon: 'gitlab',
},
grafanacom: {
bgColor: '#262628',
enabled: oauthEnabled && config.oauth.grafana_com,
enabled: oauthEnabled && Boolean(config.oauth.grafana_com),
name: 'Grafana.com',
hrefName: 'grafana_com',
icon: 'grafana',
},
okta: {
bgColor: '#2f2f2f',
enabled: oauthEnabled && config.oauth.okta,
enabled: oauthEnabled && Boolean(config.oauth.okta),
name: 'Okta',
icon: 'okta',
},
oauth: {
bgColor: '#262628',
enabled: oauthEnabled && config.oauth.generic_oauth,
enabled: oauthEnabled && Boolean(config.oauth.generic_oauth),
name: oauthEnabled && config.oauth.generic_oauth ? config.oauth.generic_oauth.name : 'OAuth',
icon: 'signin',
hrefName: 'generic_oauth',