@mondaydotcomorg/monday-authorization 3.6.0-feat-shaime-support-entity-attributes-1-f58d933 → 3.6.0-feat-shaime-support-entity-attributes-3-78dca48
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-ms-service.d.ts +68 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +263 -0
- package/dist/authorization-attributes-service.d.ts +25 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +32 -171
- package/dist/authorization-attributes-sns-service.d.ts +84 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +196 -0
- package/dist/constants/sns.d.ts +12 -2
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +22 -2
- package/dist/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/entity-attribute-assignment.js +0 -2
- package/dist/esm/authorization-attributes-ms-service.d.ts +68 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +261 -0
- package/dist/esm/authorization-attributes-service.d.ts +25 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +32 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +84 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +190 -0
- package/dist/esm/constants/sns.d.ts +12 -2
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +17 -3
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/entity-attribute-assignment.mjs +0 -2
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.mjs +0 -2
- package/dist/esm/resource-attributes-constants.d.ts +2 -1
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
- package/dist/esm/resource-attributes-constants.mjs +1 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts +2 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +14 -25
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +4 -3
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assignment-schema.d.ts +51 -0
- package/dist/esm/utils/assignment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assignment-schema.mjs +49 -0
- package/dist/esm/utils/resource-schema.d.ts +9 -0
- package/dist/esm/utils/resource-schema.d.ts.map +1 -0
- package/dist/esm/utils/resource-schema.mjs +16 -0
- package/dist/esm/utils/validation.d.ts +11 -3
- package/dist/esm/utils/validation.d.ts.map +1 -1
- package/dist/esm/utils/validation.mjs +50 -13
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.js +0 -2
- package/dist/resource-attributes-constants.d.ts +2 -1
- package/dist/resource-attributes-constants.d.ts.map +1 -1
- package/dist/resource-attributes-constants.js +1 -0
- package/dist/types/authorization-attributes-contracts.d.ts +2 -0
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-service.interface.d.ts +14 -25
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/types/general.d.ts +4 -3
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assignment-schema.d.ts +51 -0
- package/dist/utils/assignment-schema.d.ts.map +1 -0
- package/dist/utils/assignment-schema.js +58 -0
- package/dist/utils/resource-schema.d.ts +9 -0
- package/dist/utils/resource-schema.d.ts.map +1 -0
- package/dist/utils/resource-schema.js +22 -0
- package/dist/utils/validation.d.ts +11 -3
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +50 -13
- package/package.json +1 -1
- package/src/authorization-attributes-ms-service.ts +397 -0
- package/src/authorization-attributes-service.ts +34 -222
- package/src/authorization-attributes-sns-service.ts +321 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +0 -2
- package/src/index.ts +2 -0
- package/src/resource-attribute-assignment.ts +0 -2
- package/src/resource-attributes-constants.ts +1 -0
- package/src/types/authorization-attributes-contracts.ts +2 -0
- package/src/types/authorization-attributes-service.interface.ts +19 -31
- package/src/types/general.ts +4 -3
- package/src/utils/assignment-schema.ts +51 -0
- package/src/utils/resource-schema.ts +16 -0
- package/src/utils/validation.ts +76 -15
- package/dist/esm/utils/assigment-schema.d.ts +0 -29
- package/dist/esm/utils/assigment-schema.d.ts.map +0 -1
- package/dist/esm/utils/assigment-schema.mjs +0 -29
- package/dist/utils/assigment-schema.d.ts +0 -29
- package/dist/utils/assigment-schema.d.ts.map +0 -1
- package/dist/utils/assigment-schema.js +0 -36
- package/src/utils/assigment-schema.ts +0 -29
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import chunk from 'lodash/chunk.js';
|
|
2
|
+
import { getTopicAttributes, sendToSns } from '@mondaydotcomorg/monday-sns';
|
|
3
|
+
import {
|
|
4
|
+
AttributeOperation,
|
|
5
|
+
ResourceAttributeUpsertOperation,
|
|
6
|
+
EntityAttributeUpsertOperation,
|
|
7
|
+
EntityAttributeDeleteOperation,
|
|
8
|
+
ResourceAttributeDeleteOperation,
|
|
9
|
+
} from './types/authorization-attributes-contracts';
|
|
10
|
+
import { Resource } from './types/general';
|
|
11
|
+
import { logger } from './authorization-internal-service';
|
|
12
|
+
import {
|
|
13
|
+
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
14
|
+
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
15
|
+
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
16
|
+
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
17
|
+
RESOURCE_SNS_ARN_ENV_VAR_NAME,
|
|
18
|
+
ENTITY_SNS_ARN_ENV_VAR_NAME,
|
|
19
|
+
RESOURCE_SNS_DEV_TEST_NAME,
|
|
20
|
+
ENTITY_SNS_DEV_TEST_NAME,
|
|
21
|
+
SnsTopicType,
|
|
22
|
+
} from './constants/sns';
|
|
23
|
+
import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
24
|
+
import { EntityType } from './entity-attributes-constants';
|
|
25
|
+
import { ValidationUtils } from './utils/validation';
|
|
26
|
+
import type { TopicAttributesMap } from 'aws-sdk/clients/sns';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Service class for managing resource attributes asynchronously via SNS.
|
|
30
|
+
* Provides asynchronous operations to create/update and delete attributes on resources.
|
|
31
|
+
*/
|
|
32
|
+
export class AuthorizationAttributesSnsService implements AuthorizationAttributesService {
|
|
33
|
+
private static LOG_TAG = 'authorization_attributes';
|
|
34
|
+
private resourceSnsArn: string;
|
|
35
|
+
private entitySnsArn: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Public constructor to create the AuthorizationAttributesSnsService instance.
|
|
39
|
+
*/
|
|
40
|
+
constructor() {
|
|
41
|
+
this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
|
|
42
|
+
this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Async function to delete a resource attribute using SNS.
|
|
47
|
+
* Sends the delete request to SNS and returns before the change actually took place.
|
|
48
|
+
* @param accountId The account ID
|
|
49
|
+
* @param resource The resource (resourceType, resourceId)
|
|
50
|
+
* @param attributeKey Attribute key to delete
|
|
51
|
+
* @param appName App name of the calling app
|
|
52
|
+
* @param callerActionIdentifier Action identifier
|
|
53
|
+
* @return Promise with sent operation
|
|
54
|
+
*/
|
|
55
|
+
async deleteResourceAttributes(
|
|
56
|
+
accountId: number,
|
|
57
|
+
resource: Resource,
|
|
58
|
+
attributeKey: string,
|
|
59
|
+
appName?: string,
|
|
60
|
+
callerActionIdentifier?: string
|
|
61
|
+
): Promise<ResourceAttributeDeleteOperation> {
|
|
62
|
+
if (!appName || !callerActionIdentifier) {
|
|
63
|
+
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
64
|
+
}
|
|
65
|
+
ValidationUtils.validatDeleteResourceAssignment({
|
|
66
|
+
resourceType: resource.type,
|
|
67
|
+
resourceId: resource.id,
|
|
68
|
+
key: attributeKey,
|
|
69
|
+
});
|
|
70
|
+
const operation: ResourceAttributeDeleteOperation = {
|
|
71
|
+
resourceType: resource.type,
|
|
72
|
+
resourceId: resource.id,
|
|
73
|
+
key: attributeKey,
|
|
74
|
+
operationType: AttributeOperation.DELETE,
|
|
75
|
+
};
|
|
76
|
+
const [result] = await this.sendOperationsToSns(
|
|
77
|
+
this.resourceSnsArn,
|
|
78
|
+
accountId,
|
|
79
|
+
appName,
|
|
80
|
+
callerActionIdentifier,
|
|
81
|
+
[operation],
|
|
82
|
+
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
83
|
+
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
84
|
+
'Authorization resource attributes async delete: failed to send operations to SNS'
|
|
85
|
+
);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Async function to delete an entity attribute using SNS.
|
|
91
|
+
* Sends the delete request to SNS and returns before the change actually took place.
|
|
92
|
+
* @param accountId The account ID
|
|
93
|
+
* @param entityType The entity type
|
|
94
|
+
* @param entityId The entity ID
|
|
95
|
+
* @param attributeKey Attribute key to delete
|
|
96
|
+
* @param appName App name of the calling app
|
|
97
|
+
* @param callerActionIdentifier Action identifier
|
|
98
|
+
* @return Promise with sent operation
|
|
99
|
+
*/
|
|
100
|
+
async deleteEntityAttributes(
|
|
101
|
+
accountId: number,
|
|
102
|
+
entityType: EntityType,
|
|
103
|
+
entityId: number,
|
|
104
|
+
attributeKey: string,
|
|
105
|
+
appName?: string,
|
|
106
|
+
callerActionIdentifier?: string
|
|
107
|
+
): Promise<EntityAttributeDeleteOperation> {
|
|
108
|
+
if (!appName || !callerActionIdentifier) {
|
|
109
|
+
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
110
|
+
}
|
|
111
|
+
ValidationUtils.validatDeleteEntityAssignment({ entityId, entityType, key: attributeKey });
|
|
112
|
+
const operation: EntityAttributeDeleteOperation = {
|
|
113
|
+
entityType: entityType,
|
|
114
|
+
entityId,
|
|
115
|
+
key: attributeKey,
|
|
116
|
+
operationType: AttributeOperation.DELETE,
|
|
117
|
+
};
|
|
118
|
+
const [result] = await this.sendOperationsToSns(
|
|
119
|
+
this.entitySnsArn,
|
|
120
|
+
accountId,
|
|
121
|
+
appName,
|
|
122
|
+
callerActionIdentifier,
|
|
123
|
+
[operation],
|
|
124
|
+
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
125
|
+
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
126
|
+
'Authorization entity attributes async delete: failed to send operations to SNS'
|
|
127
|
+
);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Async function, this function only send the update request to SNS and return before the change actually took place
|
|
133
|
+
* @param accountId
|
|
134
|
+
* @param appName - App name of the calling app
|
|
135
|
+
* @param callerActionIdentifier - action identifier
|
|
136
|
+
* @param resourceAttributeOperation - Operation to do on resource attribute.
|
|
137
|
+
* @return {Promise<ResourceAttributeUpsertOperation>} Sent operation
|
|
138
|
+
* */
|
|
139
|
+
async updateResourceAttributes(
|
|
140
|
+
accountId: number,
|
|
141
|
+
appName: string,
|
|
142
|
+
callerActionIdentifier: string,
|
|
143
|
+
resourceAttributeOperation: ResourceAttributeUpsertOperation
|
|
144
|
+
): Promise<ResourceAttributeUpsertOperation> {
|
|
145
|
+
ValidationUtils.validatUpsertResourceAssignment(resourceAttributeOperation);
|
|
146
|
+
const [result] = await this.sendOperationsToSns(
|
|
147
|
+
this.resourceSnsArn,
|
|
148
|
+
accountId,
|
|
149
|
+
appName,
|
|
150
|
+
callerActionIdentifier,
|
|
151
|
+
[resourceAttributeOperation],
|
|
152
|
+
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
153
|
+
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
154
|
+
'Authorization resource attributes async update: failed to send operations to SNS'
|
|
155
|
+
);
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Async function, this function only send the update request to SNS and return before the change actually took place
|
|
161
|
+
* @param accountId
|
|
162
|
+
* @param appName - App name of the calling app
|
|
163
|
+
* @param callerActionIdentifier - action identifier
|
|
164
|
+
* @param entityAttributeOperation - Operation to do on entity attribute.
|
|
165
|
+
* @return {Promise<EntityAttributeUpsertOperation>} Sent operation
|
|
166
|
+
* */
|
|
167
|
+
async updateEntityAttributes(
|
|
168
|
+
accountId: number,
|
|
169
|
+
appName: string,
|
|
170
|
+
callerActionIdentifier: string,
|
|
171
|
+
entityAttributeOperation: EntityAttributeUpsertOperation
|
|
172
|
+
): Promise<EntityAttributeUpsertOperation> {
|
|
173
|
+
ValidationUtils.validatUpsertEntityAssignment(entityAttributeOperation);
|
|
174
|
+
const [result] = await this.sendOperationsToSns(
|
|
175
|
+
this.entitySnsArn,
|
|
176
|
+
accountId,
|
|
177
|
+
appName,
|
|
178
|
+
callerActionIdentifier,
|
|
179
|
+
[entityAttributeOperation],
|
|
180
|
+
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
181
|
+
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
182
|
+
'Authorization entity attributes async update: failed to send operations to SNS'
|
|
183
|
+
);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Base function to send attribute operations to SNS.
|
|
189
|
+
* Chunks operations and sends them in parallel.
|
|
190
|
+
* @param topicArn The SNS topic ARN to send messages to
|
|
191
|
+
* @param accountId The account ID
|
|
192
|
+
* @param appName App name of the calling app
|
|
193
|
+
* @param callerActionIdentifier Action identifier
|
|
194
|
+
* @param operations Array of operations to send
|
|
195
|
+
* @param chunkSize Maximum number of operations per message
|
|
196
|
+
* @param messageKind The kind of message being sent
|
|
197
|
+
* @param errorLogMessage Error message to log if sending fails
|
|
198
|
+
* @return Promise with array of sent operations
|
|
199
|
+
*/
|
|
200
|
+
private async sendOperationsToSns<
|
|
201
|
+
T extends
|
|
202
|
+
| ResourceAttributeUpsertOperation
|
|
203
|
+
| ResourceAttributeDeleteOperation
|
|
204
|
+
| EntityAttributeUpsertOperation
|
|
205
|
+
| EntityAttributeDeleteOperation
|
|
206
|
+
>(
|
|
207
|
+
topicArn: string,
|
|
208
|
+
accountId: number,
|
|
209
|
+
appName: string,
|
|
210
|
+
callerActionIdentifier: string,
|
|
211
|
+
operations: T[],
|
|
212
|
+
chunkSize: number,
|
|
213
|
+
messageKind: string,
|
|
214
|
+
errorLogMessage: string
|
|
215
|
+
): Promise<T[]> {
|
|
216
|
+
const sendToSnsPromises: Promise<T[]>[] = [];
|
|
217
|
+
const operationChunks = chunk(operations, chunkSize);
|
|
218
|
+
for (const operationsChunk of operationChunks) {
|
|
219
|
+
sendToSnsPromises.push(
|
|
220
|
+
this.sendSingleSnsMessage(
|
|
221
|
+
topicArn,
|
|
222
|
+
accountId,
|
|
223
|
+
appName,
|
|
224
|
+
callerActionIdentifier,
|
|
225
|
+
operationsChunk,
|
|
226
|
+
messageKind,
|
|
227
|
+
errorLogMessage
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return (await Promise.all(sendToSnsPromises)).flat();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private async sendSingleSnsMessage<
|
|
235
|
+
T extends
|
|
236
|
+
| ResourceAttributeUpsertOperation
|
|
237
|
+
| ResourceAttributeDeleteOperation
|
|
238
|
+
| EntityAttributeUpsertOperation
|
|
239
|
+
| EntityAttributeDeleteOperation
|
|
240
|
+
>(
|
|
241
|
+
topicArn: string,
|
|
242
|
+
accountId: number,
|
|
243
|
+
appName: string,
|
|
244
|
+
callerActionIdentifier: string,
|
|
245
|
+
operations: T[],
|
|
246
|
+
kind: string,
|
|
247
|
+
errorLogMessage: string
|
|
248
|
+
): Promise<T[]> {
|
|
249
|
+
const payload = {
|
|
250
|
+
kind,
|
|
251
|
+
payload: {
|
|
252
|
+
accountId: accountId,
|
|
253
|
+
callerAppName: appName,
|
|
254
|
+
callerActionIdentifier: callerActionIdentifier,
|
|
255
|
+
operations: operations,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
try {
|
|
259
|
+
await sendToSns(payload, topicArn);
|
|
260
|
+
return operations;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private static getSnsTopicArn(type: SnsTopicType): string {
|
|
268
|
+
let envVarName: string;
|
|
269
|
+
let devTestName: string;
|
|
270
|
+
|
|
271
|
+
switch (type) {
|
|
272
|
+
case SnsTopicType.ENTITY:
|
|
273
|
+
envVarName = ENTITY_SNS_ARN_ENV_VAR_NAME;
|
|
274
|
+
devTestName = ENTITY_SNS_DEV_TEST_NAME;
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
// Default to resource SNS constants
|
|
278
|
+
envVarName = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
279
|
+
devTestName = RESOURCE_SNS_DEV_TEST_NAME;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const arnFromEnv: string | undefined = process.env[envVarName];
|
|
284
|
+
if (arnFromEnv) {
|
|
285
|
+
return arnFromEnv;
|
|
286
|
+
}
|
|
287
|
+
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
288
|
+
return devTestName;
|
|
289
|
+
}
|
|
290
|
+
throw new Error(`Unable to get ${type} sns topic arn from env variable`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
295
|
+
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
296
|
+
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
297
|
+
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
298
|
+
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
299
|
+
* @return {Promise<boolean>} - true if succeeded
|
|
300
|
+
*/
|
|
301
|
+
async asyncResourceAttributesHealthCheck(): Promise<boolean> {
|
|
302
|
+
try {
|
|
303
|
+
const requestedTopicArn: string = this.resourceSnsArn;
|
|
304
|
+
const attributes: TopicAttributesMap = await getTopicAttributes(requestedTopicArn);
|
|
305
|
+
const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
|
|
306
|
+
if (!isHealthy) {
|
|
307
|
+
logger.error(
|
|
308
|
+
{ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG },
|
|
309
|
+
'authorization-attributes-service failed in health check'
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
return isHealthy;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
logger.error(
|
|
315
|
+
{ error, tag: AuthorizationAttributesSnsService.LOG_TAG },
|
|
316
|
+
'authorization-attributes-service got error during health check'
|
|
317
|
+
);
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
package/src/constants/sns.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export enum SnsTopicType {
|
|
2
|
+
RESOURCE = 'resource',
|
|
3
|
+
ENTITY = 'entity',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Resource SNS constants
|
|
7
|
+
export const RESOURCE_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
|
|
8
|
+
export const RESOURCE_SNS_DEV_TEST_NAME =
|
|
3
9
|
'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
|
|
10
|
+
|
|
11
|
+
// Entity SNS constants
|
|
12
|
+
export const ENTITY_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES';
|
|
13
|
+
export const ENTITY_SNS_DEV_TEST_NAME =
|
|
14
|
+
'arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local';
|
|
4
15
|
export const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
|
|
16
|
+
export const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
|
|
5
17
|
export const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
18
|
+
export const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
19
|
+
|
|
20
|
+
// Legacy exports for backward compatibility
|
|
21
|
+
export const SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
22
|
+
export const SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { EntityType } from './entity-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
3
|
import { EntityAttributeAssignment as EntityAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
4
|
-
import { ValidationUtils } from './utils/validation';
|
|
5
4
|
|
|
6
5
|
export class EntityAttributeAssignment extends BaseAttributeAssignment<EntityType, EntityAttributeAssignmentContract> {
|
|
7
6
|
public readonly entityId: number;
|
|
8
7
|
public readonly entityType: EntityType;
|
|
9
8
|
|
|
10
9
|
constructor(entityId: number, entityType: EntityType, key: string, value: string) {
|
|
11
|
-
ValidationUtils.validateEntityAssignment({ entityId, entityType, key, value });
|
|
12
10
|
super(entityId, entityType, key, value);
|
|
13
11
|
this.entityId = entityId;
|
|
14
12
|
this.entityType = entityType;
|
package/src/index.ts
CHANGED
|
@@ -58,6 +58,8 @@ export {
|
|
|
58
58
|
} from './authorization-middleware';
|
|
59
59
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
60
60
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
61
|
+
export * from 'resource-attributes-constants';
|
|
62
|
+
export * from './entity-attributes-constants';
|
|
61
63
|
export { RolesService } from './roles-service';
|
|
62
64
|
export { MembershipsService } from './memberships';
|
|
63
65
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ResourceType } from './resource-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
3
|
import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
4
|
-
import { ValidationUtils } from './utils/validation';
|
|
5
4
|
|
|
6
5
|
export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
7
6
|
ResourceType,
|
|
@@ -11,7 +10,6 @@ export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
|
11
10
|
public readonly resourceType: ResourceType;
|
|
12
11
|
|
|
13
12
|
constructor(resourceId: number, resourceType: ResourceType, attributeKey: string, attributeValue: string) {
|
|
14
|
-
ValidationUtils.validateResourceAssignment({ resourceId, resourceType, key: attributeKey, value: attributeValue });
|
|
15
13
|
super(resourceId, resourceType, attributeKey, attributeValue);
|
|
16
14
|
this.resourceId = resourceId;
|
|
17
15
|
this.resourceType = this.type;
|
|
@@ -12,6 +12,7 @@ export interface ResourceAttributeAssignment extends AttributeAssignment {
|
|
|
12
12
|
resourceId: number;
|
|
13
13
|
resourceType: ResourceType;
|
|
14
14
|
}
|
|
15
|
+
export type ResourceAttributeDeleteAssignment = Omit<ResourceAttributeAssignment, 'value'>;
|
|
15
16
|
|
|
16
17
|
// Entity Attribute Assignment - matching API contract
|
|
17
18
|
// Note: For validation, use the EntityAttributeAssignment class from '../entity-attribute-assignment'
|
|
@@ -19,6 +20,7 @@ export interface EntityAttributeAssignment extends AttributeAssignment {
|
|
|
19
20
|
entityId: number;
|
|
20
21
|
entityType: EntityType;
|
|
21
22
|
}
|
|
23
|
+
export type EntityAttributeDeleteAssignment = Omit<EntityAttributeAssignment, 'value'>;
|
|
22
24
|
|
|
23
25
|
// Legacy types for backward compatibility
|
|
24
26
|
export interface ResourceAttributeDelete {
|
|
@@ -7,69 +7,57 @@ import {
|
|
|
7
7
|
} from './authorization-attributes-contracts';
|
|
8
8
|
import { Resource } from './general';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Resource type compatible with both MS and SNS services
|
|
12
|
-
*/
|
|
13
|
-
export interface CompatibleResource {
|
|
14
|
-
resourceType?: string;
|
|
15
|
-
resourceId?: number;
|
|
16
|
-
type?: string;
|
|
17
|
-
id?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
10
|
/**
|
|
21
11
|
* Interface for authorization attributes operations.
|
|
22
12
|
* Both MS (direct) and SNS (async) services implement this interface.
|
|
23
13
|
*/
|
|
24
14
|
export interface AuthorizationAttributesService {
|
|
25
15
|
/**
|
|
26
|
-
* Deletes resource
|
|
27
|
-
*
|
|
28
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
16
|
+
* Deletes a resource attribute.
|
|
17
|
+
* Returns Promise<ResourceAttributeDeleteOperation>
|
|
29
18
|
*/
|
|
30
19
|
deleteResourceAttributes(
|
|
31
20
|
accountId: number,
|
|
32
|
-
resource:
|
|
33
|
-
|
|
21
|
+
resource: Resource,
|
|
22
|
+
attributeKey: string,
|
|
34
23
|
appName?: string,
|
|
35
24
|
callerActionIdentifier?: string
|
|
36
|
-
): Promise<
|
|
25
|
+
): Promise<ResourceAttributeDeleteOperation>;
|
|
37
26
|
|
|
38
27
|
/**
|
|
39
|
-
* Deletes entity
|
|
40
|
-
*
|
|
41
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
28
|
+
* Deletes an entity attribute.
|
|
29
|
+
* Returns Promise<EntityAttributeDeleteOperation>
|
|
42
30
|
*/
|
|
43
31
|
deleteEntityAttributes(
|
|
44
32
|
accountId: number,
|
|
45
33
|
entityType: EntityType | string,
|
|
46
34
|
entityId: number,
|
|
47
|
-
|
|
35
|
+
attributeKey: string,
|
|
48
36
|
appName?: string,
|
|
49
37
|
callerActionIdentifier?: string
|
|
50
|
-
): Promise<
|
|
38
|
+
): Promise<EntityAttributeDeleteOperation>;
|
|
51
39
|
|
|
52
40
|
/**
|
|
53
|
-
* Updates resource
|
|
54
|
-
* For MS service:
|
|
55
|
-
* For SNS service: returns Promise<
|
|
41
|
+
* Updates a resource attribute (single operation - upsert only).
|
|
42
|
+
* For MS service: performs upsert operation
|
|
43
|
+
* For SNS service: returns Promise<ResourceAttributeUpsertOperation>
|
|
56
44
|
*/
|
|
57
45
|
updateResourceAttributes(
|
|
58
46
|
accountId: number,
|
|
59
47
|
appName: string,
|
|
60
48
|
callerActionIdentifier: string,
|
|
61
|
-
|
|
62
|
-
): Promise<ResourceAttributeUpsertOperation
|
|
49
|
+
resourceAttributeOperation: ResourceAttributeUpsertOperation
|
|
50
|
+
): Promise<ResourceAttributeUpsertOperation>;
|
|
63
51
|
|
|
64
52
|
/**
|
|
65
|
-
* Updates entity
|
|
66
|
-
* For MS service:
|
|
67
|
-
* For SNS service: returns Promise<
|
|
53
|
+
* Updates an entity attribute (single operation - upsert only).
|
|
54
|
+
* For MS service: performs upsert operation
|
|
55
|
+
* For SNS service: returns Promise<EntityAttributeUpsertOperation>
|
|
68
56
|
*/
|
|
69
57
|
updateEntityAttributes(
|
|
70
58
|
accountId: number,
|
|
71
59
|
appName: string,
|
|
72
60
|
callerActionIdentifier: string,
|
|
73
|
-
|
|
74
|
-
): Promise<EntityAttributeUpsertOperation
|
|
61
|
+
entityAttributeOperation: EntityAttributeUpsertOperation
|
|
62
|
+
): Promise<EntityAttributeUpsertOperation>;
|
|
75
63
|
}
|
package/src/types/general.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Request, Response } from 'express';
|
|
2
|
+
import type { ResourceType } from '../resource-attributes-constants';
|
|
2
3
|
|
|
3
4
|
export interface Resource {
|
|
4
|
-
id
|
|
5
|
-
type:
|
|
5
|
+
id: number;
|
|
6
|
+
type: ResourceType;
|
|
6
7
|
wrapperData?: object;
|
|
7
8
|
}
|
|
8
9
|
export type Action = string;
|
|
@@ -12,7 +13,7 @@ export interface Context {
|
|
|
12
13
|
}
|
|
13
14
|
export interface AuthorizationObject {
|
|
14
15
|
resource_id?: Resource['id'];
|
|
15
|
-
resource_type:
|
|
16
|
+
resource_type: string;
|
|
16
17
|
wrapper_data?: Resource['wrapperData'];
|
|
17
18
|
action: Action;
|
|
18
19
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { EntityType } from '../entity-attributes-constants';
|
|
3
|
+
import { ResourceType } from '../resource-attributes-constants';
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
|
|
7
|
+
export const entityUpsertAssignmentSchema = ajv.compile({
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
11
|
+
entityType: { type: 'string', enum: Object.values(EntityType) },
|
|
12
|
+
key: { type: 'string', minLength: 1 },
|
|
13
|
+
value: { type: 'string', minLength: 1 },
|
|
14
|
+
},
|
|
15
|
+
required: ['entityId', 'entityType', 'key', 'value'],
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const entityDeleteAssignmentSchema = ajv.compile({
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
23
|
+
entityType: { type: 'string', enum: Object.values(EntityType) },
|
|
24
|
+
key: { type: 'string', minLength: 1 },
|
|
25
|
+
},
|
|
26
|
+
required: ['entityId', 'entityType', 'key'],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const resourceDeleteAssignmentSchema = ajv.compile({
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
resourceId: { type: 'number', multipleOf: 1 },
|
|
34
|
+
resourceType: { type: 'string', enum: Object.values(ResourceType) },
|
|
35
|
+
key: { type: 'string', minLength: 1 },
|
|
36
|
+
},
|
|
37
|
+
required: ['id', 'type', 'key'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const resourceUpsertAssignmentSchema = ajv.compile({
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
resourceId: { type: 'number', multipleOf: 1 },
|
|
45
|
+
resourceType: { type: 'string', enum: Object.values(ResourceType) },
|
|
46
|
+
key: { type: 'string', minLength: 1 },
|
|
47
|
+
value: { type: 'string', minLength: 1 },
|
|
48
|
+
},
|
|
49
|
+
required: ['resourceId', 'resourceType', 'key', 'value'],
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { RESOURCE_TYPES } from '../resource-attributes-constants';
|
|
3
|
+
|
|
4
|
+
const ajv = new Ajv({ allErrors: true });
|
|
5
|
+
|
|
6
|
+
export const resourceSchema = ajv.compile({
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
id: { type: 'number', multipleOf: 1 },
|
|
10
|
+
type: { type: 'string', enum: RESOURCE_TYPES },
|
|
11
|
+
wrapperData: { type: 'object' },
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
required: ['id', 'type'],
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
});
|