Skip to content

Commit

Permalink
Readd server configuration task. (#16104)
Browse files Browse the repository at this point in the history
* Fallback prodDatabaseType and devDatabaseType to databaseType at prompt.

* Revert server configuring task.

* Move back some derived properties.

* Update snapshot.
  • Loading branch information
mshima authored Aug 31, 2021
1 parent 3c8f306 commit 5a45f1e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 55 deletions.
49 changes: 0 additions & 49 deletions generators/generator-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const { GATLING, CUCUMBER, PROTRACTOR, CYPRESS } = require('../jdl/jhipster/test
const { GATEWAY, MICROSERVICE, MONOLITH } = require('../jdl/jhipster/application-types');
const { ELASTICSEARCH } = require('../jdl/jhipster/search-engine-types');
const { CUSTOM_PRIORITIES } = require('../lib/constants/priorities.cjs');
const { getBase64Secret, getRandomHex } = require('./utils');
const cacheTypes = require('../jdl/jhipster/cache-types');
const serviceDiscoveryTypes = require('../jdl/jhipster/service-discovery-types');
const searchEngineTypes = require('../jdl/jhipster/search-engine-types');
Expand Down Expand Up @@ -2848,30 +2847,6 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.packageFolder = dest.packageName.replace(/\./g, '/');
}

// JWT authentication is mandatory with Eureka, so the JHipster Registry
// can control the applications
if (dest.serviceDiscoveryType === EUREKA && dest.authenticationType !== OAUTH2) {
dest.authenticationType = JWT;
}

// Generate JWT secret key if key does not already exist in config
if ((dest.authenticationType === JWT || dest.applicationType === MICROSERVICE) && dest.jwtSecretKey === undefined) {
dest.jwtSecretKey = getBase64Secret.call(this, null, 64);
}
// Generate remember me key if key does not already exist in config
if (dest.authenticationType === SESSION && !dest.rememberMeKey) {
dest.rememberMeKey = getRandomHex();
}

if (dest.authenticationType === OAUTH2) {
dest.skipUserManagement = true;
}

if (dest.enableHibernateCache && [NO_CACHE, MEMCACHED].includes(dest.cacheProvider)) {
this.info(`Disabling hibernate cache for cache provider ${dest.cacheProvider}`);
dest.enableHibernateCache = false;
}

// Convert to false for templates.
if (dest.serviceDiscoveryType === NO_SERVICE_DISCOVERY || !dest.serviceDiscoveryType) {
dest.serviceDiscoveryType = false;
Expand All @@ -2886,30 +2861,6 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.messageBroker = false;
}

if (!dest.databaseType && dest.prodDatabaseType) {
dest.databaseType = this.getDBTypeFromDBValue(dest.prodDatabaseType);
}
if (!dest.devDatabaseType && dest.prodDatabaseType) {
dest.devDatabaseType = dest.prodDatabaseType;
}

// force variables unused by microservice applications
if (dest.applicationType === MICROSERVICE) {
dest.websocket = false;
}

const databaseType = dest.databaseType;
if (databaseType === NO_DATABASE) {
dest.devDatabaseType = NO_DATABASE;
dest.prodDatabaseType = NO_DATABASE;
dest.enableHibernateCache = false;
dest.skipUserManagement = true;
} else if ([MONGODB, NEO4J, COUCHBASE, CASSANDRA].includes(databaseType)) {
dest.devDatabaseType = databaseType;
dest.prodDatabaseType = databaseType;
dest.enableHibernateCache = false;
}

dest.authenticationTypeSession = dest.authenticationType === SESSION;
dest.authenticationTypeJwt = dest.authenticationType === JWT;
dest.authenticationTypeOauth2 = dest.authenticationType === OAUTH2;
Expand Down
77 changes: 74 additions & 3 deletions generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,37 @@ const os = require('os');
const prompts = require('./prompts');
const { GENERATOR_COMMON, GENERATOR_LANGUAGES, GENERATOR_SERVER } = require('../generator-list');
const databaseTypes = require('../../jdl/jhipster/database-types');
const { OAUTH2, SESSION } = require('../../jdl/jhipster/authentication-types');
const { CASSANDRA, COUCHBASE, MARIADB, MSSQL, MYSQL, ORACLE, POSTGRESQL, SQL } = require('../../jdl/jhipster/database-types');
const { CAFFEINE, EHCACHE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = require('../../jdl/jhipster/cache-types');
const BaseBlueprintGenerator = require('../generator-base-blueprint');
const writeFiles = require('./files').writeFiles;
const packagejs = require('../../package.json');
const constants = require('../generator-constants');
const statistics = require('../statistics');
const { defaultConfig } = require('../generator-defaults');
const { JWT, OAUTH2, SESSION } = require('../../jdl/jhipster/authentication-types');
const {
CASSANDRA,
COUCHBASE,
MARIADB,
MSSQL,
MYSQL,
ORACLE,
POSTGRESQL,
SQL,
MONGODB,
NEO4J,
} = require('../../jdl/jhipster/database-types');
const { CAFFEINE, EHCACHE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = require('../../jdl/jhipster/cache-types');
const { GRADLE, MAVEN } = require('../../jdl/jhipster/build-tool-types');
const { ELASTICSEARCH } = require('../../jdl/jhipster/search-engine-types');
const { EUREKA } = require('../../jdl/jhipster/service-discovery-types');
const { MICROSERVICE } = require('../../jdl/jhipster/application-types');
const { getBase64Secret, getRandomHex } = require('../utils');
const cacheTypes = require('../../jdl/jhipster/cache-types');
const websocketTypes = require('../../jdl/jhipster/websocket-types');

const NO_CACHE = cacheTypes.NO;
const NO_DATABASE = databaseTypes.NO;
const NO_WEBSOCKET = websocketTypes.FALSE;

let useBlueprints;

Expand Down Expand Up @@ -227,6 +245,9 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
this.jhipsterConfig.serverPort = 8080 + this.jhipsterConfig.applicationIndex;
}
},
configure() {
this._configureServer();
},
};
}

