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; 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. * Describes all the different Grafana configuration values available for an instance.
* *
@ -96,7 +116,7 @@ export interface GrafanaConfig {
samlEnabled: boolean; samlEnabled: boolean;
autoAssignOrg: boolean; autoAssignOrg: boolean;
verifyEmailEnabled: boolean; verifyEmailEnabled: boolean;
oauth: any; oauth: OAuthSettings;
disableUserSignUp: boolean; disableUserSignUp: boolean;
loginHint: any; loginHint: any;
passwordHint: any; passwordHint: any;

View File

@ -36,7 +36,7 @@ export * from './live';
export * from './variables'; export * from './variables';
export * from './geometry'; export * from './geometry';
export { isUnsignedPluginSignature } from './pluginSignature'; 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 { FeatureToggles } from './featureToggles.gen';
export * from './alerts'; export * from './alerts';
export * from './slider'; export * from './slider';

View File

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

View File

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