@onivoro/server-aws-redshift 22.0.6 → 22.0.8

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.
@@ -14,7 +14,9 @@ const client_redshift_data_1 = require("@aws-sdk/client-redshift-data");
14
14
  const redshift_service_1 = require("./services/redshift.service");
15
15
  const server_aws_redshift_config_class_1 = require("./classes/server-aws-redshift-config.class");
16
16
  const client_redshift_serverless_1 = require("@aws-sdk/client-redshift-serverless");
17
+ const client_redshift_1 = require("@aws-sdk/client-redshift");
17
18
  let redshiftClient = null;
19
+ let redshiftDataClient = null;
18
20
  let redshiftServerlessClient = null;
19
21
  let ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = class ServerAwsRedshiftDataModule {
20
22
  static configure(config) {
@@ -23,33 +25,21 @@ let ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = class ServerAw
23
25
  providers: [
24
26
  {
25
27
  provide: client_redshift_data_1.RedshiftDataClient,
26
- useFactory: () => redshiftClient
27
- ? redshiftClient
28
- : redshiftClient = new client_redshift_data_1.RedshiftDataClient({
29
- region: config.AWS_REGION,
30
- logger: console,
31
- credentials: config.NODE_ENV === 'production'
32
- ? undefined
33
- : {
34
- accessKeyId: config.AWS_ACCESS_KEY_ID,
35
- secretAccessKey: config.AWS_SECRET_ACCESS_KEY
36
- }
37
- })
28
+ useFactory: () => redshiftDataClient
29
+ ? redshiftDataClient
30
+ : redshiftDataClient = new client_redshift_data_1.RedshiftDataClient(from(config))
38
31
  },
39
32
  {
40
33
  provide: client_redshift_serverless_1.RedshiftServerlessClient,
41
- useFactory: () => redshiftClient
34
+ useFactory: () => redshiftServerlessClient
42
35
  ? redshiftServerlessClient
43
- : redshiftServerlessClient = new client_redshift_serverless_1.RedshiftServerlessClient({
44
- region: config.AWS_REGION,
45
- logger: console,
46
- credentials: config.NODE_ENV === 'production'
47
- ? undefined
48
- : {
49
- accessKeyId: config.AWS_ACCESS_KEY_ID,
50
- secretAccessKey: config.AWS_SECRET_ACCESS_KEY
51
- }
52
- })
36
+ : redshiftServerlessClient = new client_redshift_serverless_1.RedshiftServerlessClient(from(config))
37
+ },
38
+ {
39
+ provide: client_redshift_1.RedshiftClient,
40
+ useFactory: () => redshiftClient
41
+ ? redshiftClient
42
+ : redshiftClient = new client_redshift_1.RedshiftClient(from(config))
53
43
  },
54
44
  { provide: server_aws_redshift_config_class_1.ServerAwsRedshiftDataConfig, useValue: config },
55
45
  redshift_service_1.RedshiftDataService
@@ -61,3 +51,15 @@ exports.ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule;
61
51
  exports.ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = __decorate([
62
52
  (0, common_1.Module)({})
63
53
  ], ServerAwsRedshiftDataModule);
54
+ function from(config) {
55
+ return {
56
+ region: config.AWS_REGION,
57
+ logger: console,
58
+ credentials: config.NODE_ENV === 'production'
59
+ ? undefined
60
+ : {
61
+ accessKeyId: config.AWS_ACCESS_KEY_ID,
62
+ secretAccessKey: config.AWS_SECRET_ACCESS_KEY
63
+ }
64
+ };
65
+ }
@@ -36,4 +36,8 @@ export declare class RedshiftDataService {
36
36
  database: string;
37
37
  workgroupName: string;
38
38
  }, Sql: string): Promise<(string | number)[][]>;
39
+ getAssociatedIAmRolesByWorkgroup(_: {
40
+ database: string;
41
+ workgroupName: string;
42
+ }): Promise<(string | number)[][]>;
39
43
  }
@@ -193,6 +193,35 @@ let RedshiftDataService = class RedshiftDataService {
193
193
  throw error;
194
194
  }
195
195
  }
196
+ async getAssociatedIAmRolesByWorkgroup(_) {
197
+ try {
198
+ const query = `
199
+ SELECT
200
+ g.groname as role_name,
201
+ u.usename as member_name,
202
+ g.grosysid as role_id,
203
+ g.groowner as owner_id,
204
+ CASE WHEN pg_has_role(u.usename, g.groname, 'MEMBER') THEN true ELSE false END as is_member
205
+ FROM pg_group g
206
+ LEFT JOIN pg_user u ON u.usesysid = ANY(g.grolist)
207
+ WHERE EXISTS (
208
+ SELECT 1
209
+ FROM svv_redshift_databases d
210
+ WHERE d.database_name = current_database()
211
+ AND d.workgroup_name = $1
212
+ )
213
+ ORDER BY g.groname, u.usename;
214
+ `;
215
+ return await this.query(_, query);
216
+ }
217
+ catch (error) {
218
+ if (error instanceof Error) {
219
+ console.error(`Error getting workgroup roles: ${error.message}`);
220
+ throw error;
221
+ }
222
+ throw new Error('An unknown error occurred');
223
+ }
224
+ }
196
225
  };
197
226
  exports.RedshiftDataService = RedshiftDataService;
