@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-a77c130 → 3.6.0-feat-shaime-support-entity-attributes-1-f58d933
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 +171 -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 +167 -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 +222 -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,352 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
|
|
4
|
-
const mondayJwt = require('@mondaydotcomorg/monday-jwt');
|
|
5
|
-
const zod = require('zod');
|
|
6
|
-
const resourceAttributeAssignment = require('./resource-attribute-assignment.js');
|
|
7
|
-
const entityAttributeAssignment = require('./entity-attribute-assignment.js');
|
|
8
|
-
const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
|
|
9
|
-
const errors_argumentError = require('./errors/argument-error.js');
|
|
10
|
-
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
11
|
-
const attributionsService = require('./attributions-service.js');
|
|
12
|
-
const constants = require('./constants.js');
|
|
13
|
-
const utils_validation = require('./utils/validation.js');
|
|
14
|
-
|
|
15
|
-
const INTERNAL_APP_NAME = 'internal_ms';
|
|
16
|
-
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
17
|
-
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
18
|
-
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
19
|
-
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
20
|
-
/**
|
|
21
|
-
* Service class for managing resource attributes in the authorization microservice.
|
|
22
|
-
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
23
|
-
*/
|
|
24
|
-
class AuthorizationAttributesMsService {
|
|
25
|
-
static LOG_TAG = 'authorization_attributes_ms';
|
|
26
|
-
static httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
27
|
-
/**
|
|
28
|
-
* Creates or updates resource attributes synchronously.
|
|
29
|
-
* @param accountId The account ID
|
|
30
|
-
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
31
|
-
* @returns Promise<void>
|
|
32
|
-
*/
|
|
33
|
-
async upsertResourceAttributes(accountId, resourceAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
34
|
-
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', resourceAttributeAssignment.ResourceAttributeAssignment, 'resource', 'upsertResourceAttributes');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Deletes specific attributes from a resource synchronously.
|
|
38
|
-
* @param accountId The account ID
|
|
39
|
-
* @param resource Object with resourceType (string) and resourceId (number)
|
|
40
|
-
* @param attributeKeys Array of attribute key strings to delete
|
|
41
|
-
* @returns Promise<void>
|
|
42
|
-
*/
|
|
43
|
-
async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
|
|
44
|
-
// Validate resource object
|
|
45
|
-
if (!resource || typeof resource !== 'object') {
|
|
46
|
-
throw new errors_argumentError.ArgumentError('resource must be an object');
|
|
47
|
-
}
|
|
48
|
-
if (!resource.id) {
|
|
49
|
-
throw new errors_argumentError.ArgumentError('resource.id is required');
|
|
50
|
-
}
|
|
51
|
-
utils_validation.ValidationUtils.validateInteger(resource.id, 'resource.id');
|
|
52
|
-
utils_validation.ValidationUtils.validateString(resource.type, 'resource.type');
|
|
53
|
-
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
54
|
-
resourceType: resource.type,
|
|
55
|
-
resourceId: resource.id,
|
|
56
|
-
}, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates or updates entity attributes synchronously.
|
|
60
|
-
* @param accountId The account ID
|
|
61
|
-
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
62
|
-
* @returns Promise<void>
|
|
63
|
-
*/
|
|
64
|
-
async upsertEntityAttributes(accountId, entityAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
65
|
-
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', entityAttributeAssignment.EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Deletes specific attributes from an entity synchronously.
|
|
69
|
-
* @param accountId The account ID
|
|
70
|
-
* @param entityType The entity type
|
|
71
|
-
* @param entityId The entity ID
|
|
72
|
-
* @param attributeKeys Array of attribute key strings to delete
|
|
73
|
-
* @returns Promise<void>
|
|
74
|
-
*/
|
|
75
|
-
async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
|
|
76
|
-
if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
|
|
77
|
-
throw new errors_argumentError.ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
|
|
78
|
-
}
|
|
79
|
-
utils_validation.ValidationUtils.validateInteger(entityId, 'entityId');
|
|
80
|
-
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
81
|
-
entityType,
|
|
82
|
-
entityId,
|
|
83
|
-
}, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Updates resource attributes (batch operations).
|
|
87
|
-
* Note: MS service does not support batch operations directly.
|
|
88
|
-
* This method processes operations sequentially using upsert/delete methods.
|
|
89
|
-
* @param accountId The account ID
|
|
90
|
-
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
91
|
-
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
92
|
-
* @param resourceAttributeOperations Array of operations to perform
|
|
93
|
-
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
94
|
-
*/
|
|
95
|
-
async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
|
|
96
|
-
const processedOperations = [];
|
|
97
|
-
for (const operation of resourceAttributeOperations) {
|
|
98
|
-
if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.UPSERT) {
|
|
99
|
-
if (!operation.resourceId) {
|
|
100
|
-
throw new errors_argumentError.ArgumentError('resourceId is required for upsert operation');
|
|
101
|
-
}
|
|
102
|
-
await this.upsertResourceAttributes(accountId, [
|
|
103
|
-
new resourceAttributeAssignment.ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
|
|
104
|
-
]);
|
|
105
|
-
processedOperations.push(operation);
|
|
106
|
-
}
|
|
107
|
-
else if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.DELETE) {
|
|
108
|
-
if (!operation.resourceId) {
|
|
109
|
-
throw new errors_argumentError.ArgumentError('resourceId is required for delete operation');
|
|
110
|
-
}
|
|
111
|
-
await this.deleteResourceAttributes(accountId, {
|
|
112
|
-
type: operation.resourceType,
|
|
113
|
-
id: operation.resourceId,
|
|
114
|
-
}, [operation.key]);
|
|
115
|
-
processedOperations.push(operation);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return processedOperations;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Updates entity attributes (batch operations).
|
|
122
|
-
* Note: MS service does not support batch operations directly.
|
|
123
|
-
* This method processes operations sequentially using upsert/delete methods.
|
|
124
|
-
* @param accountId The account ID
|
|
125
|
-
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
126
|
-
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
127
|
-
* @param entityAttributeOperations Array of operations to perform
|
|
128
|
-
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
129
|
-
*/
|
|
130
|
-
async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
|
|
131
|
-
const processedOperations = [];
|
|
132
|
-
for (const operation of entityAttributeOperations) {
|
|
133
|
-
if (operation.operationType === 'upsert') {
|
|
134
|
-
await this.upsertEntityAttributes(accountId, [
|
|
135
|
-
new entityAttributeAssignment.EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, operation.value || ''),
|
|
136
|
-
]);
|
|
137
|
-
processedOperations.push(operation);
|
|
138
|
-
}
|
|
139
|
-
else if (operation.operationType === 'delete') {
|
|
140
|
-
await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [operation.key]);
|
|
141
|
-
processedOperations.push(operation);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return processedOperations;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Replaces path template parameters with actual values
|
|
148
|
-
* @param template Path template with placeholders like {accountId}
|
|
149
|
-
* @param params Object with parameter names and values
|
|
150
|
-
* @returns Path with all placeholders replaced
|
|
151
|
-
*/
|
|
152
|
-
static replacePathParams(template, params) {
|
|
153
|
-
let path = template;
|
|
154
|
-
for (const [key, value] of Object.entries(params)) {
|
|
155
|
-
path = path.replace(`{${key}}`, String(value));
|
|
156
|
-
}
|
|
157
|
-
return path;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Generic helper for executing delete requests
|
|
161
|
-
*/
|
|
162
|
-
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
|
|
163
|
-
// Validate inputs
|
|
164
|
-
utils_validation.ValidationUtils.validateInteger(accountId, 'accountId');
|
|
165
|
-
utils_validation.ValidationUtils.validateArray(keys, 'attributeKeys');
|
|
166
|
-
if (!keys.length) {
|
|
167
|
-
authorizationInternalService.logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
// Validate all keys are strings
|
|
171
|
-
utils_validation.ValidationUtils.validateStringArray(keys, 'attributeKeys');
|
|
172
|
-
// Build request body
|
|
173
|
-
const requestBody = {
|
|
174
|
-
keys,
|
|
175
|
-
};
|
|
176
|
-
if (!AuthorizationAttributesMsService.httpClient) {
|
|
177
|
-
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
178
|
-
}
|
|
179
|
-
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
180
|
-
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
181
|
-
try {
|
|
182
|
-
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
183
|
-
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
184
|
-
url: {
|
|
185
|
-
appName: constants.APP_NAME,
|
|
186
|
-
path,
|
|
187
|
-
},
|
|
188
|
-
method: 'DELETE',
|
|
189
|
-
headers,
|
|
190
|
-
body: JSON.stringify(requestBody),
|
|
191
|
-
}, {
|
|
192
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
193
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
194
|
-
});
|
|
195
|
-
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
authorizationInternalService.logger.error({
|
|
199
|
-
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
200
|
-
method: methodName,
|
|
201
|
-
accountId,
|
|
202
|
-
...pathParams,
|
|
203
|
-
...context,
|
|
204
|
-
error: err instanceof Error ? err.message : String(err),
|
|
205
|
-
}, `Failed in ${methodName}`);
|
|
206
|
-
throw err;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
211
|
-
*/
|
|
212
|
-
static getRequestHeaders(accountId, userId) {
|
|
213
|
-
const headers = {
|
|
214
|
-
'Content-Type': 'application/json',
|
|
215
|
-
};
|
|
216
|
-
// Generate Authorization token
|
|
217
|
-
const authToken = mondayJwt.signAuthorizationHeader({
|
|
218
|
-
appName: INTERNAL_APP_NAME,
|
|
219
|
-
accountId,
|
|
220
|
-
userId,
|
|
221
|
-
});
|
|
222
|
-
headers.Authorization = authToken;
|
|
223
|
-
// Add attribution headers if available
|
|
224
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
225
|
-
for (const key in attributionHeaders) {
|
|
226
|
-
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
227
|
-
headers[key] = attributionHeaders[key];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
// Add X-REQUEST-ID if available from context
|
|
231
|
-
try {
|
|
232
|
-
const tridentContext = tridentBackendApi.Api.getPart('context');
|
|
233
|
-
if (tridentContext?.runtimeAttributions) {
|
|
234
|
-
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
235
|
-
if (outgoingHeaders) {
|
|
236
|
-
const attributionHeadersMap = {};
|
|
237
|
-
for (const [key, value] of outgoingHeaders) {
|
|
238
|
-
attributionHeadersMap[key] = value;
|
|
239
|
-
}
|
|
240
|
-
if (attributionHeadersMap['x-request-id']) {
|
|
241
|
-
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
// Silently fail if context is not available
|
|
248
|
-
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
249
|
-
}
|
|
250
|
-
// Add X-REQUEST-START timestamp
|
|
251
|
-
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
252
|
-
return headers;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Validates that all messages are instances of the specified message class
|
|
256
|
-
*/
|
|
257
|
-
static validateMessages(attributesMessages, messageClass) {
|
|
258
|
-
// Validate messageClass is a function using Zod
|
|
259
|
-
const classSchema = zod.z.custom(value => typeof value === 'function', {
|
|
260
|
-
message: 'messageClass must be a class/constructor function',
|
|
261
|
-
});
|
|
262
|
-
try {
|
|
263
|
-
classSchema.parse(messageClass);
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
if (error instanceof zod.z.ZodError) {
|
|
267
|
-
const firstError = error.issues[0];
|
|
268
|
-
throw new errors_argumentError.ArgumentError(firstError.message);
|
|
269
|
-
}
|
|
270
|
-
throw error;
|
|
271
|
-
}
|
|
272
|
-
const className = messageClass.name || 'ResourceAttributeAssignment';
|
|
273
|
-
// First validate it's an array
|
|
274
|
-
utils_validation.ValidationUtils.validateArray(attributesMessages, 'attributesMessages');
|
|
275
|
-
// Then use Zod to validate each item is an instance of the class
|
|
276
|
-
const schema = zod.z.array(zod.z.any()).refine(items => {
|
|
277
|
-
for (let i = 0; i < items.length; i++) {
|
|
278
|
-
if (!(items[i] instanceof messageClass)) {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return true;
|
|
283
|
-
}, {
|
|
284
|
-
message: `All attributesMessages must be instances of ${className}`,
|
|
285
|
-
});
|
|
286
|
-
try {
|
|
287
|
-
schema.parse(attributesMessages);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
if (error instanceof zod.z.ZodError) {
|
|
291
|
-
// Find the first invalid index for a more specific error message
|
|
292
|
-
const invalidIndex = attributesMessages.findIndex(item => !(item instanceof messageClass));
|
|
293
|
-
if (invalidIndex !== -1) {
|
|
294
|
-
throw new errors_argumentError.ArgumentError(`All attributesMessages must be instances of ${className}, but item at index ${invalidIndex} is not`);
|
|
295
|
-
}
|
|
296
|
-
const firstError = error.issues[0];
|
|
297
|
-
throw new errors_argumentError.ArgumentError(firstError.message);
|
|
298
|
-
}
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Generic helper for executing upsert requests
|
|
304
|
-
*/
|
|
305
|
-
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
|
|
306
|
-
// Validate inputs
|
|
307
|
-
utils_validation.ValidationUtils.validateInteger(accountId, 'accountId');
|
|
308
|
-
utils_validation.ValidationUtils.validateArray(assignments, 'assignments');
|
|
309
|
-
if (!assignments.length) {
|
|
310
|
-
authorizationInternalService.logger.warn({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId }, `${methodName} called with empty array`);
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
// Validate all assignments are instances of the correct class
|
|
314
|
-
AuthorizationAttributesMsService.validateMessages(assignments, assignmentClass);
|
|
315
|
-
const assignmentDto = assignments.map(assignment => assignment.toDataTransferObject());
|
|
316
|
-
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
317
|
-
? { resourceAttributeAssignments: assignmentDto }
|
|
318
|
-
: { entityAttributeAssignments: assignmentDto };
|
|
319
|
-
if (!AuthorizationAttributesMsService.httpClient) {
|
|
320
|
-
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
321
|
-
}
|
|
322
|
-
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
|
|
323
|
-
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
324
|
-
try {
|
|
325
|
-
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
326
|
-
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
327
|
-
url: {
|
|
328
|
-
appName: constants.APP_NAME,
|
|
329
|
-
path,
|
|
330
|
-
},
|
|
331
|
-
method: 'POST',
|
|
332
|
-
headers,
|
|
333
|
-
body: JSON.stringify(requestBody),
|
|
334
|
-
}, {
|
|
335
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
336
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
337
|
-
});
|
|
338
|
-
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
339
|
-
}
|
|
340
|
-
catch (err) {
|
|
341
|
-
authorizationInternalService.logger.error({
|
|
342
|
-
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
343
|
-
method: methodName,
|
|
344
|
-
accountId,
|
|
345
|
-
error: err instanceof Error ? err.message : String(err),
|
|
346
|
-
}, `Failed in ${methodName}`);
|
|
347
|
-
throw err;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ResourceAttributeAssignment, ResourceAttributeOperation, EntityAttributeOperation, EntityType } from './types/authorization-attributes-contracts';
|
|
2
|
-
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
3
|
-
import { Resource } from './types/general';
|
|
4
|
-
import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
5
|
-
/**
|
|
6
|
-
* Service class for managing resource attributes asynchronously via SNS.
|
|
7
|
-
* Provides asynchronous operations to create/update and delete attributes on resources.
|
|
8
|
-
*/
|
|
9
|
-
export declare class AuthorizationAttributesSnsService implements IAuthorizationAttributesService {
|
|
10
|
-
private static LOG_TAG;
|
|
11
|
-
private resourceSnsArn;
|
|
12
|
-
private entitySnsArn;
|
|
13
|
-
/**
|
|
14
|
-
* Public constructor to create the AuthorizationAttributesSnsService instance.
|
|
15
|
-
*/
|
|
16
|
-
constructor();
|
|
17
|
-
/**
|
|
18
|
-
* Async function to upsert resource attributes using SNS.
|
|
19
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
20
|
-
* @param accountId The account ID
|
|
21
|
-
* @param appName App name of the calling app
|
|
22
|
-
* @param callerActionIdentifier Action identifier
|
|
23
|
-
* @param resourceAttributeAssignments Array of resource attribute assignments to upsert
|
|
24
|
-
* @return Promise with array of sent operations
|
|
25
|
-
*/
|
|
26
|
-
upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Async function to delete resource attributes using SNS.
|
|
29
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
30
|
-
* @param accountId The account ID
|
|
31
|
-
* @param appName App name of the calling app
|
|
32
|
-
* @param callerActionIdentifier Action identifier
|
|
33
|
-
* @param resource The resource (resourceType, resourceId)
|
|
34
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
35
|
-
* @return Promise with array of sent operations
|
|
36
|
-
*/
|
|
37
|
-
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Async function to upsert entity attributes using SNS.
|
|
40
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
41
|
-
* @param accountId The account ID
|
|
42
|
-
* @param appName App name of the calling app
|
|
43
|
-
* @param callerActionIdentifier Action identifier
|
|
44
|
-
* @param entityAttributeAssignments Array of entity attribute assignments to upsert
|
|
45
|
-
* @return Promise with array of sent operations
|
|
46
|
-
*/
|
|
47
|
-
upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Async function to delete entity attributes using SNS.
|
|
50
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
51
|
-
* @param accountId The account ID
|
|
52
|
-
* @param appName App name of the calling app
|
|
53
|
-
* @param callerActionIdentifier Action identifier
|
|
54
|
-
* @param entityType The entity type
|
|
55
|
-
* @param entityId The entity ID
|
|
56
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
57
|
-
* @return Promise with array of sent operations
|
|
58
|
-
*/
|
|
59
|
-
deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
|
|
60
|
-
/**
|
|
61
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
62
|
-
* @param accountId
|
|
63
|
-
* @param appName - App name of the calling app
|
|
64
|
-
* @param callerActionIdentifier - action identifier
|
|
65
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
66
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
67
|
-
* */
|
|
68
|
-
updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
|
|
69
|
-
/**
|
|
70
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
71
|
-
* @param accountId
|
|
72
|
-
* @param appName - App name of the calling app
|
|
73
|
-
* @param callerActionIdentifier - action identifier
|
|
74
|
-
* @param entityAttributeOperations - Array of operations to do on entity attributes.
|
|
75
|
-
* @return {Promise<EntityAttributeOperation[]>} Array of sent operations
|
|
76
|
-
* */
|
|
77
|
-
updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
|
|
78
|
-
private sendSingleSnsMessage;
|
|
79
|
-
private static getSnsTopicArn;
|
|
80
|
-
/**
|
|
81
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
82
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
83
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
84
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
85
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
86
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
87
|
-
*/
|
|
88
|
-
asyncResourceAttributesHealthCheck(): Promise<boolean>;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=authorization-attributes-sns-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-sns-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-sns-service.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EAExB,UAAU,EACX,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAc3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAErG;;;GAGG;AACH,qBAAa,iCAAkC,YAAW,+BAA+B;IACvF,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;;IAMH;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAWxC;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAgBxC;;;;;;;;OAQG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;;;;OAUG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;UAOM;IACA,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAoBxC;;;;;;;UAOM;IACA,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;YAoBxB,oBAAoB;IA2BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IA0B7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
const chunk = require('lodash/chunk.js');
|
|
4
|
-
const mondaySns = require('@mondaydotcomorg/monday-sns');
|
|
5
|
-
const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
|
|
6
|
-
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
7
|
-
const constants_sns = require('./constants/sns.js');
|
|
8
|
-
|
|
9
|
-
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
10
|
-
|
|
11
|
-
const chunk__default = /*#__PURE__*/_interopDefault(chunk);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Service class for managing resource attributes asynchronously via SNS.
|
|
15
|
-
* Provides asynchronous operations to create/update and delete attributes on resources.
|
|
16
|
-
*/
|
|
17
|
-
class AuthorizationAttributesSnsService {
|
|
18
|
-
static LOG_TAG = 'authorization_attributes';
|
|
19
|
-
resourceSnsArn;
|
|
20
|
-
entitySnsArn;
|
|
21
|
-
/**
|
|
22
|
-
* Public constructor to create the AuthorizationAttributesSnsService instance.
|
|
23
|
-
*/
|
|
24
|
-
constructor() {
|
|
25
|
-
this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(constants_sns.SnsTopicType.RESOURCE);
|
|
26
|
-
this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(constants_sns.SnsTopicType.ENTITY);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Async function to upsert resource attributes using SNS.
|
|
30
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
31
|
-
* @param accountId The account ID
|
|
32
|
-
* @param appName App name of the calling app
|
|
33
|
-
* @param callerActionIdentifier Action identifier
|
|
34
|
-
* @param resourceAttributeAssignments Array of resource attribute assignments to upsert
|
|
35
|
-
* @return Promise with array of sent operations
|
|
36
|
-
*/
|
|
37
|
-
async upsertResourceAttributes(accountId, resourceAttributeAssignments, appName, callerActionIdentifier) {
|
|
38
|
-
if (!appName || !callerActionIdentifier) {
|
|
39
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
40
|
-
}
|
|
41
|
-
const operations = resourceAttributeAssignments.map(assignment => ({
|
|
42
|
-
...assignment,
|
|
43
|
-
operationType: types_authorizationAttributesContracts.AttributeOperation.UPSERT,
|
|
44
|
-
}));
|
|
45
|
-
return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Async function to delete resource attributes using SNS.
|
|
49
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
50
|
-
* @param accountId The account ID
|
|
51
|
-
* @param appName App name of the calling app
|
|
52
|
-
* @param callerActionIdentifier Action identifier
|
|
53
|
-
* @param resource The resource (resourceType, resourceId)
|
|
54
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
55
|
-
* @return Promise with array of sent operations
|
|
56
|
-
*/
|
|
57
|
-
async deleteResourceAttributes(accountId, resource, attributeKeys, appName, callerActionIdentifier) {
|
|
58
|
-
if (!appName || !callerActionIdentifier) {
|
|
59
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
60
|
-
}
|
|
61
|
-
const operations = attributeKeys.map(key => ({
|
|
62
|
-
resourceType: resource.type,
|
|
63
|
-
resourceId: resource.id,
|
|
64
|
-
key,
|
|
65
|
-
operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
|
|
66
|
-
}));
|
|
67
|
-
return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Async function to upsert entity 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 entityAttributeAssignments Array of entity attribute assignments to upsert
|
|
76
|
-
* @return Promise with array of sent operations
|
|
77
|
-
*/
|
|
78
|
-
async upsertEntityAttributes(accountId, entityAttributeAssignments, appName, callerActionIdentifier) {
|
|
79
|
-
if (!appName || !callerActionIdentifier) {
|
|
80
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
81
|
-
}
|
|
82
|
-
const operations = entityAttributeAssignments.map(assignment => {
|
|
83
|
-
return {
|
|
84
|
-
entityId: assignment.entityId,
|
|
85
|
-
entityType: assignment.entityType,
|
|
86
|
-
key: assignment.attributeKey,
|
|
87
|
-
value: assignment.attributeValue,
|
|
88
|
-
operationType: types_authorizationAttributesContracts.AttributeOperation.UPSERT,
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Async function to delete entity attributes using SNS.
|
|
95
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
96
|
-
* @param accountId The account ID
|
|
97
|
-
* @param appName App name of the calling app
|
|
98
|
-
* @param callerActionIdentifier Action identifier
|
|
99
|
-
* @param entityType The entity type
|
|
100
|
-
* @param entityId The entity ID
|
|
101
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
102
|
-
* @return Promise with array of sent operations
|
|
103
|
-
*/
|
|
104
|
-
async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, appName, callerActionIdentifier) {
|
|
105
|
-
if (!appName || !callerActionIdentifier) {
|
|
106
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
107
|
-
}
|
|
108
|
-
const operations = attributeKeys.map(key => ({
|
|
109
|
-
entityType: entityType,
|
|
110
|
-
entityId,
|
|
111
|
-
key,
|
|
112
|
-
operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
|
|
113
|
-
}));
|
|
114
|
-
return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
118
|
-
* @param accountId
|
|
119
|
-
* @param appName - App name of the calling app
|
|
120
|
-
* @param callerActionIdentifier - action identifier
|
|
121
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
122
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
123
|
-
* */
|
|
124
|
-
async updateResourceAttributes(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
|
|
125
|
-
const topicArn = this.resourceSnsArn;
|
|
126
|
-
const sendToSnsPromises = [];
|
|
127
|
-
const operationChucks = chunk__default.default(resourceAttributeOperations, constants_sns.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
128
|
-
for (const operationsChunk of operationChucks) {
|
|
129
|
-
sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, constants_sns.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization resource attributes async update: failed to send operations to SNS'));
|
|
130
|
-
}
|
|
131
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
135
|
-
* @param accountId
|
|
136
|
-
* @param appName - App name of the calling app
|
|
137
|
-
* @param callerActionIdentifier - action identifier
|
|
138
|
-
* @param entityAttributeOperations - Array of operations to do on entity attributes.
|
|
139
|
-
* @return {Promise<EntityAttributeOperation[]>} Array of sent operations
|
|
140
|
-
* */
|
|
141
|
-
async updateEntityAttributes(accountId, appName, callerActionIdentifier, entityAttributeOperations) {
|
|
142
|
-
const topicArn = this.entitySnsArn;
|
|
143
|
-
const sendToSnsPromises = [];
|
|
144
|
-
const operationChucks = chunk__default.default(entityAttributeOperations, constants_sns.ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
145
|
-
for (const operationsChunk of operationChucks) {
|
|
146
|
-
sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, constants_sns.ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization entity attributes async update: failed to send operations to SNS'));
|
|
147
|
-
}
|
|
148
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
149
|
-
}
|
|
150
|
-
async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations, kind, errorLogMessage) {
|
|
151
|
-
const payload = {
|
|
152
|
-
kind,
|
|
153
|
-
payload: {
|
|
154
|
-
accountId: accountId,
|
|
155
|
-
callerAppName: appName,
|
|
156
|
-
callerActionIdentifier: callerActionIdentifier,
|
|
157
|
-
operations: operations,
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
try {
|
|
161
|
-
await mondaySns.sendToSns(payload, topicArn);
|
|
162
|
-
return operations;
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
static getSnsTopicArn(type) {
|
|
170
|
-
let envVarName;
|
|
171
|
-
let devTestName;
|
|
172
|
-
switch (type) {
|
|
173
|
-
case constants_sns.SnsTopicType.ENTITY:
|
|
174
|
-
envVarName = constants_sns.ENTITY_SNS_ARN_ENV_VAR_NAME;
|
|
175
|
-
devTestName = constants_sns.ENTITY_SNS_DEV_TEST_NAME;
|
|
176
|
-
break;
|
|
177
|
-
default:
|
|
178
|
-
// Default to resource SNS constants
|
|
179
|
-
envVarName = constants_sns.RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
180
|
-
devTestName = constants_sns.RESOURCE_SNS_DEV_TEST_NAME;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
const arnFromEnv = process.env[envVarName];
|
|
184
|
-
if (arnFromEnv) {
|
|
185
|
-
return arnFromEnv;
|
|
186
|
-
}
|
|
187
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
188
|
-
return devTestName;
|
|
189
|
-
}
|
|
190
|
-
throw new Error(`Unable to get ${type} sns topic arn from env variable`);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
194
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
195
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
196
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
197
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
198
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
199
|
-
*/
|
|
200
|
-
async asyncResourceAttributesHealthCheck() {
|
|
201
|
-
try {
|
|
202
|
-
const requestedTopicArn = this.resourceSnsArn;
|
|
203
|
-
const attributes = await mondaySns.getTopicAttributes(requestedTopicArn);
|
|
204
|
-
const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
|
|
205
|
-
if (!isHealthy) {
|
|
206
|
-
authorizationInternalService.logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service failed in health check');
|
|
207
|
-
}
|
|
208
|
-
return isHealthy;
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service got error during health check');
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
exports.AuthorizationAttributesSnsService = AuthorizationAttributesSnsService;
|