Browse Source

Nc fix/ssl prop related (#9071)

* fix: handle invalid ssl value in GUI

* fix: handle invalid ssl value in backend and move logic to sdk
pull/9074/head
Pranav C 4 months ago committed by GitHub
parent
commit
4ac5980c51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 52
      packages/nc-gui/components/dashboard/TreeView/ViewsList.vue
  2. 13
      packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue
  3. 14
      packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue
  4. 2
      packages/nc-gui/components/smartsheet/grid/Table.vue
  5. 4
      packages/nc-gui/components/workspace/AuditLogs.vue
  6. 2
      packages/nc-gui/composables/usePaginationShortcuts.ts
  7. 4
      packages/nc-gui/store/views.ts
  8. 10
      packages/nc-gui/utils/baseCreateUtils.ts
  9. 33
      packages/nocodb-sdk/src/lib/connectionConfigUtils.ts
  10. 10
      packages/nocodb-sdk/src/lib/enums.ts
  11. 1
      packages/nocodb-sdk/src/lib/index.ts
  12. 7
      packages/nocodb/src/controllers/utils.controller.ts
  13. 11
      packages/nocodb/src/services/sources.service.ts

52
packages/nc-gui/components/dashboard/TreeView/ViewsList.vue

@ -402,37 +402,37 @@ function onOpenModal({
:selected-keys="selected"
class="nc-views-menu flex flex-col w-full !border-r-0 !bg-inherit"
>
<template v-if="!isSharedBase">
<DashboardTreeViewCreateViewBtn
v-if="isUIAllowed('viewCreateOrEdit')"
:align-left-level="isDefaultSource ? 1 : 2"
:class="{
'!pl-13.3 !xs:(pl-13.5)': isDefaultSource,
'!pl-18.6 !xs:(pl-20)': !isDefaultSource,
}"
:source="source"
>
<div
<template v-if="!isSharedBase">
<DashboardTreeViewCreateViewBtn
v-if="isUIAllowed('viewCreateOrEdit')"
:align-left-level="isDefaultSource ? 1 : 2"
:class="{
'text-brand-500 hover:text-brand-600': activeTableId === table.id,
'text-gray-500 hover:text-brand-500': activeTableId !== table.id,
'!pl-13.3 !xs:(pl-13.5)': isDefaultSource,
'!pl-18.6 !xs:(pl-20)': !isDefaultSource,
}"
class="nc-create-view-btn flex flex-row items-center cursor-pointer rounded-md w-full"
role="button"
:source="source"
>
<div class="flex flex-row items-center pl-1.25 !py-1.5 text-inherit">
<GeneralIcon icon="plus" />
<div class="pl-1.75">
{{
$t('general.createEntity', {
entity: $t('objects.view'),
})
}}
<div
:class="{
'text-brand-500 hover:text-brand-600': activeTableId === table.id,
'text-gray-500 hover:text-brand-500': activeTableId !== table.id,
}"
class="nc-create-view-btn flex flex-row items-center cursor-pointer rounded-md w-full"
role="button"
>
<div class="flex flex-row items-center pl-1.25 !py-1.5 text-inherit">
<GeneralIcon icon="plus" />
<div class="pl-1.75">
{{
$t('general.createEntity', {
entity: $t('objects.view'),
})
}}
</div>
</div>
</div>
</div>
</DashboardTreeViewCreateViewBtn>
</template>
</DashboardTreeViewCreateViewBtn>
</template>
<template v-if="views.length">
<DashboardTreeViewViewsNode
v-for="view of views"

13
packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue

