@onivoro/server-aws-redshift 22.0.1 → 22.0.3
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.
- package/dist/cjs/lib/services/redshift.service.d.ts +20 -23
- package/dist/cjs/lib/services/redshift.service.js +41 -70
- package/dist/esm/lib/services/redshift.service.d.ts +20 -23
- package/dist/esm/lib/services/redshift.service.js +41 -70
- package/dist/types/lib/services/redshift.service.d.ts +20 -23
- package/package.json +1 -1
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { RedshiftDataClient } from "@aws-sdk/client-redshift-data";
|
|
2
|
-
import { ServerAwsRedshiftDataConfig } from '../classes/server-aws-redshift-config.class';
|
|
3
2
|
import { RedshiftServerlessClient } from '@aws-sdk/client-redshift-serverless';
|
|
4
3
|
export declare class RedshiftDataService {
|
|
5
4
|
private redshiftDataClient;
|
|
6
5
|
private redshiftServerlessClient;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
waitForStatement(statementId: string): Promise<void>;
|
|
6
|
+
constructor(redshiftDataClient: RedshiftDataClient, redshiftServerlessClient: RedshiftServerlessClient);
|
|
7
|
+
waitForStatement(statementId: string, maxAttempts?: number, delay?: number): Promise<void>;
|
|
10
8
|
verifyEndpointAccess(workgroupName: string): Promise<import("@aws-sdk/client-redshift-serverless").GetWorkgroupCommandOutput>;
|
|
11
|
-
addIamUserToDatabaseGroup(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
addIamUserToDatabaseGroup(_: {
|
|
10
|
+
database: string;
|
|
11
|
+
workgroupName: string;
|
|
12
|
+
user: string;
|
|
13
|
+
group: string;
|
|
16
14
|
}): Promise<void>;
|
|
17
|
-
createDatabaseUser(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): Promise<
|
|
22
|
-
grantUsageOnSchema(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Group: string;
|
|
15
|
+
createDatabaseUser(_: {
|
|
16
|
+
database: string;
|
|
17
|
+
workgroupName: string;
|
|
18
|
+
user: string;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
grantUsageOnSchema(_: {
|
|
21
|
+
database: string;
|
|
22
|
+
workgroupName: string;
|
|
23
|
+
schema: string;
|
|
24
|
+
group: string;
|
|
28
25
|
}): Promise<void>;
|
|
29
|
-
createDbGroupFromIamGroupIfNotExists(
|
|
26
|
+
createDbGroupFromIamGroupIfNotExists(_: {
|
|
30
27
|
iamGroup: string;
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
database: string;
|
|
29
|
+
workgroupName: string;
|
|
33
30
|
}): Promise<any>;
|
|
34
31
|
}
|
|
@@ -12,20 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.RedshiftDataService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const client_redshift_data_1 = require("@aws-sdk/client-redshift-data");
|
|
15
|
-
const server_aws_redshift_config_class_1 = require("../classes/server-aws-redshift-config.class");
|
|
16
15
|
const client_redshift_serverless_1 = require("@aws-sdk/client-redshift-serverless");
|
|
17
16
|
const crypto_1 = require("crypto");
|
|
18
17
|
let RedshiftDataService = class RedshiftDataService {
|
|
19
18
|
redshiftDataClient;
|
|
20
19
|
redshiftServerlessClient;
|
|
21
|
-
|
|
22
|
-
constructor(redshiftDataClient, redshiftServerlessClient, config) {
|
|
20
|
+
constructor(redshiftDataClient, redshiftServerlessClient) {
|
|
23
21
|
this.redshiftDataClient = redshiftDataClient;
|
|
24
22
|
this.redshiftServerlessClient = redshiftServerlessClient;
|
|
25
|
-
this.config = config;
|
|
26
23
|
}
|
|
27
|
-
async waitForStatement(statementId) {
|
|
28
|
-
const maxAttempts = 10;
|
|
24
|
+
async waitForStatement(statementId, maxAttempts = 10, delay = 1000) {
|
|
29
25
|
let attempts = 0;
|
|
30
26
|
while (attempts < maxAttempts) {
|
|
31
27
|
const describeStatementCommand = new client_redshift_data_1.DescribeStatementCommand({
|
|
@@ -39,40 +35,38 @@ let RedshiftDataService = class RedshiftDataService {
|
|
|
39
35
|
throw new Error(`SQL statement failed: ${status.Error}`);
|
|
40
36
|
}
|
|
41
37
|
attempts++;
|
|
42
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
38
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
43
39
|
}
|
|
44
40
|
throw new Error('Timeout waiting for SQL statement to complete');
|
|
45
41
|
}
|
|
46
42
|
async verifyEndpointAccess(workgroupName) {
|
|
47
43
|
const workgroupResponse = await this.redshiftServerlessClient.send(new client_redshift_serverless_1.GetWorkgroupCommand({ workgroupName }));
|
|
48
44
|
if (!workgroupResponse?.workgroup?.endpoint?.address) {
|
|
49
|
-
console.error(`Could not retrieve endpoint for
|
|
45
|
+
console.error(`Could not retrieve endpoint for workgroupName "${workgroupName}"`);
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
52
48
|
return workgroupResponse;
|
|
53
49
|
}
|
|
54
|
-
async addIamUserToDatabaseGroup(
|
|
55
|
-
const { Database, WorkgroupName, User, Group } = params;
|
|
50
|
+
async addIamUserToDatabaseGroup(_) {
|
|
56
51
|
try {
|
|
57
52
|
const groupResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
58
|
-
Database,
|
|
59
|
-
Sql: `ALTER GROUP ${
|
|
60
|
-
WorkgroupName
|
|
53
|
+
Database: _.database,
|
|
54
|
+
Sql: `ALTER GROUP ${_.group} ADD USER "${_.user}";`,
|
|
55
|
+
WorkgroupName: _.workgroupName
|
|
61
56
|
}));
|
|
62
57
|
await this.waitForStatement(groupResult.Id);
|
|
63
|
-
console.log(`Added user "${
|
|
58
|
+
console.log(`Added user "${_.user}" to group "${_.group}`);
|
|
64
59
|
}
|
|
65
60
|
catch (error) {
|
|
66
|
-
console.warn({ detail: `Warning adding ${
|
|
61
|
+
console.warn({ detail: `Warning adding ${_.user} to group:`, error });
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
async createDatabaseUser(
|
|
70
|
-
const { Database, WorkgroupName, User } = params;
|
|
64
|
+
async createDatabaseUser(_) {
|
|
71
65
|
try {
|
|
72
66
|
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
73
|
-
Database,
|
|
67
|
+
Database: _.database,
|
|
74
68
|
Sql: `SELECT u.usename as username FROM pg_user u;`,
|
|
75
|
-
WorkgroupName
|
|
69
|
+
WorkgroupName: _.workgroupName
|
|
76
70
|
}));
|
|
77
71
|
await this.waitForStatement(checkResult.Id);
|
|
78
72
|
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
@@ -80,97 +74,75 @@ let RedshiftDataService = class RedshiftDataService {
|
|
|
80
74
|
if (!checkStatus.ResultRows) {
|
|
81
75
|
const placeholderPassword = `IAM_${(0, crypto_1.randomUUID)().replace(/-/g, '_')}`;
|
|
82
76
|
const createUserCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
83
|
-
Database,
|
|
84
|
-
Sql: `CREATE USER ${
|
|
85
|
-
WorkgroupName
|
|
77
|
+
Database: _.database,
|
|
78
|
+
Sql: `CREATE USER ${_.user} PASSWORD '${placeholderPassword}';`,
|
|
79
|
+
WorkgroupName: _.workgroupName
|
|
86
80
|
});
|
|
87
81
|
const createResult = await this.redshiftDataClient.send(createUserCommand);
|
|
88
82
|
await this.waitForStatement(createResult.Id);
|
|
89
|
-
console.log(`Created user: ${
|
|
83
|
+
console.log(`Created user: ${_.user}`);
|
|
84
|
+
return placeholderPassword;
|
|
90
85
|
}
|
|
91
86
|
else {
|
|
92
|
-
console.log(`User "${
|
|
87
|
+
console.log(`User "${_.user} already exists`);
|
|
88
|
+
return '';
|
|
93
89
|
}
|
|
94
|
-
return true;
|
|
95
90
|
}
|
|
96
91
|
catch (error) {
|
|
97
|
-
console.warn({ detail: `Warning creating user ${
|
|
98
|
-
|
|
92
|
+
console.warn({ detail: `Warning creating user ${_.user}`, error });
|
|
93
|
+
throw error;
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
|
-
async grantUsageOnSchema(
|
|
102
|
-
const { GroupName, Database, WorkgroupName, Schema, Group } = params;
|
|
96
|
+
async grantUsageOnSchema(_) {
|
|
103
97
|
try {
|
|
104
|
-
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
105
|
-
Database,
|
|
106
|
-
Sql: `SELECT 1 FROM pg_group WHERE groname = '${Group}';`,
|
|
107
|
-
WorkgroupName
|
|
108
|
-
}));
|
|
109
|
-
await this.waitForStatement(checkResult.Id);
|
|
110
|
-
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
111
|
-
const checkStatus = await this.redshiftDataClient.send(describeCommand);
|
|
112
|
-
if (!checkStatus.ResultRows) {
|
|
113
|
-
const createGroupCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
114
|
-
Database,
|
|
115
|
-
Sql: 'CREATE GROUP ${Group};',
|
|
116
|
-
WorkgroupName
|
|
117
|
-
});
|
|
118
|
-
const createResult = await this.redshiftDataClient.send(createGroupCommand);
|
|
119
|
-
await this.waitForStatement(createResult.Id);
|
|
120
|
-
console.log('Created "${Group}" group');
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
console.log('"${Group}" group already exists');
|
|
124
|
-
}
|
|
125
98
|
const setupStatements = [
|
|
126
|
-
`GRANT USAGE ON SCHEMA ${
|
|
127
|
-
`GRANT SELECT ON ALL TABLES IN SCHEMA ${
|
|
128
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${
|
|
99
|
+
`GRANT USAGE ON SCHEMA ${_.schema} TO GROUP ${_.group};`,
|
|
100
|
+
`GRANT SELECT ON ALL TABLES IN SCHEMA ${_.schema} TO GROUP ${_.group};`,
|
|
101
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${_.schema} GRANT SELECT ON TABLES TO GROUP ${_.group};`,
|
|
129
102
|
];
|
|
130
103
|
for (const Sql of setupStatements) {
|
|
131
104
|
const executeStatementCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
132
|
-
Database,
|
|
105
|
+
Database: _.database,
|
|
133
106
|
Sql,
|
|
134
|
-
WorkgroupName
|
|
107
|
+
WorkgroupName: _.workgroupName
|
|
135
108
|
});
|
|
136
109
|
try {
|
|
137
110
|
const result = await this.redshiftDataClient.send(executeStatementCommand);
|
|
138
111
|
await this.waitForStatement(result.Id);
|
|
139
|
-
console.log(
|
|
112
|
+
console.log(Sql);
|
|
140
113
|
}
|
|
141
114
|
catch (error) {
|
|
142
|
-
console.warn(
|
|
115
|
+
console.warn({ Sql, error });
|
|
143
116
|
}
|
|
144
117
|
}
|
|
145
118
|
}
|
|
146
119
|
catch (error) {
|
|
147
|
-
console.error({
|
|
120
|
+
console.error({ error });
|
|
148
121
|
throw error;
|
|
149
122
|
}
|
|
150
123
|
}
|
|
151
|
-
async createDbGroupFromIamGroupIfNotExists(
|
|
152
|
-
const { iamGroup, Database, WorkgroupName } = params;
|
|
124
|
+
async createDbGroupFromIamGroupIfNotExists(_) {
|
|
153
125
|
try {
|
|
154
126
|
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
155
|
-
Database,
|
|
156
|
-
Sql: `SELECT 1 FROM pg_group WHERE groname = '${iamGroup}';`,
|
|
157
|
-
WorkgroupName
|
|
127
|
+
Database: _.database,
|
|
128
|
+
Sql: `SELECT 1 FROM pg_group WHERE groname = '${_.iamGroup}';`,
|
|
129
|
+
WorkgroupName: _.workgroupName
|
|
158
130
|
}));
|
|
159
131
|
await this.waitForStatement(checkResult.Id);
|
|
160
132
|
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
161
133
|
const checkStatus = await this.redshiftDataClient.send(describeCommand);
|
|
162
134
|
if (!checkStatus.ResultRows) {
|
|
163
135
|
const createGroupCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
164
|
-
Database,
|
|
165
|
-
Sql: `CREATE GROUP ${iamGroup};`,
|
|
166
|
-
WorkgroupName
|
|
136
|
+
Database: _.database,
|
|
137
|
+
Sql: `CREATE GROUP ${_.iamGroup};`,
|
|
138
|
+
WorkgroupName: _.workgroupName
|
|
167
139
|
});
|
|
168
140
|
const createResult = await this.redshiftDataClient.send(createGroupCommand);
|
|
169
141
|
await this.waitForStatement(createResult.Id);
|
|
170
|
-
console.log(`Created "${iamGroup}" group`);
|
|
142
|
+
console.log(`Created "${_.iamGroup}" group`);
|
|
171
143
|
}
|
|
172
144
|
else {
|
|
173
|
-
console.log(`"${iamGroup}" group already exists`);
|
|
145
|
+
console.log(`"${_.iamGroup}" group already exists`);
|
|
174
146
|
}
|
|
175
147
|
}
|
|
176
148
|
catch (error) {
|
|
@@ -183,6 +155,5 @@ exports.RedshiftDataService = RedshiftDataService;
|
|
|
183
155
|
exports.RedshiftDataService = RedshiftDataService = __decorate([
|
|
184
156
|
(0, common_1.Injectable)(),
|
|
185
157
|
__metadata("design:paramtypes", [client_redshift_data_1.RedshiftDataClient,
|
|
186
|
-
client_redshift_serverless_1.RedshiftServerlessClient
|
|
187
|
-
server_aws_redshift_config_class_1.ServerAwsRedshiftDataConfig])
|
|
158
|
+
client_redshift_serverless_1.RedshiftServerlessClient])
|
|
188
159
|
], RedshiftDataService);
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { RedshiftDataClient } from "@aws-sdk/client-redshift-data";
|
|
2
|
-
import { ServerAwsRedshiftDataConfig } from '../classes/server-aws-redshift-config.class';
|
|
3
2
|
import { RedshiftServerlessClient } from '@aws-sdk/client-redshift-serverless';
|
|
4
3
|
export declare class RedshiftDataService {
|
|
5
4
|
private redshiftDataClient;
|
|
6
5
|
private redshiftServerlessClient;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
waitForStatement(statementId: string): Promise<void>;
|
|
6
|
+
constructor(redshiftDataClient: RedshiftDataClient, redshiftServerlessClient: RedshiftServerlessClient);
|
|
7
|
+
waitForStatement(statementId: string, maxAttempts?: number, delay?: number): Promise<void>;
|
|
10
8
|
verifyEndpointAccess(workgroupName: string): Promise<import("@aws-sdk/client-redshift-serverless").GetWorkgroupCommandOutput>;
|
|
11
|
-
addIamUserToDatabaseGroup(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
addIamUserToDatabaseGroup(_: {
|
|
10
|
+
database: string;
|
|
11
|
+
workgroupName: string;
|
|
12
|
+
user: string;
|
|
13
|
+
group: string;
|
|
16
14
|
}): Promise<void>;
|
|
17
|
-
createDatabaseUser(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): Promise<
|
|
22
|
-
grantUsageOnSchema(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Group: string;
|
|
15
|
+
createDatabaseUser(_: {
|
|
16
|
+
database: string;
|
|
17
|
+
workgroupName: string;
|
|
18
|
+
user: string;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
grantUsageOnSchema(_: {
|
|
21
|
+
database: string;
|
|
22
|
+
workgroupName: string;
|
|
23
|
+
schema: string;
|
|
24
|
+
group: string;
|
|
28
25
|
}): Promise<void>;
|
|
29
|
-
createDbGroupFromIamGroupIfNotExists(
|
|
26
|
+
createDbGroupFromIamGroupIfNotExists(_: {
|
|
30
27
|
iamGroup: string;
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
database: string;
|
|
29
|
+
workgroupName: string;
|
|
33
30
|
}): Promise<any>;
|
|
34
31
|
}
|
|
@@ -12,20 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.RedshiftDataService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const client_redshift_data_1 = require("@aws-sdk/client-redshift-data");
|
|
15
|
-
const server_aws_redshift_config_class_1 = require("../classes/server-aws-redshift-config.class");
|
|
16
15
|
const client_redshift_serverless_1 = require("@aws-sdk/client-redshift-serverless");
|
|
17
16
|
const crypto_1 = require("crypto");
|
|
18
17
|
let RedshiftDataService = class RedshiftDataService {
|
|
19
18
|
redshiftDataClient;
|
|
20
19
|
redshiftServerlessClient;
|
|
21
|
-
|
|
22
|
-
constructor(redshiftDataClient, redshiftServerlessClient, config) {
|
|
20
|
+
constructor(redshiftDataClient, redshiftServerlessClient) {
|
|
23
21
|
this.redshiftDataClient = redshiftDataClient;
|
|
24
22
|
this.redshiftServerlessClient = redshiftServerlessClient;
|
|
25
|
-
this.config = config;
|
|
26
23
|
}
|
|
27
|
-
async waitForStatement(statementId) {
|
|
28
|
-
const maxAttempts = 10;
|
|
24
|
+
async waitForStatement(statementId, maxAttempts = 10, delay = 1000) {
|
|
29
25
|
let attempts = 0;
|
|
30
26
|
while (attempts < maxAttempts) {
|
|
31
27
|
const describeStatementCommand = new client_redshift_data_1.DescribeStatementCommand({
|
|
@@ -39,40 +35,38 @@ let RedshiftDataService = class RedshiftDataService {
|
|
|
39
35
|
throw new Error(`SQL statement failed: ${status.Error}`);
|
|
40
36
|
}
|
|
41
37
|
attempts++;
|
|
42
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
38
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
43
39
|
}
|
|
44
40
|
throw new Error('Timeout waiting for SQL statement to complete');
|
|
45
41
|
}
|
|
46
42
|
async verifyEndpointAccess(workgroupName) {
|
|
47
43
|
const workgroupResponse = await this.redshiftServerlessClient.send(new client_redshift_serverless_1.GetWorkgroupCommand({ workgroupName }));
|
|
48
44
|
if (!workgroupResponse?.workgroup?.endpoint?.address) {
|
|
49
|
-
console.error(`Could not retrieve endpoint for
|
|
45
|
+
console.error(`Could not retrieve endpoint for workgroupName "${workgroupName}"`);
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
52
48
|
return workgroupResponse;
|
|
53
49
|
}
|
|
54
|
-
async addIamUserToDatabaseGroup(
|
|
55
|
-
const { Database, WorkgroupName, User, Group } = params;
|
|
50
|
+
async addIamUserToDatabaseGroup(_) {
|
|
56
51
|
try {
|
|
57
52
|
const groupResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
58
|
-
Database,
|
|
59
|
-
Sql: `ALTER GROUP ${
|
|
60
|
-
WorkgroupName
|
|
53
|
+
Database: _.database,
|
|
54
|
+
Sql: `ALTER GROUP ${_.group} ADD USER "${_.user}";`,
|
|
55
|
+
WorkgroupName: _.workgroupName
|
|
61
56
|
}));
|
|
62
57
|
await this.waitForStatement(groupResult.Id);
|
|
63
|
-
console.log(`Added user "${
|
|
58
|
+
console.log(`Added user "${_.user}" to group "${_.group}`);
|
|
64
59
|
}
|
|
65
60
|
catch (error) {
|
|
66
|
-
console.warn({ detail: `Warning adding ${
|
|
61
|
+
console.warn({ detail: `Warning adding ${_.user} to group:`, error });
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
async createDatabaseUser(
|
|
70
|
-
const { Database, WorkgroupName, User } = params;
|
|
64
|
+
async createDatabaseUser(_) {
|
|
71
65
|
try {
|
|
72
66
|
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
73
|
-
Database,
|
|
67
|
+
Database: _.database,
|
|
74
68
|
Sql: `SELECT u.usename as username FROM pg_user u;`,
|
|
75
|
-
WorkgroupName
|
|
69
|
+
WorkgroupName: _.workgroupName
|
|
76
70
|
}));
|
|
77
71
|
await this.waitForStatement(checkResult.Id);
|
|
78
72
|
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
@@ -80,97 +74,75 @@ let RedshiftDataService = class RedshiftDataService {
|
|
|
80
74
|
if (!checkStatus.ResultRows) {
|
|
81
75
|
const placeholderPassword = `IAM_${(0, crypto_1.randomUUID)().replace(/-/g, '_')}`;
|
|
82
76
|
const createUserCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
83
|
-
Database,
|
|
84
|
-
Sql: `CREATE USER ${
|
|
85
|
-
WorkgroupName
|
|
77
|
+
Database: _.database,
|
|
78
|
+
Sql: `CREATE USER ${_.user} PASSWORD '${placeholderPassword}';`,
|
|
79
|
+
WorkgroupName: _.workgroupName
|
|
86
80
|
});
|
|
87
81
|
const createResult = await this.redshiftDataClient.send(createUserCommand);
|
|
88
82
|
await this.waitForStatement(createResult.Id);
|
|
89
|
-
console.log(`Created user: ${
|
|
83
|
+
console.log(`Created user: ${_.user}`);
|
|
84
|
+
return placeholderPassword;
|
|
90
85
|
}
|
|
91
86
|
else {
|
|
92
|
-
console.log(`User "${
|
|
87
|
+
console.log(`User "${_.user} already exists`);
|
|
88
|
+
return '';
|
|
93
89
|
}
|
|
94
|
-
return true;
|
|
95
90
|
}
|
|
96
91
|
catch (error) {
|
|
97
|
-
console.warn({ detail: `Warning creating user ${
|
|
98
|
-
|
|
92
|
+
console.warn({ detail: `Warning creating user ${_.user}`, error });
|
|
93
|
+
throw error;
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
|
-
async grantUsageOnSchema(
|
|
102
|
-
const { GroupName, Database, WorkgroupName, Schema, Group } = params;
|
|
96
|
+
async grantUsageOnSchema(_) {
|
|
103
97
|
try {
|
|
104
|
-
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
105
|
-
Database,
|
|
106
|
-
Sql: `SELECT 1 FROM pg_group WHERE groname = '${Group}';`,
|
|
107
|
-
WorkgroupName
|
|
108
|
-
}));
|
|
109
|
-
await this.waitForStatement(checkResult.Id);
|
|
110
|
-
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
111
|
-
const checkStatus = await this.redshiftDataClient.send(describeCommand);
|
|
112
|
-
if (!checkStatus.ResultRows) {
|
|
113
|
-
const createGroupCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
114
|
-
Database,
|
|
115
|
-
Sql: 'CREATE GROUP ${Group};',
|
|
116
|
-
WorkgroupName
|
|
117
|
-
});
|
|
118
|
-
const createResult = await this.redshiftDataClient.send(createGroupCommand);
|
|
119
|
-
await this.waitForStatement(createResult.Id);
|
|
120
|
-
console.log('Created "${Group}" group');
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
console.log('"${Group}" group already exists');
|
|
124
|
-
}
|
|
125
98
|
const setupStatements = [
|
|
126
|
-
`GRANT USAGE ON SCHEMA ${
|
|
127
|
-
`GRANT SELECT ON ALL TABLES IN SCHEMA ${
|
|
128
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${
|
|
99
|
+
`GRANT USAGE ON SCHEMA ${_.schema} TO GROUP ${_.group};`,
|
|
100
|
+
`GRANT SELECT ON ALL TABLES IN SCHEMA ${_.schema} TO GROUP ${_.group};`,
|
|
101
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${_.schema} GRANT SELECT ON TABLES TO GROUP ${_.group};`,
|
|
129
102
|
];
|
|
130
103
|
for (const Sql of setupStatements) {
|
|
131
104
|
const executeStatementCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
132
|
-
Database,
|
|
105
|
+
Database: _.database,
|
|
133
106
|
Sql,
|
|
134
|
-
WorkgroupName
|
|
107
|
+
WorkgroupName: _.workgroupName
|
|
135
108
|
});
|
|
136
109
|
try {
|
|
137
110
|
const result = await this.redshiftDataClient.send(executeStatementCommand);
|
|
138
111
|
await this.waitForStatement(result.Id);
|
|
139
|
-
console.log(
|
|
112
|
+
console.log(Sql);
|
|
140
113
|
}
|
|
141
114
|
catch (error) {
|
|
142
|
-
console.warn(
|
|
115
|
+
console.warn({ Sql, error });
|
|
143
116
|
}
|
|
144
117
|
}
|
|
145
118
|
}
|
|
146
119
|
catch (error) {
|
|
147
|
-
console.error({
|
|
120
|
+
console.error({ error });
|
|
148
121
|
throw error;
|
|
149
122
|
}
|
|
150
123
|
}
|
|
151
|
-
async createDbGroupFromIamGroupIfNotExists(
|
|
152
|
-
const { iamGroup, Database, WorkgroupName } = params;
|
|
124
|
+
async createDbGroupFromIamGroupIfNotExists(_) {
|
|
153
125
|
try {
|
|
154
126
|
const checkResult = await this.redshiftDataClient.send(new client_redshift_data_1.ExecuteStatementCommand({
|
|
155
|
-
Database,
|
|
156
|
-
Sql: `SELECT 1 FROM pg_group WHERE groname = '${iamGroup}';`,
|
|
157
|
-
WorkgroupName
|
|
127
|
+
Database: _.database,
|
|
128
|
+
Sql: `SELECT 1 FROM pg_group WHERE groname = '${_.iamGroup}';`,
|
|
129
|
+
WorkgroupName: _.workgroupName
|
|
158
130
|
}));
|
|
159
131
|
await this.waitForStatement(checkResult.Id);
|
|
160
132
|
const describeCommand = new client_redshift_data_1.DescribeStatementCommand({ Id: checkResult.Id });
|
|
161
133
|
const checkStatus = await this.redshiftDataClient.send(describeCommand);
|
|
162
134
|
if (!checkStatus.ResultRows) {
|
|
163
135
|
const createGroupCommand = new client_redshift_data_1.ExecuteStatementCommand({
|
|
164
|
-
Database,
|
|
165
|
-
Sql: `CREATE GROUP ${iamGroup};`,
|
|
166
|
-
WorkgroupName
|
|
136
|
+
Database: _.database,
|
|
137
|
+
Sql: `CREATE GROUP ${_.iamGroup};`,
|
|
138
|
+
WorkgroupName: _.workgroupName
|
|
167
139
|
});
|
|
168
140
|
const createResult = await this.redshiftDataClient.send(createGroupCommand);
|
|
169
141
|
await this.waitForStatement(createResult.Id);
|
|
170
|
-
console.log(`Created "${iamGroup}" group`);
|
|
142
|
+
console.log(`Created "${_.iamGroup}" group`);
|
|
171
143
|
}
|
|
172
144
|
else {
|
|
173
|
-
console.log(`"${iamGroup}" group already exists`);
|
|
145
|
+
console.log(`"${_.iamGroup}" group already exists`);
|
|
174
146
|
}
|
|
175
147
|
}
|
|
176
148
|
catch (error) {
|
|
@@ -183,6 +155,5 @@ exports.RedshiftDataService = RedshiftDataService;
|
|
|
183
155
|
exports.RedshiftDataService = RedshiftDataService = __decorate([
|
|
184
156
|
(0, common_1.Injectable)(),
|
|
185
157
|
__metadata("design:paramtypes", [client_redshift_data_1.RedshiftDataClient,
|
|
186
|
-
client_redshift_serverless_1.RedshiftServerlessClient
|
|
187
|
-
server_aws_redshift_config_class_1.ServerAwsRedshiftDataConfig])
|
|
158
|
+
client_redshift_serverless_1.RedshiftServerlessClient])
|
|
188
159
|
], RedshiftDataService);
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { RedshiftDataClient } from "@aws-sdk/client-redshift-data";
|
|
2
|
-
import { ServerAwsRedshiftDataConfig } from '../classes/server-aws-redshift-config.class';
|
|
3
2
|
import { RedshiftServerlessClient } from '@aws-sdk/client-redshift-serverless';
|
|
4
3
|
export declare class RedshiftDataService {
|
|
5
4
|
private redshiftDataClient;
|
|
6
5
|
private redshiftServerlessClient;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
waitForStatement(statementId: string): Promise<void>;
|
|
6
|
+
constructor(redshiftDataClient: RedshiftDataClient, redshiftServerlessClient: RedshiftServerlessClient);
|
|
7
|
+
waitForStatement(statementId: string, maxAttempts?: number, delay?: number): Promise<void>;
|
|
10
8
|
verifyEndpointAccess(workgroupName: string): Promise<import("@aws-sdk/client-redshift-serverless").GetWorkgroupCommandOutput>;
|
|
11
|
-
addIamUserToDatabaseGroup(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
addIamUserToDatabaseGroup(_: {
|
|
10
|
+
database: string;
|
|
11
|
+
workgroupName: string;
|
|
12
|
+
user: string;
|
|
13
|
+
group: string;
|
|
16
14
|
}): Promise<void>;
|
|
17
|
-
createDatabaseUser(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): Promise<
|
|
22
|
-
grantUsageOnSchema(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Group: string;
|
|
15
|
+
createDatabaseUser(_: {
|
|
16
|
+
database: string;
|
|
17
|
+
workgroupName: string;
|
|
18
|
+
user: string;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
grantUsageOnSchema(_: {
|
|
21
|
+
database: string;
|
|
22
|
+
workgroupName: string;
|
|
23
|
+
schema: string;
|
|
24
|
+
group: string;
|
|
28
25
|
}): Promise<void>;
|
|
29
|
-
createDbGroupFromIamGroupIfNotExists(
|
|
26
|
+
createDbGroupFromIamGroupIfNotExists(_: {
|
|
30
27
|
iamGroup: string;
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
database: string;
|
|
29
|
+
workgroupName: string;
|
|
33
30
|
}): Promise<any>;
|
|
34
31
|
}
|