Add ntml config
This commit is contained in:
parent
00fff6eded
commit
c4fec6973f
|
@ -27,12 +27,14 @@ const DEFAULT_SCHEMA = "dbo"
|
||||||
|
|
||||||
import { ConfidentialClientApplication } from "@azure/msal-node"
|
import { ConfidentialClientApplication } from "@azure/msal-node"
|
||||||
|
|
||||||
|
import { utils } from "@budibase/shared-core"
|
||||||
|
|
||||||
enum MSSQLConfigAuthType {
|
enum MSSQLConfigAuthType {
|
||||||
AZURE_ACTIVE_DIRECTORY = "Azure Active Directory",
|
AZURE_ACTIVE_DIRECTORY = "Azure Active Directory",
|
||||||
LOCAL_ACTIVE_DIRECTORY = "Local Active Directory",
|
LOCAL_ACTIVE_DIRECTORY = "Local Active Directory",
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MSSQLConfig {
|
interface BasicMSSQLConfig {
|
||||||
user: string
|
user: string
|
||||||
password: string
|
password: string
|
||||||
server: string
|
server: string
|
||||||
|
@ -41,13 +43,30 @@ interface MSSQLConfig {
|
||||||
schema: string
|
schema: string
|
||||||
encrypt?: boolean
|
encrypt?: boolean
|
||||||
authType?: MSSQLConfigAuthType
|
authType?: MSSQLConfigAuthType
|
||||||
adConfig?: {
|
}
|
||||||
|
|
||||||
|
interface AzureADMSSQLConfig extends BasicMSSQLConfig {
|
||||||
|
authType: MSSQLConfigAuthType.AZURE_ACTIVE_DIRECTORY
|
||||||
|
adConfig: {
|
||||||
clientId: string
|
clientId: string
|
||||||
clientSecret: string
|
clientSecret: string
|
||||||
tenantId: string
|
tenantId: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LocalADMSSQLConfig extends BasicMSSQLConfig {
|
||||||
|
authType: MSSQLConfigAuthType.LOCAL_ACTIVE_DIRECTORY
|
||||||
|
localADConfig: {
|
||||||
|
domain: string
|
||||||
|
trustServerCertificate: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MSSQLConfig =
|
||||||
|
| (BasicMSSQLConfig & { authType: undefined })
|
||||||
|
| AzureADMSSQLConfig
|
||||||
|
| LocalADMSSQLConfig
|
||||||
|
|
||||||
const SCHEMA: Integration = {
|
const SCHEMA: Integration = {
|
||||||
docs: "https://github.com/tediousjs/node-mssql",
|
docs: "https://github.com/tediousjs/node-mssql",
|
||||||
plus: true,
|
plus: true,
|
||||||
|
@ -128,6 +147,28 @@ const SCHEMA: Integration = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
localADConfig: {
|
||||||
|
type: DatasourceFieldType.FIELD_GROUP,
|
||||||
|
default: true,
|
||||||
|
display: "Configure Local Active Directory",
|
||||||
|
hidden: `'{{authType}}' !== '${MSSQLConfigAuthType.LOCAL_ACTIVE_DIRECTORY}'`,
|
||||||
|
config: {
|
||||||
|
openByDefault: true,
|
||||||
|
nestedFields: true,
|
||||||
|
},
|
||||||
|
fields: {
|
||||||
|
domain: {
|
||||||
|
type: DatasourceFieldType.STRING,
|
||||||
|
required: true,
|
||||||
|
display: "Domain",
|
||||||
|
},
|
||||||
|
trustServerCertificate: {
|
||||||
|
type: DatasourceFieldType.BOOLEAN,
|
||||||
|
required: true,
|
||||||
|
display: "Trust server certificate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
create: {
|
create: {
|
||||||
|
@ -205,26 +246,43 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
delete clientCfg.encrypt
|
delete clientCfg.encrypt
|
||||||
|
|
||||||
if (this.config.authType === MSSQLConfigAuthType.AZURE_ACTIVE_DIRECTORY) {
|
switch (this.config.authType) {
|
||||||
const { clientId, tenantId, clientSecret } = this.config.adConfig!
|
case MSSQLConfigAuthType.AZURE_ACTIVE_DIRECTORY:
|
||||||
const clientApp = new ConfidentialClientApplication({
|
const { clientId, tenantId, clientSecret } = this.config.adConfig
|
||||||
auth: {
|
const clientApp = new ConfidentialClientApplication({
|
||||||
clientId,
|
auth: {
|
||||||
authority: `https://login.microsoftonline.com/${tenantId}`,
|
clientId,
|
||||||
clientSecret,
|
authority: `https://login.microsoftonline.com/${tenantId}`,
|
||||||
},
|
clientSecret,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const response = await clientApp.acquireTokenByClientCredential({
|
const response = await clientApp.acquireTokenByClientCredential({
|
||||||
scopes: ["https://database.windows.net/.default"],
|
scopes: ["https://database.windows.net/.default"],
|
||||||
})
|
})
|
||||||
|
|
||||||
clientCfg.authentication = {
|
clientCfg.authentication = {
|
||||||
type: "azure-active-directory-access-token",
|
type: "azure-active-directory-access-token",
|
||||||
options: {
|
options: {
|
||||||
token: response!.accessToken,
|
token: response!.accessToken,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
case MSSQLConfigAuthType.LOCAL_ACTIVE_DIRECTORY:
|
||||||
|
const { domain, trustServerCertificate } = this.config.localADConfig
|
||||||
|
clientCfg.authentication = {
|
||||||
|
type: "ntml",
|
||||||
|
options: {
|
||||||
|
domain,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
clientCfg.options ??= {}
|
||||||
|
clientCfg.options.trustServerCertificate = trustServerCertificate
|
||||||
|
break
|
||||||
|
case undefined:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
utils.unreachable(this.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
const pool = new sqlServer.ConnectionPool(clientCfg)
|
const pool = new sqlServer.ConnectionPool(clientCfg)
|
||||||
|
|
Loading…
Reference in New Issue