Skip to content

Commit

Permalink
srv: consistent defaulting and checking of app instance argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rlindner81 committed Jan 22, 2025
1 parent e7d7fe7 commit 69b7dc6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/submodules/serverDiagnostic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ const _serverDebug = async (context, { appName, appInstance } = {}) => {
url: cfRouteUrl,
pathname: "/info",
auth: { token },
...(/\d+/.test(appInstance) && {
headers: {
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`,
},
}),
headers: {
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`,
},
logged: false,
checkStatus: false,
});
Expand All @@ -47,7 +45,6 @@ const _serverDebug = async (context, { appName, appInstance } = {}) => {
} catch (err) {} // eslint-disable-line no-empty
}
const { debugPort } = responseData;
appInstance = appInstance || "0";
const remotePort = debugPort || inferredPort;
assert(remotePort, `could not determine remote debugPort from /info or infer from buildpack`);

Expand All @@ -63,7 +60,10 @@ const _serverDebug = async (context, { appName, appInstance } = {}) => {
return cfSsh({ localPort, remotePort, appInstance });
};

const serverDebug = async (context, [appName, appInstance]) => _serverDebug(context, { appName, appInstance });
const serverDebug = async (context, [appName, appInstance = "0"]) => {
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`);
return _serverDebug(context, { appName, appInstance });
};

const serverEnvironment = async (context, [appName]) => {
const { cfEnvServices, cfEnvApp, cfEnvVariables } = appName
Expand All @@ -75,7 +75,8 @@ const serverEnvironment = async (context, [appName]) => {
);
logger.info(`saved system environment to ${DEFAULT_ENV_FILENAME}`);
};
const serverCertificates = async (context, [appName, appInstance = 0]) => {
const serverCertificates = async (context, [appName, appInstance = "0"]) => {
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`);
const { cfSsh, cfAppName } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo();
const dumpFile = async (cfFilename, localFilename) => {
const [file] = await cfSsh({ command: `cat ${cfFilename}`, appInstance });
Expand All @@ -86,7 +87,8 @@ const serverCertificates = async (context, [appName, appInstance = 0]) => {
logger.info("saved instance certificates");
};

const serverStartDebugger = async (context, [appName, appInstance]) => {
const serverStartDebugger = async (context, [appName, appInstance = "0"]) => {
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`);
const { cfSsh } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo();
return cfSsh({ command: "pkill --signal SIGUSR1 node", appInstance });
};
Expand Down

0 comments on commit 69b7dc6

Please sign in to comment.