feat: fixed feedback

This commit is contained in:
=
2025-02-25 16:30:21 +05:30
parent 11f2719842
commit c16a4e00d8
3 changed files with 27 additions and 16 deletions

View File

@@ -69,13 +69,13 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
const gatewayProxyWrapper = async (
providerInputs: z.infer<typeof DynamicSecretSqlDBSchema>,
gatewayCallback: (port: number) => Promise<void>
gatewayCallback: (host: string, port: number) => Promise<void>
) => {
const relayDetails = await gatewayService.fnGetGatewayClientTls(providerInputs.projectGatewayId as string);
const [relayHost, relayPort] = relayDetails.relayAddress.split(":");
await withGatewayProxy(
async (port) => {
await gatewayCallback(port);
await gatewayCallback("localhost", port);
},
{
targetHost: providerInputs.host,
@@ -96,8 +96,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
const validateConnection = async (inputs: unknown) => {
const providerInputs = await validateProviderInputs(inputs);
let isConnected = false;
const gatewayCallback = async (port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port });
const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port, host });
// oracle needs from keyword
const testStatement = providerInputs.client === SqlProviders.Oracle ? "SELECT 1 FROM DUAL" : "SELECT 1";
@@ -106,8 +106,10 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
};
if (providerInputs.projectGatewayId) {
console.log(">>>>>> inside gateway");
await gatewayProxyWrapper(providerInputs, gatewayCallback);
} else {
console.log(">>>>>> outside gateway");
await gatewayCallback();
}
return isConnected;
@@ -117,8 +119,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
const providerInputs = await validateProviderInputs(inputs);
const username = generateUsername(providerInputs.client);
const password = generatePassword(providerInputs.client);
const gatewayCallback = async (port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port });
const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port, host });
const { database } = providerInputs;
const expiration = new Date(expireAt).toISOString();
@@ -150,8 +152,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
const providerInputs = await validateProviderInputs(inputs);
const username = entityId;
const { database } = providerInputs;
const gatewayCallback = async (port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port });
const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port, host });
const revokeStatement = handlebars.compile(providerInputs.revocationStatement)({ username, database });
const queries = revokeStatement.toString().split(";").filter(Boolean);
await db.transaction(async (tx) => {
@@ -175,8 +177,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO)
const providerInputs = await validateProviderInputs(inputs);
if (!providerInputs.renewStatement) return { entityId };
const gatewayCallback = async (port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port });
const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
const db = await $getClient({ ...providerInputs, port, host });
const expiration = new Date(expireAt).toISOString();
const { database } = providerInputs;

View File

@@ -88,9 +88,14 @@ export const gatewayServiceFactory = ({
};
const getGatewayRelayDetails = async (actorId: string, actorOrgId: string, actorAuthMethod: ActorAuthMethod) => {
const TURN_CRED_EXPIRY = 5 * 60;
const TURN_CRED_EXPIRY = 10 * 60; // 10 minutes
const envCfg = getConfig();
await $validateOrgAccessToGateway(actorOrgId, actorId, actorAuthMethod);
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: actorOrgId
});
if (
!envCfg.GATEWAY_RELAY_AUTH_SECRET ||
@@ -108,7 +113,9 @@ export const gatewayServiceFactory = ({
// keep it in redis for 5mins to avoid generating so many credentials
const previousCredential = await keyStore.getItem(KeyStorePrefixes.GatewayIdentityCredential(actorId));
if (previousCredential) {
const el = await TURN_SERVER_CREDENTIALS_SCHEMA.parseAsync(JSON.parse(previousCredential));
const el = await TURN_SERVER_CREDENTIALS_SCHEMA.parseAsync(
JSON.parse(decryptor({ cipherTextBlob: Buffer.from(previousCredential, "hex") }).toString())
);
turnServerUsername = el.username;
turnServerPassword = el.password;
} else {
@@ -116,7 +123,9 @@ export const gatewayServiceFactory = ({
await keyStore.setItemWithExpiry(
KeyStorePrefixes.GatewayIdentityCredential(actorId),
TURN_CRED_EXPIRY,
JSON.stringify({ username: el.username, password: el.password })
encryptor({
plainText: Buffer.from(JSON.stringify({ username: el.username, password: el.password }))
}).cipherTextBlob.toString("hex")
);
turnServerUsername = el.username;
turnServerPassword = el.password;

View File

@@ -35,7 +35,7 @@ const formSchema = z.object({
revocationStatement: z.string().min(1),
renewStatement: z.string().optional(),
ca: z.string().optional(),
gatewayId: z.string().optional()
projectGatewayId: z.string().optional()
}),
defaultTTL: z.string().superRefine((val, ctx) => {
const valMs = ms(val);
@@ -233,7 +233,7 @@ export const SqlDatabaseInputForm = ({
<div>
<Controller
control={control}
name="provider.gatewayId"
name="provider.projectGatewayId"
defaultValue=""
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
@@ -257,7 +257,7 @@ export const SqlDatabaseInputForm = ({
Internet Gateway
</SelectItem>
{projectGateways?.map((el) => (
<SelectItem value={el.id} key={el.id}>
<SelectItem value={el.projectGatewayId} key={el.projectGatewayId}>
{el.name}
</SelectItem>
))}