@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-a77c130 → 3.6.0-feat-shaime-support-entity-attributes-1-4c8e283
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/authorization-attributes-service.d.ts +47 -26
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +172 -33
- package/dist/authorization-middleware.d.ts +2 -2
- package/dist/authorization-middleware.d.ts.map +1 -1
- package/dist/authorization-service.d.ts +3 -3
- package/dist/authorization-service.d.ts.map +1 -1
- package/dist/base-attribute-assignment.d.ts +6 -5
- package/dist/base-attribute-assignment.d.ts.map +1 -1
- package/dist/base-attribute-assignment.js +8 -17
- package/dist/constants/sns.d.ts +2 -12
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +2 -22
- package/dist/entity-attribute-assignment.d.ts +4 -8
- package/dist/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/entity-attribute-assignment.js +5 -4
- package/dist/entity-attributes-constants.d.ts +6 -6
- package/dist/entity-attributes-constants.d.ts.map +1 -1
- package/dist/entity-attributes-constants.js +7 -5
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +0 -1
- package/dist/esm/authorization-attributes-service.d.ts +47 -26
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +168 -33
- package/dist/esm/authorization-middleware.d.ts +2 -2
- package/dist/esm/authorization-middleware.d.ts.map +1 -1
- package/dist/esm/authorization-service.d.ts +3 -3
- package/dist/esm/authorization-service.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.d.ts +6 -5
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.mjs +4 -17
- package/dist/esm/constants/sns.d.ts +2 -12
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +3 -17
- package/dist/esm/entity-attribute-assignment.d.ts +4 -8
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/entity-attribute-assignment.mjs +5 -4
- package/dist/esm/entity-attributes-constants.d.ts +6 -6
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -1
- package/dist/esm/entity-attributes-constants.mjs +8 -6
- package/dist/esm/errors/argument-error.d.ts.map +1 -1
- package/dist/esm/errors/argument-error.mjs +0 -1
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +0 -7
- package/dist/esm/prometheus-service.d.ts +2 -1
- package/dist/esm/prometheus-service.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.d.ts +4 -8
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.mjs +3 -2
- package/dist/esm/resource-attributes-constants.d.ts +21 -11
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
- package/dist/esm/resource-attributes-constants.mjs +17 -14
- package/dist/esm/testKit/index.d.ts +4 -4
- package/dist/esm/testKit/index.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +5 -4
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +7 -20
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +2 -1
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assigment-schema.d.ts +29 -0
- package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assigment-schema.mjs +29 -0
- package/dist/esm/utils/validation.d.ts +13 -38
- package/dist/esm/utils/validation.d.ts.map +1 -1
- package/dist/esm/utils/validation.mjs +38 -97
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -15
- package/dist/prometheus-service.d.ts +2 -1
- package/dist/prometheus-service.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.d.ts +4 -8
- package/dist/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.js +3 -2
- package/dist/resource-attributes-constants.d.ts +21 -11
- package/dist/resource-attributes-constants.d.ts.map +1 -1
- package/dist/resource-attributes-constants.js +16 -13
- package/dist/testKit/index.d.ts +4 -4
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +5 -4
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-service.interface.d.ts +7 -20
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/types/general.d.ts +2 -1
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assigment-schema.d.ts +29 -0
- package/dist/utils/assigment-schema.d.ts.map +1 -0
- package/dist/utils/assigment-schema.js +36 -0
- package/dist/utils/validation.d.ts +13 -38
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +42 -97
- package/package.json +3 -3
- package/src/authorization-attributes-service.ts +223 -35
- package/src/authorization-middleware.ts +2 -2
- package/src/authorization-service.ts +4 -4
- package/src/base-attribute-assignment.ts +10 -35
- package/src/constants/sns.ts +2 -19
- package/src/entity-attribute-assignment.ts +9 -6
- package/src/entity-attributes-constants.ts +6 -6
- package/src/errors/argument-error.ts +0 -1
- package/src/index.ts +0 -9
- package/src/prometheus-service.ts +3 -1
- package/src/resource-attribute-assignment.ts +11 -13
- package/src/resource-attributes-constants.ts +15 -23
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +5 -5
- package/src/types/authorization-attributes-service.interface.ts +12 -38
- package/src/types/general.ts +2 -3
- package/src/utils/assigment-schema.ts +29 -0
- package/src/utils/validation.ts +41 -92
- package/dist/authorization-attributes-ms-service.d.ts +0 -90
- package/dist/authorization-attributes-ms-service.d.ts.map +0 -1
- package/dist/authorization-attributes-ms-service.js +0 -352
- package/dist/authorization-attributes-sns-service.d.ts +0 -90
- package/dist/authorization-attributes-sns-service.d.ts.map +0 -1
- package/dist/authorization-attributes-sns-service.js +0 -217
- package/dist/esm/authorization-attributes-ms-service.d.ts +0 -90
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +0 -1
- package/dist/esm/authorization-attributes-ms-service.mjs +0 -350
- package/dist/esm/authorization-attributes-sns-service.d.ts +0 -90
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +0 -1
- package/dist/esm/authorization-attributes-sns-service.mjs +0 -211
- package/src/authorization-attributes-ms-service.ts +0 -514
- package/src/authorization-attributes-sns-service.ts +0 -312
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import chunk from 'lodash/chunk.js';
|
|
2
|
-
import { getTopicAttributes, sendToSns } from '@mondaydotcomorg/monday-sns';
|
|
3
|
-
import {
|
|
4
|
-
ResourceAttributeAssignment,
|
|
5
|
-
ResourceAttributeOperation,
|
|
6
|
-
EntityAttributeOperation,
|
|
7
|
-
AttributeOperation,
|
|
8
|
-
EntityType,
|
|
9
|
-
} from './types/authorization-attributes-contracts';
|
|
10
|
-
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
11
|
-
import { Resource } from './types/general';
|
|
12
|
-
import { logger } from './authorization-internal-service';
|
|
13
|
-
import {
|
|
14
|
-
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
15
|
-
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
16
|
-
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
17
|
-
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
18
|
-
RESOURCE_SNS_ARN_ENV_VAR_NAME,
|
|
19
|
-
ENTITY_SNS_ARN_ENV_VAR_NAME,
|
|
20
|
-
RESOURCE_SNS_DEV_TEST_NAME,
|
|
21
|
-
ENTITY_SNS_DEV_TEST_NAME,
|
|
22
|
-
SnsTopicType,
|
|
23
|
-
} from './constants/sns';
|
|
24
|
-
import type { TopicAttributesMap } from 'aws-sdk/clients/sns';
|
|
25
|
-
import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Service class for managing resource attributes asynchronously via SNS.
|
|
29
|
-
* Provides asynchronous operations to create/update and delete attributes on resources.
|
|
30
|
-
*/
|
|
31
|
-
export class AuthorizationAttributesSnsService implements IAuthorizationAttributesService {
|
|
32
|
-
private static LOG_TAG = 'authorization_attributes';
|
|
33
|
-
private resourceSnsArn: string;
|
|
34
|
-
private entitySnsArn: string;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Public constructor to create the AuthorizationAttributesSnsService instance.
|
|
38
|
-
*/
|
|
39
|
-
constructor() {
|
|
40
|
-
this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
|
|
41
|
-
this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Async function to upsert resource attributes using SNS.
|
|
46
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
47
|
-
* @param accountId The account ID
|
|
48
|
-
* @param appName App name of the calling app
|
|
49
|
-
* @param callerActionIdentifier Action identifier
|
|
50
|
-
* @param resourceAttributeAssignments Array of resource attribute assignments to upsert
|
|
51
|
-
* @return Promise with array of sent operations
|
|
52
|
-
*/
|
|
53
|
-
async upsertResourceAttributes(
|
|
54
|
-
accountId: number,
|
|
55
|
-
resourceAttributeAssignments: ResourceAttributeAssignment[],
|
|
56
|
-
appName?: string,
|
|
57
|
-
callerActionIdentifier?: string
|
|
58
|
-
): Promise<ResourceAttributeOperation[]> {
|
|
59
|
-
if (!appName || !callerActionIdentifier) {
|
|
60
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
61
|
-
}
|
|
62
|
-
const operations: ResourceAttributeOperation[] = resourceAttributeAssignments.map(assignment => ({
|
|
63
|
-
...assignment,
|
|
64
|
-
operationType: AttributeOperation.UPSERT,
|
|
65
|
-
}));
|
|
66
|
-
return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Async function to delete resource attributes using SNS.
|
|
71
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
72
|
-
* @param accountId The account ID
|
|
73
|
-
* @param appName App name of the calling app
|
|
74
|
-
* @param callerActionIdentifier Action identifier
|
|
75
|
-
* @param resource The resource (resourceType, resourceId)
|
|
76
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
77
|
-
* @return Promise with array of sent operations
|
|
78
|
-
*/
|
|
79
|
-
async deleteResourceAttributes(
|
|
80
|
-
accountId: number,
|
|
81
|
-
resource: Resource,
|
|
82
|
-
attributeKeys: string[],
|
|
83
|
-
appName?: string,
|
|
84
|
-
callerActionIdentifier?: string
|
|
85
|
-
): Promise<ResourceAttributeOperation[]> {
|
|
86
|
-
if (!appName || !callerActionIdentifier) {
|
|
87
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
88
|
-
}
|
|
89
|
-
const operations: ResourceAttributeOperation[] = attributeKeys.map(
|
|
90
|
-
key =>
|
|
91
|
-
({
|
|
92
|
-
resourceType: resource.type,
|
|
93
|
-
resourceId: resource.id!,
|
|
94
|
-
key,
|
|
95
|
-
operationType: AttributeOperation.DELETE,
|
|
96
|
-
} as ResourceAttributeOperation)
|
|
97
|
-
);
|
|
98
|
-
return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Async function to upsert entity attributes using SNS.
|
|
103
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
104
|
-
* @param accountId The account ID
|
|
105
|
-
* @param appName App name of the calling app
|
|
106
|
-
* @param callerActionIdentifier Action identifier
|
|
107
|
-
* @param entityAttributeAssignments Array of entity attribute assignments to upsert
|
|
108
|
-
* @return Promise with array of sent operations
|
|
109
|
-
*/
|
|
110
|
-
async upsertEntityAttributes(
|
|
111
|
-
accountId: number,
|
|
112
|
-
entityAttributeAssignments: EntityAttributeAssignment[],
|
|
113
|
-
appName?: string,
|
|
114
|
-
callerActionIdentifier?: string
|
|
115
|
-
): Promise<EntityAttributeOperation[]> {
|
|
116
|
-
if (!appName || !callerActionIdentifier) {
|
|
117
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
118
|
-
}
|
|
119
|
-
const operations: EntityAttributeOperation[] = entityAttributeAssignments.map(assignment => {
|
|
120
|
-
return {
|
|
121
|
-
entityId: assignment.entityId,
|
|
122
|
-
entityType: assignment.entityType,
|
|
123
|
-
key: assignment.attributeKey,
|
|
124
|
-
value: assignment.attributeValue,
|
|
125
|
-
operationType: AttributeOperation.UPSERT,
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Async function to delete entity attributes using SNS.
|
|
133
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
134
|
-
* @param accountId The account ID
|
|
135
|
-
* @param appName App name of the calling app
|
|
136
|
-
* @param callerActionIdentifier Action identifier
|
|
137
|
-
* @param entityType The entity type
|
|
138
|
-
* @param entityId The entity ID
|
|
139
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
140
|
-
* @return Promise with array of sent operations
|
|
141
|
-
*/
|
|
142
|
-
async deleteEntityAttributes(
|
|
143
|
-
accountId: number,
|
|
144
|
-
entityType: EntityType | string,
|
|
145
|
-
entityId: number,
|
|
146
|
-
attributeKeys: string[],
|
|
147
|
-
appName?: string,
|
|
148
|
-
callerActionIdentifier?: string
|
|
149
|
-
): Promise<EntityAttributeOperation[]> {
|
|
150
|
-
if (!appName || !callerActionIdentifier) {
|
|
151
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
152
|
-
}
|
|
153
|
-
const operations: EntityAttributeOperation[] = attributeKeys.map(
|
|
154
|
-
key =>
|
|
155
|
-
({
|
|
156
|
-
entityType: entityType,
|
|
157
|
-
entityId,
|
|
158
|
-
key,
|
|
159
|
-
operationType: AttributeOperation.DELETE,
|
|
160
|
-
} as EntityAttributeOperation)
|
|
161
|
-
);
|
|
162
|
-
return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
167
|
-
* @param accountId
|
|
168
|
-
* @param appName - App name of the calling app
|
|
169
|
-
* @param callerActionIdentifier - action identifier
|
|
170
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
171
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
172
|
-
* */
|
|
173
|
-
async updateResourceAttributes(
|
|
174
|
-
accountId: number,
|
|
175
|
-
appName: string,
|
|
176
|
-
callerActionIdentifier: string,
|
|
177
|
-
resourceAttributeOperations: ResourceAttributeOperation[]
|
|
178
|
-
): Promise<ResourceAttributeOperation[]> {
|
|
179
|
-
const topicArn: string = this.resourceSnsArn;
|
|
180
|
-
const sendToSnsPromises: Promise<ResourceAttributeOperation[]>[] = [];
|
|
181
|
-
const operationChucks = chunk(resourceAttributeOperations, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
182
|
-
for (const operationsChunk of operationChucks) {
|
|
183
|
-
sendToSnsPromises.push(
|
|
184
|
-
this.sendSingleSnsMessage(
|
|
185
|
-
topicArn,
|
|
186
|
-
accountId,
|
|
187
|
-
appName,
|
|
188
|
-
callerActionIdentifier,
|
|
189
|
-
operationsChunk,
|
|
190
|
-
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
191
|
-
'Authorization resource attributes async update: failed to send operations to SNS'
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
200
|
-
* @param accountId
|
|
201
|
-
* @param appName - App name of the calling app
|
|
202
|
-
* @param callerActionIdentifier - action identifier
|
|
203
|
-
* @param entityAttributeOperations - Array of operations to do on entity attributes.
|
|
204
|
-
* @return {Promise<EntityAttributeOperation[]>} Array of sent operations
|
|
205
|
-
* */
|
|
206
|
-
async updateEntityAttributes(
|
|
207
|
-
accountId: number,
|
|
208
|
-
appName: string,
|
|
209
|
-
callerActionIdentifier: string,
|
|
210
|
-
entityAttributeOperations: EntityAttributeOperation[]
|
|
211
|
-
): Promise<EntityAttributeOperation[]> {
|
|
212
|
-
const topicArn: string = this.entitySnsArn;
|
|
213
|
-
const sendToSnsPromises: Promise<EntityAttributeOperation[]>[] = [];
|
|
214
|
-
const operationChucks = chunk(entityAttributeOperations, ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
215
|
-
for (const operationsChunk of operationChucks) {
|
|
216
|
-
sendToSnsPromises.push(
|
|
217
|
-
this.sendSingleSnsMessage(
|
|
218
|
-
topicArn,
|
|
219
|
-
accountId,
|
|
220
|
-
appName,
|
|
221
|
-
callerActionIdentifier,
|
|
222
|
-
operationsChunk,
|
|
223
|
-
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
224
|
-
'Authorization entity attributes async update: failed to send operations to SNS'
|
|
225
|
-
)
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private async sendSingleSnsMessage<T extends ResourceAttributeOperation | EntityAttributeOperation>(
|
|
232
|
-
topicArn: string,
|
|
233
|
-
accountId: number,
|
|
234
|
-
appName: string,
|
|
235
|
-
callerActionIdentifier: string,
|
|
236
|
-
operations: T[],
|
|
237
|
-
kind: string,
|
|
238
|
-
errorLogMessage: string
|
|
239
|
-
): Promise<T[]> {
|
|
240
|
-
const payload = {
|
|
241
|
-
kind,
|
|
242
|
-
payload: {
|
|
243
|
-
accountId: accountId,
|
|
244
|
-
callerAppName: appName,
|
|
245
|
-
callerActionIdentifier: callerActionIdentifier,
|
|
246
|
-
operations: operations,
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
try {
|
|
250
|
-
await sendToSns(payload, topicArn);
|
|
251
|
-
return operations;
|
|
252
|
-
} catch (error) {
|
|
253
|
-
logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
|
|
254
|
-
return [];
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private static getSnsTopicArn(type: SnsTopicType): string {
|
|
259
|
-
let envVarName: string;
|
|
260
|
-
let devTestName: string;
|
|
261
|
-
|
|
262
|
-
switch (type) {
|
|
263
|
-
case SnsTopicType.ENTITY:
|
|
264
|
-
envVarName = ENTITY_SNS_ARN_ENV_VAR_NAME;
|
|
265
|
-
devTestName = ENTITY_SNS_DEV_TEST_NAME;
|
|
266
|
-
break;
|
|
267
|
-
default:
|
|
268
|
-
// Default to resource SNS constants
|
|
269
|
-
envVarName = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
270
|
-
devTestName = RESOURCE_SNS_DEV_TEST_NAME;
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const arnFromEnv: string | undefined = process.env[envVarName];
|
|
275
|
-
if (arnFromEnv) {
|
|
276
|
-
return arnFromEnv;
|
|
277
|
-
}
|
|
278
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
279
|
-
return devTestName;
|
|
280
|
-
}
|
|
281
|
-
throw new Error(`Unable to get ${type} sns topic arn from env variable`);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
286
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
287
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
288
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
289
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
290
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
291
|
-
*/
|
|
292
|
-
async asyncResourceAttributesHealthCheck(): Promise<boolean> {
|
|
293
|
-
try {
|
|
294
|
-
const requestedTopicArn: string = this.resourceSnsArn;
|
|
295
|
-
const attributes: TopicAttributesMap = await getTopicAttributes(requestedTopicArn);
|
|
296
|
-
const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
|
|
297
|
-
if (!isHealthy) {
|
|
298
|
-
logger.error(
|
|
299
|
-
{ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG },
|
|
300
|
-
'authorization-attributes-service failed in health check'
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
return isHealthy;
|
|
304
|
-
} catch (error) {
|
|
305
|
-
logger.error(
|
|
306
|
-
{ error, tag: AuthorizationAttributesSnsService.LOG_TAG },
|
|
307
|
-
'authorization-attributes-service got error during health check'
|
|
308
|
-
);
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|