open-consul/ui-v2/config/environment.js
John Cowen 412eec7f5d UI: Improved Login/Logout flow inc SSO support (#7790)
* 6 new components for new login/logout flow, plus SSO support

UI Components:

1. AuthDialog: Wraps/orchestrates AuthForm and AuthProfile
2. AuthForm: Authorization form shown when logged out.
3. AuthProfile: Simple presentational component to show the users
'Profile'
4. OidcSelect: A 'select' component for selecting an OIDC provider,
dynamically uses either a single select menu or multiple buttons
depending on the amount of providers

Data Components:

1. JwtSource: Given an OIDC provider URL this component will request a
token from the provider and fire an donchange event when it has been
retrieved. Used by TokenSource.
2. TokenSource: Given a oidc provider name or a Consul SecretID,
TokenSource will use whichever method/API requests required to retrieve
Consul ACL Token, which is emitted to the onchange event handler.

Very basic README documentation included here, which is likely to be
refined somewhat.

* CSS required for new auth/SSO UI components

* Remaining app code required to tie the new auth/SSO work together

* CSS code required to help tie the auth/SSO work together

* Test code in order to get current tests passing with new auth/SSO flow

..plus extremely basics/skipped rendering tests for the new components

* Treat the secret received from the server as the truth

Previously we've always treated what the user typed as the truth, this
breaks down when using SSO as the user doesn't type anything to retrieve
a token. Therefore we change this so that we use the secret in the API
response as the truth.

* Make sure removing an dom tree from a buffer only removes its own tree
2020-05-12 17:14:51 +00:00

156 lines
5 KiB
JavaScript

'use strict';
const fs = require('fs');
const path = require('path');
module.exports = function(environment, $ = process.env) {
let ENV = {
modulePrefix: 'consul-ui',
environment,
rootURL: '/ui/',
locationType: 'auto',
// We use a complete dynamically (from Consul) configured
// torii provider. We provide this object here to
// prevent ember from giving a log message when starting ember up
torii: {},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
resizeServiceDefaults: {
injectionFactories: ['view', 'controller', 'component'],
},
};
// TODO: These should probably go onto APP
ENV = Object.assign({}, ENV, {
CONSUL_UI_DISABLE_REALTIME: typeof process.env.CONSUL_UI_DISABLE_REALTIME !== 'undefined',
CONSUL_UI_DISABLE_ANCHOR_SELECTION:
typeof process.env.CONSUL_UI_DISABLE_ANCHOR_SELECTION !== 'undefined',
CONSUL_COPYRIGHT_YEAR: (function(val) {
if (val) {
return val;
}
return require('child_process')
.execSync('git show -s --format=%ci HEAD')
.toString()
.trim()
.split('-')
.shift();
})(process.env.CONSUL_COPYRIGHT_YEAR),
CONSUL_GIT_SHA: (function(val) {
if (val) {
return val;
}
return require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim();
})(process.env.CONSUL_GIT_SHA),
CONSUL_VERSION: (function(val) {
if (val) {
return val;
}
// see /scripts/dist.sh:8
const version_go = `${path.dirname(path.dirname(__dirname))}/version/version.go`;
const contents = fs.readFileSync(version_go).toString();
return contents
.split('\n')
.find(function(item, i, arr) {
return item.indexOf('Version =') !== -1;
})
.trim()
.split('"')[1];
})(process.env.CONSUL_VERSION),
CONSUL_BINARY_TYPE: process.env.CONSUL_BINARY_TYPE ? process.env.CONSUL_BINARY_TYPE : 'oss',
CONSUL_ACLS_ENABLED: false,
CONSUL_NSPACES_ENABLED: false,
CONSUL_SSO_ENABLED: false,
CONSUL_HOME_URL: 'https://www.consul.io',
CONSUL_REPO_ISSUES_URL: 'https://github.com/hashicorp/consul/issues/new/choose',
CONSUL_DOCS_URL: 'https://www.consul.io/docs',
CONSUL_DOCS_LEARN_URL: 'https://learn.hashicorp.com',
CONSUL_DOCS_API_URL: 'https://www.consul.io/api',
CONSUL_COPYRIGHT_URL: 'https://www.hashicorp.com',
});
const isTestLike = ['staging', 'test'].indexOf(environment) > -1;
const isDevLike = ['development', 'staging', 'test'].indexOf(environment) > -1;
const isProdLike = ['production', 'staging'].indexOf(environment) > -1;
switch (true) {
case environment === 'test':
ENV = Object.assign({}, ENV, {
locationType: 'none',
CONSUL_NSPACES_TEST: true,
CONSUL_NSPACES_ENABLED:
typeof $['CONSUL_NSPACES_ENABLED'] !== 'undefined'
? !!JSON.parse(String($['CONSUL_NSPACES_ENABLED']).toLowerCase())
: true,
CONSUL_SSO_ENABLED:
typeof $['CONSUL_SSO_ENABLED'] !== 'undefined'
? !!JSON.parse(String($['CONSUL_SSO_ENABLED']).toLowerCase())
: false,
'@hashicorp/ember-cli-api-double': {
'auto-import': false,
enabled: true,
endpoints: {
'/v1': '/node_modules/@hashicorp/consul-api-double/v1',
},
},
APP: Object.assign({}, ENV.APP, {
LOG_ACTIVE_GENERATION: false,
LOG_VIEW_LOOKUPS: false,
rootElement: '#ember-testing',
autoboot: false,
}),
});
break;
case environment === 'staging':
ENV = Object.assign({}, ENV, {
CONSUL_NSPACES_ENABLED: true,
CONSUL_SSO_ENABLED: true,
'@hashicorp/ember-cli-api-double': {
enabled: true,
endpoints: {
'/v1': '/node_modules/@hashicorp/consul-api-double/v1',
},
},
});
break;
case environment === 'production':
ENV = Object.assign({}, ENV, {
CONSUL_ACLS_ENABLED: '{{.ACLsEnabled}}',
CONSUL_SSO_ENABLED: '{{.SSOEnabled}}',
CONSUL_NSPACES_ENABLED:
'{{ if .NamespacesEnabled }}{{.NamespacesEnabled}}{{ else }}false{{ end }}',
});
break;
}
switch (true) {
case isTestLike:
ENV = Object.assign({}, ENV, {
CONSUL_ACLS_ENABLED: true,
// 'APP': Object.assign({}, ENV.APP, {
// 'LOG_RESOLVER': true,
// 'LOG_ACTIVE_GENERATION': true,
// 'LOG_TRANSITIONS': true,
// 'LOG_TRANSITIONS_INTERNAL': true,
// 'LOG_VIEW_LOOKUPS': true,
// })
});
break;
case isProdLike:
break;
}
return ENV;
};