Skip to content

Commit

Permalink
Merge pull request #310 from vscheuber/main
Browse files Browse the repository at this point in the history
improve connection profiles file initialization
  • Loading branch information
vscheuber authored Sep 26, 2023
2 parents 065b371 + bcc2b9e commit 9dd2399
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/ops/ConnectionProfileOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@ const newProfileFilename = 'Connections.json';
* @returns {String} connection profiles file name
*/
export function getConnectionProfilesPath({ state }: { state: State }): string {
return (
debugMessage({
message: `ConnectionProfileOps.getConnectionProfilesPath: start`,
state,
});
const profilesPath =
state.getConnectionProfilesPath() ||
process.env[Constants.FRODO_CONNECTION_PROFILES_PATH_KEY] ||
`${os.homedir()}/.frodo/${newProfileFilename}`
);
`${os.homedir()}/.frodo/${newProfileFilename}`;
debugMessage({
message: `ConnectionProfileOps.getConnectionProfilesPath: end [profilesPath=${profilesPath}]`,
state,
});
return profilesPath;
}

/**
Expand Down Expand Up @@ -266,16 +274,30 @@ function migrateFromLegacyProfile() {
* @param {State} state library state
*/
export async function initConnectionProfiles({ state }: { state: State }) {
debugMessage({
message: `ConnectionProfileOps.initConnectionProfiles: start`,
state,
});
const dataProtection = new DataProtection({
pathToMasterKey: state.getMasterKeyPath(),
state,
});
// create connections.json file if it doesn't exist
const filename = getConnectionProfilesPath({ state });
const folderName = path.dirname(filename);
if (!fs.existsSync(folderName)) {
fs.mkdirSync(folderName, { recursive: true });
if (!fs.existsSync(filename)) {
if (!fs.existsSync(folderName)) {
debugMessage({
message: `ConnectionProfileOps.initConnectionProfiles: folder does not exist: ${folderName}, creating...`,
state,
});
fs.mkdirSync(folderName, { recursive: true });
}
if (!fs.existsSync(filename)) {
debugMessage({
message: `ConnectionProfileOps.initConnectionProfiles: file does not exist: ${filename}, creating...`,
state,
});
fs.writeFileSync(
filename,
JSON.stringify({}, null, fileOptions.indentation)
Expand Down Expand Up @@ -317,6 +339,10 @@ export async function initConnectionProfiles({ state }: { state: State }) {
);
}
}
debugMessage({
message: `ConnectionProfileOps.initConnectionProfiles: end`,
state,
});
}

/**
Expand Down

0 comments on commit 9dd2399

Please sign in to comment.