Skip to content

Commit

Permalink
HCK-8622: fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WilhelmWesser committed Nov 5, 2024
1 parent cf30fab commit 77edc42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
19 changes: 8 additions & 11 deletions reverse_engineering/databaseService/databaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const axios = require('axios');
const sql = require('mssql');
const https = require('https');
const { getObjectsFromDatabase, getNewConnectionClientByDb } = require('./helpers');
const msal = require('@azure/msal-node');
const getSampleDocSize = require('../helpers/getSampleDocSize');
const { logAuthTokenInfo } = require('../helpers/logInfo');
const { getConnection } = require('./helpers/connection');
Expand Down Expand Up @@ -34,16 +33,14 @@ const getConnectionClient = async (connectionInfo, logger) => {
const redirectUri = 'http://localhost:8080';

const connection = getConnection({
type: connectionInfo.authMethod,
data: {
connectionInfo,
commonConfig,
credentialsConfig,
tenantId,
clientId,
redirectUri,
logger,
},
authMethod: connectionInfo.authMethod,
connectionInfo,
commonConfig,
credentialsConfig,
tenantId,
clientId,
redirectUri,
logger,
});

return connection.connect();
Expand Down
30 changes: 18 additions & 12 deletions reverse_engineering/databaseService/helpers/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ const axios = require('axios');
const sql = require('mssql');
const https = require('https');
const msal = require('@azure/msal-node');
const { logAuthTokenInfo } = require('../../helpers/logInfo');
const { logAuthTokenInfo, logConnectionHostAndUsername } = require('../../helpers/logInfo');
const { prepareError } = require('./errorService');

const logConnectionHostAndUsername = ({ hostname, username, authMethod, logger }) => {
logger.log(
'info',
`hostname: ${hostname ?? 'absent'}, username: ${username ?? 'absent'}, auth method: ${authMethod}`,
'Auth info',
);
};

class Connection {
constructor({ logger }) {
this.logger = logger;
Expand Down Expand Up @@ -187,7 +179,7 @@ class AzureActiveDirectoryMFAConnection extends Connection {
}
}

async #getAuthConfig() {
#getAuthConfig() {
return {
system: {
loggerOptions: {
Expand Down Expand Up @@ -243,8 +235,22 @@ class AzureActiveDirectoryUsernamePasswordConnection extends Connection {
}
}

const getConnection = ({ type, data }) => {
switch (type) {
/**
*
* @param {{
* authMethod,
* connectionInfo,
* commonConfig,
* credentialsConfig,
* tenantId,
* clientId,
* redirectUri,
* logger,
* }} param
* @returns {Promise<object>}
*/
const getConnection = ({ authMethod, ...data }) => {
switch (authMethod) {
case 'Username / Password':
return new UsernamePasswordConnection(data);
case 'Username / Password (Windows)':
Expand Down
14 changes: 13 additions & 1 deletion reverse_engineering/helpers/logInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ const logAuthTokenInfo = ({ token, logger }) => {
logger.log('info', { token }, `MFA token is of type ${tokenType}${tokenLength}`, ['token']);
};

const logConnectionHostAndUsername = ({ hostname, username, authMethod, logger }) => {
const hostnameToDisplay = hostname ?? 'absent';
const usernameToDisplay = username ?? 'absent';

logger.log(
'info',
`hostname: ${hostnameToDisplay}, username: ${usernameToDisplay}, auth method: ${authMethod}`,
'Auth info',
);
};

module.exports = {
logAuthTokenInfo,
logInfo,
logAuthTokenInfo,
logConnectionHostAndUsername,
};

0 comments on commit 77edc42

Please sign in to comment.