@ -1,6 +1,7 @@
<script lang="ts" setup>
import { Form, message } from 'ant-design-vue'
import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select'
import { validateAndExtractSSLProp } from 'nocodb-sdk'
import {
type CertTypes,
ClientType,
@ -148,7 +149,7 @@ const onSSLModeChange = ((mode: SSLUsage) => {
const connection = formState.value.dataSource.connection as DefaultConnection
switch (mode) {
case SSLUsage.No:
delete connection.ssl
connection.ssl = undefined
break
case SSLUsage.Allowed:
connection.ssl = 'true'
@ -217,14 +218,8 @@ function getConnectionConfig() {
...extraParameters,
}
if ('ssl' in connection && connection.ssl) {
if (
formState.value.sslUse === SSLUsage.No ||
(typeof connection.ssl === 'object' && Object.values(connection.ssl).every((v) => v === null || v === undefined))
) {
delete connection.ssl
}
}
connection.ssl = validateAndExtractSSLProp(connection, formState.value.sslUse, formState.value.dataSource.client)
return connection
}

14
packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue

@ -1,5 +1,5 @@
<script lang="ts" setup>
import type { SourceType } from 'nocodb-sdk'
import { type SourceType, validateAndExtractSSLProp } from 'nocodb-sdk'
import { Form, message } from 'ant-design-vue'
import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select'
import {
@ -133,7 +133,7 @@ const onSSLModeChange = ((mode: SSLUsage) => {
const connection = formState.value.dataSource.connection as DefaultConnection
switch (mode) {
case SSLUsage.No:
delete connection.ssl
connection.ssl = undefined
break
case SSLUsage.Allowed:
connection.ssl = 'true'
@ -202,14 +202,8 @@ function getConnectionConfig() {
...extraParameters,
}
if ('ssl' in connection && connection.ssl) {
if (
formState.value.sslUse === SSLUsage.No ||
(typeof connection.ssl === 'object' && Object.values(connection.ssl).every((v) => v === null || v === undefined))
) {
delete connection.ssl
}
}
connection.ssl = validateAndExtractSSLProp(connection, formState.value.sslUse, formState.value.dataSource.client)
return connection
}

2
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -181,7 +181,7 @@ const { onDrag, onDragStart, onDragEnd, draggedCol, dragColPlaceholderDomRef, to
const { onLeft, onRight, onUp, onDown } = usePaginationShortcuts({
paginationDataRef,
changePage: changePage as any,
isViewDataLoading
isViewDataLoading,
})
// #Variables

4
packages/nc-gui/components/workspace/AuditLogs.vue

@ -475,12 +475,12 @@ onKeyStroke('ArrowDown', onDown)
:total="+auditPaginationData.totalRows"
show-size-changer
:use-stored-page-size="false"
@update:current="loadAudits(undefined, undefined, false)"
@update:page-size="loadAudits(currentPage, $event, false)"
:prev-page-tooltip="`${renderAltOrOptlKey()}+←`"
:next-page-tooltip="`${renderAltOrOptlKey()}+→`"
:first-page-tooltip="`${renderAltOrOptlKey()}+↓`"
:last-page-tooltip="`${renderAltOrOptlKey()}+↑`"
@update:current="loadAudits(undefined, undefined, false)"
@update:page-size="loadAudits(currentPage, $event, false)"
/>
<div class="text-gray-500 text-xs">
{{ auditPaginationData.totalRows }} {{ auditPaginationData.totalRows === 1 ? 'record' : 'records' }}

2
packages/nc-gui/composables/usePaginationShortcuts.ts

@ -4,7 +4,7 @@ import type { PaginatedType } from 'nocodb-sdk'
const usePaginationShortcuts = ({
changePage,
paginationDataRef,
isViewDataLoading
isViewDataLoading,
}: {
changePage: (page: number) => Promise<void> | undefined
paginationDataRef: Ref<PaginatedType | undefined>

4
packages/nc-gui/store/views.ts

@ -425,8 +425,8 @@ export const useViewsStore = defineStore('viewsStore', () => {
updateTabTitle()
},
{
flush:'post'
}
flush: 'post',
},
)
return {

10
packages/nc-gui/utils/baseCreateUtils.ts

@ -1,3 +1,4 @@
import { SSLUsage } from 'nocodb-sdk'
import { ClientType } from '~/lib/enums'
// todo: move to noco-sdk
@ -219,15 +220,6 @@ export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateFor
}
}
enum SSLUsage {
No = 'No',
Allowed = 'Allowed',
Preferred = 'Preferred',
Required = 'Required',
RequiredWithCa = 'Required-CA',
RequiredWithIdentity = 'Required-Identity',
}
enum CertTypes {
ca = 'ca',
cert = 'cert',

33
packages/nocodb-sdk/src/lib/connectionConfigUtils.ts

@ -0,0 +1,33 @@
import { SSLUsage } from '~/lib/enums';
export const validateAndExtractSSLProp = (
connectionConfig: any,
sslUse: SSLUsage = SSLUsage.No,
client: string
) => {
if ('ssl' in connectionConfig && connectionConfig.ssl) {
if (
sslUse === SSLUsage.No ||
(typeof connectionConfig.ssl === 'object' &&
Object.values(connectionConfig.ssl).every(
(v) => v === null || v === undefined
))
) {
return undefined;
}
// if postgres then only allow boolean or object
else if (
client === 'pg' &&
['true', 'false'].includes(connectionConfig.ssl)
) {
return connectionConfig.ssl === 'true';
} else if (
client === 'pg' &&
!['boolean', 'object'].includes(typeof connectionConfig.ssl)
) {
return undefined;
}
return connectionConfig.ssl;
}
};

10
packages/nocodb-sdk/src/lib/enums.ts

@ -327,10 +327,16 @@ export enum APIContext {
SORTS = 'sorts',
}
export enum SourceRestriction {
SCHEMA_READONLY = 'is_schema_readonly',
DATA_READONLY = 'is_data_readonly',
}
export enum SSLUsage {
No = 'No',
Allowed = 'Allowed',
Preferred = 'Preferred',
Required = 'Required',
RequiredWithCa = 'Required-CA',
RequiredWithIdentity = 'Required-Identity',
}

1
packages/nocodb-sdk/src/lib/index.ts

@ -31,3 +31,4 @@ export * from '~/lib/mergeSwaggerSchema';
export * from '~/lib/dateTimeHelper';
export * from '~/lib/form';
export * from '~/lib/aggregationHelper';
export * from '~/lib/connectionConfigUtils';

7
packages/nocodb/src/controllers/utils.controller.ts

@ -9,6 +9,7 @@ import {
Req,
UseGuards,
} from '@nestjs/common';
import { validateAndExtractSSLProp } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { UtilsService } from '~/services/utils.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
@ -55,6 +56,12 @@ export class UtilsController {
max: 1,
};
body.connection.ssl = validateAndExtractSSLProp(
body.connection,
body.sslUse,
body.client,
);
return await this.utilsService.testConnection({ body });
}

11
packages/nocodb/src/services/sources.service.ts

@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { AppEvents } from 'nocodb-sdk';
import { AppEvents, validateAndExtractSSLProp } from 'nocodb-sdk';
import type { BaseReqType } from 'nocodb-sdk';
import type { NcContext, NcRequest } from '~/interface/config';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
@ -101,6 +101,15 @@ export class SourcesService {
param.logger?.('Creating the source');
// update invalid ssl config value if found
if (baseBody.config?.connection?.ssl) {
baseBody.config.connection.ssl = validateAndExtractSSLProp(
baseBody.config.connection,
baseBody.config.sslUse,
baseBody.config.client,
);
}
const source = await Source.createBase(context, {
...baseBody,
type: baseBody.config?.client,

Loading…
Cancel
Save