Expand Down Expand Up @@ -558,4 +579,54 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
if (useBlueprints) return;
return this._end();
}

_configureServer(config = this.jhipsterConfig) {
// JWT authentication is mandatory with Eureka, so the JHipster Registry
// can control the applications
if (config.serviceDiscoveryType === EUREKA && config.authenticationType !== OAUTH2) {
config.authenticationType = JWT;
}

// Generate JWT secret key if key does not already exist in config
if ((config.authenticationType === JWT || config.applicationType === MICROSERVICE) && config.jwtSecretKey === undefined) {
config.jwtSecretKey = getBase64Secret.call(this, null, 64);
}
// Generate remember me key if key does not already exist in config
if (config.authenticationType === SESSION && !config.rememberMeKey) {
config.rememberMeKey = getRandomHex();
}

if (config.authenticationType === OAUTH2) {
config.skipUserManagement = true;
}

if (config.enableHibernateCache && [NO_CACHE, MEMCACHED].includes(config.cacheProvider)) {
this.info(`Disabling hibernate cache for cache provider ${config.cacheProvider}`);
config.enableHibernateCache = false;
}

if (!config.databaseType && config.prodDatabaseType) {
config.databaseType = this.getDBTypeFromDBValue(config.prodDatabaseType);
}
if (!config.devDatabaseType && config.prodDatabaseType) {
config.devDatabaseType = config.prodDatabaseType;
}

// force variables unused by microservice applications
if (config.applicationType === MICROSERVICE) {
config.websocket = NO_WEBSOCKET;
}

const databaseType = config.databaseType;
if (databaseType === NO_DATABASE) {
config.devDatabaseType = NO_DATABASE;
config.prodDatabaseType = NO_DATABASE;
config.enableHibernateCache = false;
config.skipUserManagement = true;
} else if ([MONGODB, NEO4J, COUCHBASE, CASSANDRA].includes(databaseType)) {
config.devDatabaseType = databaseType;
config.prodDatabaseType = databaseType;
config.enableHibernateCache = false;
}
}
};
8 changes: 5 additions & 3 deletions generators/server/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ function askForServerSideOpts() {
this.serverPort = this.jhipsterConfig.serverPort = answers.serverPort || '8080';
this.cacheProvider = this.jhipsterConfig.cacheProvider = !answers.reactive ? answers.cacheProvider : NO_CACHE_PROVIDER;
this.enableHibernateCache = this.jhipsterConfig.enableHibernateCache = !!answers.enableHibernateCache;
this.databaseType = this.jhipsterConfig.databaseType = answers.databaseType;
this.devDatabaseType = this.jhipsterConfig.devDatabaseType = answers.devDatabaseType;
this.prodDatabaseType = this.jhipsterConfig.prodDatabaseType = answers.prodDatabaseType;

const { databaseType } = answers;
this.databaseType = this.jhipsterConfig.databaseType = databaseType;
this.devDatabaseType = this.jhipsterConfig.devDatabaseType = answers.devDatabaseType || databaseType;
this.prodDatabaseType = this.jhipsterConfig.prodDatabaseType = answers.prodDatabaseType || databaseType;
this.searchEngine = this.jhipsterConfig.searchEngine = answers.searchEngine;
this.buildTool = this.jhipsterConfig.buildTool = answers.buildTool;
});
Expand Down
6 changes: 6 additions & 0 deletions test/client/__snapshots__/angular.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ Object {
"src/main/webapp/swagger-ui/index.html": Object {
"stateCleared": "modified",
},
"src/test/resources/i18n/messages_en.properties": Object {
"stateCleared": "modified",
},
"src/test/resources/i18n/messages_fr.properties": Object {
"stateCleared": "modified",
},
"tsconfig.app.json": Object {
"stateCleared": "modified",
},
Expand Down

0 comments on commit 5a45f1e

Please sign in to comment.