198
227
  exports.RedshiftDataService = RedshiftDataService = __decorate([
@@ -14,7 +14,9 @@ const client_redshift_data_1 = require("@aws-sdk/client-redshift-data");
14
14
  const redshift_service_1 = require("./services/redshift.service");
15
15
  const server_aws_redshift_config_class_1 = require("./classes/server-aws-redshift-config.class");
16
16
  const client_redshift_serverless_1 = require("@aws-sdk/client-redshift-serverless");
17
+ const client_redshift_1 = require("@aws-sdk/client-redshift");
17
18
  let redshiftClient = null;
19
+ let redshiftDataClient = null;
18
20
  let redshiftServerlessClient = null;
19
21
  let ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = class ServerAwsRedshiftDataModule {
20
22
  static configure(config) {
@@ -23,33 +25,21 @@ let ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = class ServerAw
23
25
  providers: [
24
26
  {
25
27
  provide: client_redshift_data_1.RedshiftDataClient,
26
- useFactory: () => redshiftClient
27
- ? redshiftClient
28
- : redshiftClient = new client_redshift_data_1.RedshiftDataClient({
29
- region: config.AWS_REGION,
30
- logger: console,
31
- credentials: config.NODE_ENV === 'production'
32
- ? undefined
33
- : {
34
- accessKeyId: config.AWS_ACCESS_KEY_ID,
35
- secretAccessKey: config.AWS_SECRET_ACCESS_KEY
36
- }
37
- })
28
+ useFactory: () => redshiftDataClient
29
+ ? redshiftDataClient
30
+ : redshiftDataClient = new client_redshift_data_1.RedshiftDataClient(from(config))
38
31
  },
39
32
  {
40
33
  provide: client_redshift_serverless_1.RedshiftServerlessClient,
41
- useFactory: () => redshiftClient
34
+ useFactory: () => redshiftServerlessClient
42
35
  ? redshiftServerlessClient
43
- : redshiftServerlessClient = new client_redshift_serverless_1.RedshiftServerlessClient({
44
- region: config.AWS_REGION,
45
- logger: console,
46
- credentials: config.NODE_ENV === 'production'
47
- ? undefined
48
- : {
49
- accessKeyId: config.AWS_ACCESS_KEY_ID,
50
- secretAccessKey: config.AWS_SECRET_ACCESS_KEY
51
- }
52
- })
36
+ : redshiftServerlessClient = new client_redshift_serverless_1.RedshiftServerlessClient(from(config))
37
+ },
38
+ {
39
+ provide: client_redshift_1.RedshiftClient,
40
+ useFactory: () => redshiftClient
41
+ ? redshiftClient
42
+ : redshiftClient = new client_redshift_1.RedshiftClient(from(config))
53
43
  },
54
44
  { provide: server_aws_redshift_config_class_1.ServerAwsRedshiftDataConfig, useValue: config },
55
45
  redshift_service_1.RedshiftDataService
@@ -61,3 +51,15 @@ exports.ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule;
61
51
  exports.ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule = ServerAwsRedshiftDataModule_1 = __decorate([
62
52
  (0, common_1.Module)({})
63
53
  ], ServerAwsRedshiftDataModule);
54
+ function from(config) {
55
+ return {
56
+ region: config.AWS_REGION,
57
+ logger: console,
58
+ credentials: config.NODE_ENV === 'production'
59
+ ? undefined
60
+ : {
61
+ accessKeyId: config.AWS_ACCESS_KEY_ID,
62
+ secretAccessKey: config.AWS_SECRET_ACCESS_KEY
63
+ }
64
+ };
65
+ }
@@ -36,4 +36,8 @@ export declare class RedshiftDataService {
36
36
  database: string;
37
37
  workgroupName: string;
38
38
  }, Sql: string): Promise<(string | number)[][]>;
39
+ getAssociatedIAmRolesByWorkgroup(_: {
40
+ database: string;
41
+ workgroupName: string;
42
+ }): Promise<(string | number)[][]>;
39
43
  }
@@ -193,6 +193,35 @@ let RedshiftDataService = class RedshiftDataService {
193
193
  throw error;
194
194
  }
195
195
  }
196
+ async getAssociatedIAmRolesByWorkgroup(_) {
197
+ try {
198
+ const query = `
199
+ SELECT
200
+ g.groname as role_name,
201
+ u.usename as member_name,
202
+ g.grosysid as role_id,
203
+ g.groowner as owner_id,
204
+ CASE WHEN pg_has_role(u.usename, g.groname, 'MEMBER') THEN true ELSE false END as is_member
205
+ FROM pg_group g
206
+ LEFT JOIN pg_user u ON u.usesysid = ANY(g.grolist)
207
+ WHERE EXISTS (
208
+ SELECT 1
209
+ FROM svv_redshift_databases d
210
+ WHERE d.database_name = current_database()
211
+ AND d.workgroup_name = $1
212
+ )
213
+ ORDER BY g.groname, u.usename;
214
+ `;
215
+ return await this.query(_, query);
216
+ }
217
+ catch (error) {
218
+ if (error instanceof Error) {
219
+ console.error(`Error getting workgroup roles: ${error.message}`);
220
+ throw error;
221
+ }
222
+ throw new Error('An unknown error occurred');
223
+ }
224
+ }
196
225
  };
197
226
  exports.RedshiftDataService = RedshiftDataService;
198
227
  exports.RedshiftDataService = RedshiftDataService = __decorate([
@@ -36,4 +36,8 @@ export declare class RedshiftDataService {
36
36
  database: string;
37
37
  workgroupName: string;
38
38
  }, Sql: string): Promise<(string | number)[][]>;
39
+ getAssociatedIAmRolesByWorkgroup(_: {
40
+ database: string;
41
+ workgroupName: string;
42
+ }): Promise<(string | number)[][]>;
39
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-aws-redshift",
3
- "version": "22.0.6",
3
+ "version": "22.0.8",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-aws-redshift.git"
6
6
  },