Skip to content

Commit

Permalink
[HCK-7986]Fix wallet connection screen to ask the walletPassword and …
Browse files Browse the repository at this point in the history
…remove the need for the serviceName as it can be loaded from tnsnames.ora (#131)

* Fix wallet connection screen to ask the walletPassword and remove the need for the serviceName as it can be loaded from tnsnames.ora

* Fix sonar reports

* Hide wallet password by default
  • Loading branch information
bigorn0 authored Sep 17, 2024
1 parent f28afc3 commit 7fe22d6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@
"description": "Specify the service name of the Oracle Instance",
"inputType": "text",
"dependency": {
"type": "or",
"values": [
{
"key": "identifierType",
"value": "serviceName"
},
{
"key": "connectionMethod",
"value": ["Wallet", "TNS"]
}
]
"key": "connectionMethod",
"value": ["TNS"]
}
},
{
"inputLabel": "Wallet Password",
"inputKeyword": "walletPassword",
"description": "Specify the password used to protect the wallet",
"inputType": "password",
"isHiddenKey": true,
"dependency": {
"key": "connectionMethod",
"value": ["Wallet"]
}
},
{
Expand Down
85 changes: 51 additions & 34 deletions reverse_engineering/helpers/oracleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const parseProxyOptions = (proxyString = '') => {
};

const getTnsNamesOraFile = configDir => {
return [
const tnsNamesOraFile = [
configDir,
process.env.TNS_ADMIN,
path.join(process.env.ORACLE_HOME || '', 'network', 'admin'),
Expand All @@ -43,6 +43,8 @@ const getTnsNamesOraFile = configDir => {
return filePath;
}
}, '');

return tnsNamesOraFile;
};

const parseTnsNamesOra = filePath => {
Expand All @@ -63,16 +65,24 @@ const getConnectionStringByTnsNames = (configDir, serviceName, proxy, logger) =>
const tnsData = parseTnsNamesOra(filePath);

logger({ message: 'tnsnames.ora successfully parsed' });
const tnsServicesNames = Object.keys(tnsData);

if (!tnsData[serviceName]) {
logger({ message: 'Cannot find "' + serviceName + '" in tnsnames.ora' });

if (!tnsData[serviceName] && tnsServicesNames.length === 0) {
logger({ message: `Cannot find '${serviceName}' in tnsnames.ora and no fallback found` });
return serviceName;
}

const address = tnsData[serviceName]?.data?.description?.address;
const service = tnsData[serviceName]?.data?.description?.connect_data?.service_name;
const sid = tnsData[serviceName]?.data?.description?.connect_data?.sid;
const [firstTnsServiceName] = tnsServicesNames;
const tnsService = tnsData[serviceName] || tnsData[firstTnsServiceName];
if (!tnsData[serviceName]) {
logger({
message: `Connect using first TNS service ${firstTnsServiceName}' from ${path.join(configDir, 'tnsnames.ora')}.`,
});
}

const address = tnsService?.data?.description?.address;
const service = tnsService?.data?.description?.connect_data?.service_name;
const sid = tnsService?.data?.description?.connect_data?.sid;

logger({ message: 'tnsnames.ora', address, service });

Expand Down Expand Up @@ -178,6 +188,7 @@ const getSshConnectionString = async (data, sshService, logger) => {
const connect = async (
{
walletFile,
walletPassword,
tempFolder,
name,
connectionMethod,
Expand Down Expand Up @@ -244,11 +255,7 @@ const connect = async (
let connectString = '';

if (['Wallet', 'TNS'].includes(connectionMethod)) {
if (proxy) {
connectString = getConnectionStringByTnsNames(configDir, serviceName, proxy, logger);
} else {
connectString = serviceName;
}
connectString = getConnectionStringByTnsNames(configDir, serviceName, proxy, logger);
} else {
connectString = getConnectionDescription(
{
Expand Down Expand Up @@ -303,6 +310,8 @@ const connect = async (
password: userPassword,
queryRequestTimeout,
authRole,
walletLocation: configDir,
walletPassword,
});
};

Expand All @@ -327,29 +336,37 @@ const disconnect = async sshService => {
});
};

const authByCredentials = ({ connectString, username, password, queryRequestTimeout, authRole }) => {
const authByCredentials = ({
connectString,
username,
password,
queryRequestTimeout,
authRole,
walletPassword,
walletLocation,
}) => {
return new Promise((resolve, reject) => {
oracleDB.getConnection(
{
username,
password,
connectString,
privilege: authRole === 'default' ? undefined : oracleDB[authRole],
},
(err, conn) => {
if (err) {
connection = null;
return reject(err);
}
try {
conn.callTimeout = Number(queryRequestTimeout || 0);
connection = conn;
resolve();
} catch (err) {
reject(err);
}
},
);
const connectionConfig = {
username,
password,
connectString,
privilege: authRole === 'default' ? undefined : oracleDB[authRole],
walletLocation,
walletPassword,
};
oracleDB.getConnection(connectionConfig, (err, conn) => {
if (err) {
connection = null;
return reject(err);
}
try {
conn.callTimeout = Number(queryRequestTimeout || 0);
connection = conn;
resolve();
} catch (err) {
reject(err);
}
});
});
};

Expand Down

0 comments on commit 7fe22d6

Please sign in to comment.