Skip to content

Commit

Permalink
load testing: remove call to getConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
TBonnin committed Feb 9, 2024
1 parent 6055a95 commit 37a05d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 37 deletions.
26 changes: 13 additions & 13 deletions packages/server/lib/controllers/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ConnectionController {
const accountId = getAccount(res);
const connectionId = req.params['connectionId'] as string;
const providerConfigKey = req.query['provider_config_key'] as string;
const returnRefreshToken = req.query['refresh_token'] === 'true';
// const returnRefreshToken = req.query['refresh_token'] === 'true';
const instantRefresh = req.query['force_refresh'] === 'true';

const action = LogActionEnum.TOKEN;
Expand All @@ -257,18 +257,18 @@ class ConnectionController {
return;
}

if (connection && connection.credentials && connection.credentials.type === ProviderAuthModes.OAuth2 && !returnRefreshToken) {
if (connection.credentials.refresh_token) {
delete connection.credentials.refresh_token;
}

if (connection.credentials.raw && connection.credentials.raw['refresh_token']) {
const rawCreds = { ...connection.credentials.raw }; // Properties from 'raw' are not mutable so we need to create a new object.
delete rawCreds['refresh_token'];
connection.credentials.raw = rawCreds;
}
}

// if (connection && connection.credentials && connection.credentials.type === ProviderAuthModes.OAuth2 && !returnRefreshToken) {
// if (connection.credentials.refresh_token) {
// delete connection.credentials.refresh_token;
// }
//
// if (connection.credentials.raw && connection.credentials.raw['refresh_token']) {
// const rawCreds = { ...connection.credentials.raw }; // Properties from 'raw' are not mutable so we need to create a new object.
// delete rawCreds['refresh_token'];
// connection.credentials.raw = rawCreds;
// }
// }
//
res.status(200).send(connection);
} catch (err) {
next(err);
Expand Down
66 changes: 42 additions & 24 deletions packages/shared/lib/services/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,24 @@ class ConnectionService {
return { success: false, error, response: null };
}

const { success, error, response: connection } = await this.getConnection(connectionId, providerConfigKey, environmentId);
// const { success, error, response: connection } = await this.getConnection(connectionId, providerConfigKey, environmentId);
const success = true;
const error = null;
const connection: Connection = {
id: 146,
connection_id: 'thomas',
provider_config_key: 'demo-github-integration',
environment_id: 184,
credentials: {
type: ProviderAuthModes.OAuth2,
access_token: '1',
refresh_token: '1',
expires_at: new Date(),
raw: {}
},
connection_config: {},
metadata: {}
};

if (!success) {
return { success, error, response: null };
Expand Down Expand Up @@ -601,29 +618,30 @@ class ConnectionService {
return { success: false, error, response: null };
}

const template: ProviderTemplate | undefined = configService.getTemplate(config?.provider as string);

if (connection?.credentials?.type === ProviderAuthModes.OAuth2 || connection?.credentials?.type === ProviderAuthModes.App) {
const {
success,
error,
response: credentials
} = await this.refreshCredentialsIfNeeded(
connection as Connection,
config as ProviderConfig,
template as ProviderTemplateOAuth2,
activityLogId,
environmentId,
instantRefresh,
action
);

if (!success) {
return { success, error, response: null };
}

connection.credentials = credentials as OAuth2Credentials;
}
// const template: ProviderTemplate | undefined = configService.getTemplate(config?.provider as string);
//
// if (connection?.credentials?.type === ProviderAuthModes.OAuth2 || connection?.credentials?.type === ProviderAuthModes.App) {
// const {
// success,
// error,
// response: credentials
// } = await this.refreshCredentialsIfNeeded(
// connection as Connection,
// config as ProviderConfig,
// template as ProviderTemplateOAuth2,
// activityLogId,
// environmentId,
// instantRefresh,
// action
// );
//
// if (!success) {
// return { success, error, response: null };
// }
//
// connection.credentials = credentials as OAuth2Credentials;
// }
console.log(action, instantRefresh);

return { success: true, error: null, response: connection };
}
Expand Down

0 comments on commit 37a05d7

Please sign in to comment.