Skip to content

Commit

Permalink
feat(dashmate)!: move ssl dir (dashpay#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic authored Oct 23, 2023
1 parent 8030147 commit 67f2282
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
28 changes: 28 additions & 0 deletions packages/dashmate/configs/getConfigFileMigrationsFactory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable no-param-reassign */
const fs = require('fs');
const path = require('path');

const { NETWORK_LOCAL, NETWORK_TESTNET, NETWORK_MAINNET } = require('../src/constants');

Expand Down Expand Up @@ -240,6 +242,32 @@ function getConfigFileMigrationsFactory(homeDir, defaultConfigs) {
options.platform.drive.abci.logs = base.get('platform.drive.abci.logs');
});

return configFile;
},
'0.25.7': (configFile) => {
Object.entries(configFile.configs)
.forEach(([name, options]) => {
if (options.network !== NETWORK_MAINNET) {
const filenames = ['private.key', 'bundle.crt', 'bundle.csr', 'csr.pem'];

for (const filename of filenames) {
const oldFilePath = homeDir.joinPath('ssl', name, filename);
const newFilePath = homeDir.joinPath(name,
'platform', 'dapi', 'envoy', 'ssl', filename);

if (fs.existsSync(oldFilePath)) {
fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
fs.copyFileSync(oldFilePath, newFilePath);
fs.rmSync(oldFilePath, { recursive: true });
}
}
}
});

if (fs.existsSync(homeDir.joinPath('ssl'))) {
fs.rmSync(homeDir.joinPath('ssl'), { recursive: true });
}

return configFile;
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/dashmate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ services:
- ENVOY_GID=${LOCAL_GID:?err}
volumes:
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/platform/dapi/envoy/envoy.yaml:/etc/envoy/envoy.yaml:ro
- ${DASHMATE_HOME_DIR:?err}/ssl/${CONFIG_NAME:?err}/bundle.crt:/etc/ssl/bundle.crt:ro
- ${DASHMATE_HOME_DIR:?err}/ssl/${CONFIG_NAME:?err}/private.key:/etc/ssl/private.key:ro
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/platform/dapi/envoy/ssl/bundle.crt:/etc/ssl/bundle.crt:ro
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/platform/dapi/envoy/ssl/private.key:/etc/ssl/private.key:ro
stop_grace_period: 10s
profiles:
- platform
Expand Down
7 changes: 6 additions & 1 deletion packages/dashmate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@
"name": "Konstantin Shuplenkov",
"email": "[email protected]",
"url": "https://github.com/shuplenkov"
},
{
"name": "Mikhail Pshenichnikov",
"email": "[email protected]",
"url": "https://github.com/pshenmic"
}
],
"engines": {
"node": ">=12"
"node": ">=18"
},
"license": "MIT",
"bugs": {
Expand Down
6 changes: 0 additions & 6 deletions packages/dashmate/src/listr/tasks/resetNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ function resetNodeTaskFactory(
recursive: true,
force: true,
});

// Remove SSL files
fs.rmSync(homeDir.joinPath('ssl', baseConfigName), {
recursive: true,
force: true,
});
},
},
]);
Expand Down
9 changes: 5 additions & 4 deletions packages/dashmate/src/listr/tasks/ssl/saveCertificateTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ function saveCertificateTaskFactory(homeDir) {
{
title: 'Save certificates',
task: async (ctx) => {
const configDir = homeDir.joinPath('ssl', config.getName());
const certificatesDir = homeDir.joinPath(config.getName(),
'platform', 'dapi', 'envoy', 'ssl');

fs.mkdirSync(configDir, { recursive: true });
fs.mkdirSync(certificatesDir, { recursive: true });

const crtFile = path.join(configDir, 'bundle.crt');
const crtFile = path.join(certificatesDir, 'bundle.crt');

fs.writeFileSync(crtFile, ctx.certificateFile, 'utf8');

const keyFile = path.join(configDir, 'private.key');
const keyFile = path.join(certificatesDir, 'private.key');
fs.writeFileSync(keyFile, ctx.privateKeyFile, 'utf8');

config.set('platform.dapi.envoy.ssl.enabled', true);
Expand Down

0 comments on commit 67f2282

Please sign in to comment.