Skip to content

Commit

Permalink
Merge pull request #33 from Vitalii4as/fix/HCK-3432
Browse files Browse the repository at this point in the history
RE: add showing of error message if user have error related to privileges and they does not have role SELECT_CATALOG_ROLE
  • Loading branch information
Vitalii4as authored Apr 21, 2023
2 parents f0a53f8 + 0e5c121 commit 629d21b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ module.exports = {

callback(null, packages.filter(Boolean), { version: dbVersion });
} catch (error) {
if (error?.errorNum === 31603) {
logger.log(
'error',
{
message: 'Missing required role “SELECT_CATALOG_ROLE” to perform this operation',
stack: error.stack,
error,
},
'Reverse-engineering process failed',
);
return callback({
message: 'Missing required role “SELECT_CATALOG_ROLE” to perform this operation',
type: 'simpleError',
});
}

logger.log('error', { message: error.message, stack: error.stack, error }, 'Reverse-engineering process failed');
callback({ message: error.message, stack: error.stack });
}
Expand Down
31 changes: 31 additions & 0 deletions reverse_engineering/helpers/oracleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ const getDDL = async (tableName, schema, logger) => {
};
}
} catch (err) {
if(err?.errorNum === 31603 && !(await checkUserHaveRequiredRole(logger))) {
throw err;
}

logger.log('error', {
message: 'Cannot get DDL for table: ' + tableName,
error: { message: err.message, stack: err.stack, err: _.omit(err, ['message', 'stack']) }
Expand Down Expand Up @@ -706,6 +710,10 @@ const getViewDDL = async (viewName, logger) => {
const viewDDL = await _.first(_.first(queryResult)).getData();
return viewDDL;
} catch (err) {
if(err?.errorNum === 31603 && !(await checkUserHaveRequiredRole(logger))) {
throw err;
}

logger.log('error', {
message: 'Cannot get DDL for view: ' + viewName,
error: { message: err.message, stack: err.stack, err: _.omit(err, ['message', 'stack']) }
Expand All @@ -714,6 +722,29 @@ const getViewDDL = async (viewName, logger) => {
}
};

const checkUserHaveRequiredRole = async (logger) => {
try {
const userResult = await execute("SELECT sys_context('USERENV', 'CURRENT_USER') FROM dual");
const username = _.first(_.first(userResult));
const roles = (await execute(`SELECT GRANTED_ROLE FROM USER_ROLE_PRIVS WHERE USERNAME = '${username}'`))?.map(
([role]) => role,
);

return roles.includes('SELECT_CATALOG_ROLE');
} catch (error) {
logger.log(
'error',
{
message: 'Checking user privileges error',
error: { message: error.message, stack: error.stack, err: _.omit(error, ['message', 'stack']) },
},
'Getting DDL',
);

return false;
}
}

const logEnvironment = (logger) => {
logger.log('info', {
TNS_ADMIN: process.env.TNS_ADMIN ?? '',
Expand Down

0 comments on commit 629d21b

Please sign in to comment.