@lightdash/cli 0.2258.1 → 0.2259.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createProject.d.ts","sourceRoot":"","sources":["../../src/handlers/createProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,+BAA+B,EAE/B,WAAW,EAEX,KAAK,uBAAuB,EAG/B,MAAM,mBAAmB,CAAC;AA2D3B,eAAO,MAAM,kCAAkC,SACrC,MAAM,KACb,OAAO,CAAC,MAAM,CAyChB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,+BAA+B,CAAC;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,aAAa,YACb,oBAAoB,KAC9B,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAkI7C,CAAC"}
1
+ {"version":3,"file":"createProject.d.ts","sourceRoot":"","sources":["../../src/handlers/createProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,+BAA+B,EAG/B,WAAW,EAGX,KAAK,uBAAuB,EAG/B,MAAM,mBAAmB,CAAC;AA6D3B,eAAO,MAAM,kCAAkC,SACrC,MAAM,KACb,OAAO,CAAC,MAAM,CAyChB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,+BAA+B,CAAC;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAYF,eAAO,MAAM,aAAa,YACb,oBAAoB,KAC9B,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAuK7C,CAAC"}
@@ -13,7 +13,7 @@ const styles = tslib_1.__importStar(require("../styles"));
13
13
  const apiClient_1 = require("./dbt/apiClient");
14
14
  const getDbtProfileTargetName_1 = tslib_1.__importDefault(require("./dbt/getDbtProfileTargetName"));
15
15
  const getDbtVersion_1 = require("./dbt/getDbtVersion");
16
- const getWarehouseClient_1 = tslib_1.__importDefault(require("./dbt/getWarehouseClient"));
16
+ const getWarehouseClient_1 = tslib_1.__importStar(require("./dbt/getWarehouseClient"));
17
17
  const askToRememberAnswer = async () => {
18
18
  const answers = await inquirer_1.default.prompt([
19
19
  {
@@ -84,6 +84,14 @@ const resolveOrganizationCredentialsName = async (name) => {
84
84
  }
85
85
  };
86
86
  exports.resolveOrganizationCredentialsName = resolveOrganizationCredentialsName;
87
+ const isSnowflakeSsoEnabled = async () => {
88
+ const response = await (0, apiClient_1.lightdashApi)({
89
+ method: 'GET',
90
+ url: `/api/v1/health`,
91
+ body: undefined,
92
+ });
93
+ return response?.auth?.snowflake?.enabled ?? false;
94
+ };
87
95
  const createProject = async (options) => {
88
96
  await (0, apiClient_1.checkProjectCreationPermission)(options.upstreamProjectUuid, options.type);
89
97
  // Resolve organization credentials early before doing any heavy work
@@ -160,6 +168,30 @@ const createProject = async (options) => {
160
168
  }
161
169
  spinner?.start();
162
170
  }
171
+ if (credentials?.type === common_1.WarehouseTypes.SNOWFLAKE &&
172
+ credentials?.authenticationType ===
173
+ common_1.SnowflakeAuthenticationType.EXTERNAL_BROWSER) {
174
+ const snowflakeSsoEnabled = await isSnowflakeSsoEnabled();
175
+ if (snowflakeSsoEnabled) {
176
+ console.error(styles.info(`\nLightdash server has Snowflake OAuth authentication enabled.
177
+ We will ask for user credentials again on the Lightdash UI.\n`));
178
+ credentials = {
179
+ ...credentials,
180
+ requireUserCredentials: true,
181
+ };
182
+ }
183
+ else {
184
+ console.error(styles.warning(`\nUser has externalbrowser snowflake authentication.
185
+ We will generate programatically a temporary PAT to enable access on Lightdash which expires in 1 day.
186
+ For a better user experience, we recommend enabling Snowflake OAuth authentication on the server.\n`));
187
+ const patToken = await (0, getWarehouseClient_1.createProgramaticallySnowflakePat)(credentials);
188
+ credentials = {
189
+ ...credentials,
190
+ authenticationType: common_1.SnowflakeAuthenticationType.PASSWORD,
191
+ password: patToken,
192
+ };
193
+ }
194
+ }
163
195
  const project = {
164
196
  name: options.name,
165
197
  type: options.type,
@@ -1,4 +1,4 @@
1
- import { CreateWarehouseCredentials, WarehouseTableSchema } from '@lightdash/common';
1
+ import { CreateSnowflakeCredentials, CreateWarehouseCredentials, WarehouseTableSchema } from '@lightdash/common';
2
2
  import { warehouseClientFromCredentials } from '@lightdash/warehouses';
3
3
  type GetTableCatalogProps = {
4
4
  projectUuid: string;
@@ -14,6 +14,7 @@ type GetWarehouseClientOptions = {
14
14
  target?: string;
15
15
  startOfWeek?: number;
16
16
  };
17
+ export declare const createProgramaticallySnowflakePat: (credentials: CreateSnowflakeCredentials) => Promise<string>;
17
18
  type GetWarehouseClientReturn = {
18
19
  warehouseClient: ReturnType<typeof warehouseClientFromCredentials>;
19
20
  credentials: CreateWarehouseCredentials;
@@ -1 +1 @@
1
- {"version":3,"file":"getWarehouseClient.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getWarehouseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,0BAA0B,EAQ1B,oBAAoB,EAEvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEH,8BAA8B,EACjC,MAAM,uBAAuB,CAAC;AAwC/B,KAAK,oBAAoB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,cAAc,0DAKxB,oBAAoB,kCAKjB,CAAC;AA8HP,KAAK,yBAAyB,GAAG;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC5B,eAAe,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC;IACnE,WAAW,EAAE,0BAA0B,CAAC;CAC3C,CAAC;AAEF,wBAA8B,kBAAkB,CAC5C,OAAO,EAAE,yBAAyB,GACnC,OAAO,CAAC,wBAAwB,CAAC,CA+KnC"}
1
+ {"version":3,"file":"getWarehouseClient.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getWarehouseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,0BAA0B,EAC1B,0BAA0B,EAQ1B,oBAAoB,EAEvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGH,8BAA8B,EACjC,MAAM,uBAAuB,CAAC;AAwC/B,KAAK,oBAAoB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,cAAc,0DAKxB,oBAAoB,kCAKjB,CAAC;AA8HP,KAAK,yBAAyB,GAAG;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AASF,eAAO,MAAM,iCAAiC,gBAC7B,0BAA0B,KACxC,OAAO,CAAC,MAAM,CAwBhB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC5B,eAAe,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC;IACnE,WAAW,EAAE,0BAA0B,CAAC;CAC3C,CAAC;AAEF,wBAA8B,kBAAkB,CAC5C,OAAO,EAAE,yBAAyB,GACnC,OAAO,CAAC,wBAAwB,CAAC,CA+KnC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTableSchema = void 0;
3
+ exports.createProgramaticallySnowflakePat = exports.getTableSchema = void 0;
4
4
  exports.default = getWarehouseClient;
5
5
  const tslib_1 = require("tslib");
6
6
  const common_1 = require("@lightdash/common");
@@ -149,6 +149,30 @@ function getMockCredentials(dbtAdaptorType) {
149
149
  }
150
150
  return credentials;
151
151
  }
152
+ /*
153
+ Generates a temporary Snowflake PAT to enable access on Lightdash which expires in 1 day.
154
+ Snowflake PAT limitations and error messages:
155
+ - 15 PATs per user: Exceeded maximum of 15 programmatic access tokens.
156
+ - Must be unique: Programmatic access token LIGHTDASH_CLI already exists.
157
+ - Can't include "-" in the name : SQL compilation error: syntax error line 1 at position 37 unexpected '-'
158
+ */
159
+ const createProgramaticallySnowflakePat = async (credentials) => {
160
+ const tempClient = new warehouses_1.SnowflakeWarehouseClient({
161
+ ...credentials,
162
+ });
163
+ try {
164
+ console.error(`\n- Creating Snowflake Programmatic Access Token\n`);
165
+ const { tokenSecret, tokenName } = await tempClient.createProgrammaticAccessToken(`lightdash_cli_${Date.now()}`, 1);
166
+ console.error(`\n✓ Successfully created Snowflake PAT: ${tokenName}\n`);
167
+ return tokenSecret;
168
+ }
169
+ catch (e) {
170
+ console.error(styles.error(`\nFailed to create Snowflake PAT: ${(0, common_1.getErrorMessage)(e)}`));
171
+ process.exit(1);
172
+ }
173
+ return '';
174
+ };
175
+ exports.createProgramaticallySnowflakePat = createProgramaticallySnowflakePat;
152
176
  async function getWarehouseClient(options) {
153
177
  let warehouseClient;
154
178
  let credentials;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "0.2258.1",
3
+ "version": "0.2259.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,8 +38,8 @@
38
38
  "unique-names-generator": "^4.7.1",
39
39
  "uuid": "^11.0.3",
40
40
  "yaml": "^2.7.0",
41
- "@lightdash/common": "0.2258.1",
42
- "@lightdash/warehouses": "0.2258.1"
41
+ "@lightdash/warehouses": "0.2259.1",
42
+ "@lightdash/common": "0.2259.1"
43
43
  },
44
44
  "description": "Lightdash CLI tool",
45
45
  "devDependencies": {