Skip to content

Commit

Permalink
provide functionality to dump certificates from app server (#53)
Browse files Browse the repository at this point in the history
* provide functionality to dump certificates from app server

* fix tests

* respect app instance & applied feedback

* default appInstance in parameter

---------

Co-authored-by: d060338 <[email protected]>
  • Loading branch information
Kkoile and d060338 authored Jan 11, 2024
1 parent f1a8606 commit 6db6e0d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ commands:
~ srv --server-info call server /info
~ srvd --server-debug [APP_NAME] [APP_INSTANCE] open ssh tunnel to port /info {debugPort}
~ srvenv --server-env [APP_NAME] dump system environment
~ srvcrt --server-certificates [APP_NAME] [APP_INSTANCE] dump instance certificates
* --server-start-debugger [APP_NAME] [APP_INSTANCE] start debugger on server node process
... [APP_NAME] run server commands for a specific app
... [APP_INSTANCE] tunnel to specific app instance, fallback to 0
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ commands:
~ srv --server-info call server /info
~ srvd --server-debug [APP_NAME] [APP_INSTANCE] open ssh tunnel to port /info {debugPort}
~ srvenv --server-env [APP_NAME] dump system environment
~ srvcrt --server-certificates [APP_NAME] [APP_INSTANCE] dump instance certificates
* --server-start-debugger [APP_NAME] [APP_INSTANCE] start debugger on server node process
... [APP_NAME] run server commands for a specific app
... [APP_INSTANCE] tunnel to specific app instance, fallback to 0
Expand Down
7 changes: 7 additions & 0 deletions src/cliOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ module.exports = {
useCache: false,
readonly: true,
},
SRV_CERTIFICATES: {
commandVariants: ["srvcrt", "--server-certificates"],
optionalPassArgs: [PASS_ARG.APP_NAME, PASS_ARG.APP_INSTANCE],
callback: srv.serverCertificates,
useCache: false,
readonly: true,
},
SRV_START_DEBUGGER: {
commandVariants: ["--server-start-debugger"],
optionalPassArgs: [PASS_ARG.APP_NAME, PASS_ARG.APP_INSTANCE],
Expand Down
11 changes: 11 additions & 0 deletions src/submodules/serverDiagnostic.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const serverEnvironment = async (context, [appName]) => {
);
console.log(`saved system environment to ${DEFAULT_ENV_FILENAME}`);
};
const serverCertificates = async (context, [appName, appInstance = 0]) => {
const { cfSsh, cfAppName } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo();
const dumpFile = async (cfFilename, localFilename) => {
const [file] = await cfSsh({ command: `cat ${cfFilename}`, appInstance });
writeFileSync(localFilename, file);
};
await dumpFile("$CF_INSTANCE_CERT", `certificate-${cfAppName}-${appInstance}.crt`);
await dumpFile("$CF_INSTANCE_KEY", `certificate-${cfAppName}-${appInstance}.key`);
console.log("saved instance certificates");
};

const serverStartDebugger = async (context, [appName, appInstance]) => {
const { cfSsh } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo();
Expand All @@ -92,5 +102,6 @@ module.exports = {
serverInfo,
serverDebug,
serverEnvironment,
serverCertificates,
serverStartDebugger,
};

0 comments on commit 6db6e0d

Please sign in to comment.