Skip to content

Commit

Permalink
Pass workspaceId for remoteServer and PostgresCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMalfait committed Oct 20, 2024
1 parent 40d752e commit 5477e18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import {
Injectable,
} from '@nestjs/common';

import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';

@Injectable()
export class FilePathGuard implements CanActivate {
constructor(
private readonly jwtWrapperService: JwtWrapperService,
private readonly environmentService: EnvironmentService,
) {}
constructor(private readonly jwtWrapperService: JwtWrapperService) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export class PostgresCredentialsService {
const user = `user_${randomBytes(4).toString('hex')}`;
const password = randomBytes(16).toString('hex');

const key = this.jwtWrapperService.generateAppSecret('POSTGRES_PROXY');
const key = this.jwtWrapperService.generateAppSecret(
'POSTGRES_PROXY',
workspaceId,
);
const passwordHash = encryptText(password, key);

const existingCredentials =
Expand Down Expand Up @@ -81,7 +84,10 @@ export class PostgresCredentialsService {
id: postgresCredentials.id,
});

const key = this.jwtWrapperService.generateAppSecret('POSTGRES_PROXY');
const key = this.jwtWrapperService.generateAppSecret(
'POSTGRES_PROXY',
workspaceId,
);

return {
id: postgresCredentials.id,
Expand All @@ -105,7 +111,10 @@ export class PostgresCredentialsService {
return null;
}

const key = this.jwtWrapperService.generateAppSecret('POSTGRES_PROXY');
const key = this.jwtWrapperService.generateAppSecret(
'POSTGRES_PROXY',
workspaceId,
);

return {
id: postgresCredentials.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class RemoteServerService<T extends RemoteServerType> {
...remoteServerInput.userMappingOptions,
password: this.encryptPassword(
remoteServerInput.userMappingOptions.password,
workspaceId,
),
},
};
Expand Down Expand Up @@ -156,6 +157,7 @@ export class RemoteServerService<T extends RemoteServerType> {
...partialRemoteServerWithUpdates.userMappingOptions,
password: this.encryptPassword(
partialRemoteServerWithUpdates.userMappingOptions.password,
workspaceId,
),
},
};
Expand Down Expand Up @@ -252,8 +254,11 @@ export class RemoteServerService<T extends RemoteServerType> {
});
}

private encryptPassword(password: string) {
const key = this.jwtWrapperService.generateAppSecret('REMOTE_SERVER');
private encryptPassword(password: string, workspaceId: string) {
const key = this.jwtWrapperService.generateAppSecret(
'REMOTE_SERVER',
workspaceId,
);

return encryptText(password, key);
}
Expand Down

0 comments on commit 5477e18

Please sign in to comment.