@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,68 @@
|
|
|
1
|
+
import { ResourceAttributeUpsertOperation, ResourceAttributeDeleteOperation, EntityAttributeUpsertOperation, EntityAttributeDeleteOperation } from './types/authorization-attributes-contracts';
|
|
2
|
+
import { EntityType } from './entity-attributes-constants';
|
|
3
|
+
import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
4
|
+
import { Resource } from './types/general';
|
|
5
|
+
/**
|
|
6
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
7
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AuthorizationAttributesMsService implements AuthorizationAttributesService {
|
|
10
|
+
private static LOG_TAG;
|
|
11
|
+
private static httpClient;
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Deletes a specific attribute from a resource synchronously.
|
|
15
|
+
* @param accountId The account ID
|
|
16
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
17
|
+
* @param attributeKey Attribute key string to delete
|
|
18
|
+
* @returns Promise<ResourceAttributeDeleteOperation>
|
|
19
|
+
*/
|
|
20
|
+
deleteResourceAttributes(accountId: number, resource: Resource, attributeKey: string, _appName?: string, _callerActionIdentifier?: string): Promise<ResourceAttributeDeleteOperation>;
|
|
21
|
+
/**
|
|
22
|
+
* Deletes a specific attribute from an entity synchronously.
|
|
23
|
+
* @param accountId The account ID
|
|
24
|
+
* @param entityType The entity type
|
|
25
|
+
* @param entityId The entity ID
|
|
26
|
+
* @param attributeKey Attribute key string to delete
|
|
27
|
+
* @returns Promise<EntityAttributeDeleteOperation>
|
|
28
|
+
*/
|
|
29
|
+
deleteEntityAttributes(accountId: number, entityType: EntityType, entityId: number, attributeKey: string, _appName?: string, _callerActionIdentifier?: string): Promise<EntityAttributeDeleteOperation>;
|
|
30
|
+
/**
|
|
31
|
+
* Updates a resource attribute (single operation - upsert only).
|
|
32
|
+
* @param accountId The account ID
|
|
33
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
34
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
35
|
+
* @param resourceAttributeOperation Operation to perform (must be UPSERT)
|
|
36
|
+
* @returns Promise<ResourceAttributeUpsertOperation> Processed operation
|
|
37
|
+
*/
|
|
38
|
+
updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperation: ResourceAttributeUpsertOperation): Promise<ResourceAttributeUpsertOperation>;
|
|
39
|
+
/**
|
|
40
|
+
* Updates an entity attribute (single operation - upsert only).
|
|
41
|
+
* @param accountId The account ID
|
|
42
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
43
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
44
|
+
* @param entityAttributeOperation Operation to perform (must be UPSERT)
|
|
45
|
+
* @returns Promise<EntityAttributeUpsertOperation> Processed operation
|
|
46
|
+
*/
|
|
47
|
+
updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperation: EntityAttributeUpsertOperation): Promise<EntityAttributeUpsertOperation>;
|
|
48
|
+
/**
|
|
49
|
+
* Replaces path template parameters with actual values
|
|
50
|
+
* @param template Path template with placeholders like {accountId}
|
|
51
|
+
* @param params Object with parameter names and values
|
|
52
|
+
* @returns Path with all placeholders replaced
|
|
53
|
+
*/
|
|
54
|
+
private static replacePathParams;
|
|
55
|
+
/**
|
|
56
|
+
* Generic helper for executing delete requests
|
|
57
|
+
*/
|
|
58
|
+
private static executeDeleteRequest;
|
|
59
|
+
/**
|
|
60
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
61
|
+
*/
|
|
62
|
+
private static getRequestHeaders;
|
|
63
|
+
/**
|
|
64
|
+
* Generic helper for executing upsert requests
|
|
65
|
+
*/
|
|
66
|
+
private static executeUpsertRequest;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=authorization-attributes-ms-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,gCAAgC,EAChC,gCAAgC,EAChC,8BAA8B,EAC9B,8BAA8B,EAC/B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAK3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oDAAoD,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,8BAA8B;IACrF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqD;;IAW9E;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,gCAAgC,CAAC;IA0B5C;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,8BAA8B,CAAC;IAqB1C;;;;;;;OAOG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,0BAA0B,EAAE,gCAAgC,GAC3D,OAAO,CAAC,gCAAgC,CAAC;IA0B5C;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,wBAAwB,EAAE,8BAA8B,GACvD,OAAO,CAAC,8BAA8B,CAAC;IA4B1C;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;OAEG;mBACkB,oBAAoB;IAiEzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;mBACkB,oBAAoB;CA4D1C"}
|
|
@@ -0,0 +1,263 @@
|
|
|
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 resourceAttributeAssignment = require('./resource-attribute-assignment.js');
|
|
6
|
+
const entityAttributeAssignment = require('./entity-attribute-assignment.js');
|
|
7
|
+
const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
|
|
8
|
+
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
9
|
+
const attributionsService = require('./attributions-service.js');
|
|
10
|
+
const constants = require('./constants.js');
|
|
11
|
+
const utils_validation = require('./utils/validation.js');
|
|
12
|
+
|
|
13
|
+
const INTERNAL_APP_NAME = 'internal_ms';
|
|
14
|
+
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
15
|
+
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
16
|
+
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
17
|
+
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
18
|
+
/**
|
|
19
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
20
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
21
|
+
*/
|
|
22
|
+
class AuthorizationAttributesMsService {
|
|
23
|
+
static LOG_TAG = 'authorization_attributes_ms';
|
|
24
|
+
static httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
25
|
+
constructor() {
|
|
26
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
27
|
+
AuthorizationAttributesMsService.httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
28
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
29
|
+
throw new Error('HTTP client is not initialized');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a specific attribute from a resource synchronously.
|
|
35
|
+
* @param accountId The account ID
|
|
36
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
37
|
+
* @param attributeKey Attribute key string to delete
|
|
38
|
+
* @returns Promise<ResourceAttributeDeleteOperation>
|
|
39
|
+
*/
|
|
40
|
+
async deleteResourceAttributes(accountId, resource, attributeKey, _appName, _callerActionIdentifier) {
|
|
41
|
+
utils_validation.ValidationUtils.validateResource(resource);
|
|
42
|
+
utils_validation.ValidationUtils.validatDeleteResourceAssignment({
|
|
43
|
+
resourceType: resource.type,
|
|
44
|
+
resourceId: resource.id,
|
|
45
|
+
key: attributeKey,
|
|
46
|
+
});
|
|
47
|
+
await AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
48
|
+
resourceType: resource.type,
|
|
49
|
+
resourceId: resource.id,
|
|
50
|
+
}, [attributeKey], 'resource', 'deleteResourceAttributesSync');
|
|
51
|
+
return {
|
|
52
|
+
resourceType: resource.type,
|
|
53
|
+
resourceId: resource.id,
|
|
54
|
+
key: attributeKey,
|
|
55
|
+
operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Deletes a specific attribute from an entity synchronously.
|
|
60
|
+
* @param accountId The account ID
|
|
61
|
+
* @param entityType The entity type
|
|
62
|
+
* @param entityId The entity ID
|
|
63
|
+
* @param attributeKey Attribute key string to delete
|
|
64
|
+
* @returns Promise<EntityAttributeDeleteOperation>
|
|
65
|
+
*/
|
|
66
|
+
async deleteEntityAttributes(accountId, entityType, entityId, attributeKey, _appName, _callerActionIdentifier) {
|
|
67
|
+
utils_validation.ValidationUtils.validateInteger(accountId);
|
|
68
|
+
await AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
69
|
+
entityType,
|
|
70
|
+
entityId,
|
|
71
|
+
}, [attributeKey], 'entity', 'deleteEntityAttributesSync');
|
|
72
|
+
return {
|
|
73
|
+
entityType,
|
|
74
|
+
entityId,
|
|
75
|
+
key: attributeKey,
|
|
76
|
+
operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Updates a resource attribute (single operation - upsert only).
|
|
81
|
+
* @param accountId The account ID
|
|
82
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
83
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
84
|
+
* @param resourceAttributeOperation Operation to perform (must be UPSERT)
|
|
85
|
+
* @returns Promise<ResourceAttributeUpsertOperation> Processed operation
|
|
86
|
+
*/
|
|
87
|
+
async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperation) {
|
|
88
|
+
utils_validation.ValidationUtils.validatUpsertResourceAssignment({
|
|
89
|
+
resourceId: resourceAttributeOperation.resourceId,
|
|
90
|
+
resourceType: resourceAttributeOperation.resourceType,
|
|
91
|
+
key: resourceAttributeOperation.key,
|
|
92
|
+
value: resourceAttributeOperation.value,
|
|
93
|
+
});
|
|
94
|
+
await AuthorizationAttributesMsService.executeUpsertRequest(accountId, [
|
|
95
|
+
new resourceAttributeAssignment.ResourceAttributeAssignment(resourceAttributeOperation.resourceId, resourceAttributeOperation.resourceType, resourceAttributeOperation.key, resourceAttributeOperation.value || ''),
|
|
96
|
+
], UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', 'resource', 'updateResourceAttributesSync');
|
|
97
|
+
return resourceAttributeOperation;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Updates an entity attribute (single operation - upsert only).
|
|
101
|
+
* @param accountId The account ID
|
|
102
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
103
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
104
|
+
* @param entityAttributeOperation Operation to perform (must be UPSERT)
|
|
105
|
+
* @returns Promise<EntityAttributeUpsertOperation> Processed operation
|
|
106
|
+
*/
|
|
107
|
+
async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperation) {
|
|
108
|
+
// Validate before processing
|
|
109
|
+
utils_validation.ValidationUtils.validatUpsertEntityAssignment({
|
|
110
|
+
entityId: entityAttributeOperation.entityId,
|
|
111
|
+
entityType: entityAttributeOperation.entityType,
|
|
112
|
+
key: entityAttributeOperation.key,
|
|
113
|
+
value: entityAttributeOperation.value,
|
|
114
|
+
});
|
|
115
|
+
await AuthorizationAttributesMsService.executeUpsertRequest(accountId, [
|
|
116
|
+
new entityAttributeAssignment.EntityAttributeAssignment(entityAttributeOperation.entityId, entityAttributeOperation.entityType, entityAttributeOperation.key, entityAttributeOperation.value),
|
|
117
|
+
], UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', 'entity', 'upsertEntityAttributesSync');
|
|
118
|
+
return entityAttributeOperation;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Replaces path template parameters with actual values
|
|
122
|
+
* @param template Path template with placeholders like {accountId}
|
|
123
|
+
* @param params Object with parameter names and values
|
|
124
|
+
* @returns Path with all placeholders replaced
|
|
125
|
+
*/
|
|
126
|
+
static replacePathParams(template, params) {
|
|
127
|
+
let path = template;
|
|
128
|
+
for (const [key, value] of Object.entries(params)) {
|
|
129
|
+
path = path.replace(`{${key}}`, String(value));
|
|
130
|
+
}
|
|
131
|
+
return path;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generic helper for executing delete requests
|
|
135
|
+
*/
|
|
136
|
+
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName) {
|
|
137
|
+
// Validate inputs
|
|
138
|
+
utils_validation.ValidationUtils.validateInteger(accountId);
|
|
139
|
+
utils_validation.ValidationUtils.validateStringArray(keys);
|
|
140
|
+
if (!keys.length) {
|
|
141
|
+
authorizationInternalService.logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const requestBody = { keys };
|
|
145
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
146
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
147
|
+
}
|
|
148
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
149
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
150
|
+
try {
|
|
151
|
+
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
152
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
153
|
+
url: {
|
|
154
|
+
appName: constants.APP_NAME,
|
|
155
|
+
path,
|
|
156
|
+
},
|
|
157
|
+
method: 'DELETE',
|
|
158
|
+
headers,
|
|
159
|
+
body: JSON.stringify(requestBody),
|
|
160
|
+
}, {
|
|
161
|
+
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
162
|
+
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
163
|
+
});
|
|
164
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
authorizationInternalService.logger.error({
|
|
168
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
169
|
+
method: methodName,
|
|
170
|
+
accountId,
|
|
171
|
+
...pathParams,
|
|
172
|
+
error: err instanceof Error ? err.message : String(err),
|
|
173
|
+
}, `Failed in ${methodName}`);
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
179
|
+
*/
|
|
180
|
+
static getRequestHeaders(accountId, userId) {
|
|
181
|
+
const headers = {
|
|
182
|
+
'Content-Type': 'application/json',
|
|
183
|
+
};
|
|
184
|
+
// Generate Authorization token
|
|
185
|
+
const authToken = mondayJwt.signAuthorizationHeader({
|
|
186
|
+
appName: INTERNAL_APP_NAME,
|
|
187
|
+
accountId,
|
|
188
|
+
userId,
|
|
189
|
+
});
|
|
190
|
+
headers.Authorization = authToken;
|
|
191
|
+
// Add attribution headers if available
|
|
192
|
+
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
193
|
+
for (const key in attributionHeaders) {
|
|
194
|
+
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
195
|
+
headers[key] = attributionHeaders[key];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Add X-REQUEST-ID if available from context
|
|
199
|
+
try {
|
|
200
|
+
const tridentContext = tridentBackendApi.Api.getPart('context');
|
|
201
|
+
if (tridentContext?.runtimeAttributions) {
|
|
202
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
203
|
+
if (outgoingHeaders) {
|
|
204
|
+
const attributionHeadersMap = {};
|
|
205
|
+
for (const [key, value] of outgoingHeaders) {
|
|
206
|
+
attributionHeadersMap[key] = value;
|
|
207
|
+
}
|
|
208
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
209
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
// Silently fail if context is not available
|
|
216
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
217
|
+
}
|
|
218
|
+
// Add X-REQUEST-START timestamp
|
|
219
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
220
|
+
return headers;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Generic helper for executing upsert requests
|
|
224
|
+
*/
|
|
225
|
+
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, logPrefix, methodName) {
|
|
226
|
+
const assignmentDto = assignments.map(assignment => assignment.toDataTransferObject());
|
|
227
|
+
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
228
|
+
? { resourceAttributeAssignments: assignmentDto }
|
|
229
|
+
: { entityAttributeAssignments: assignmentDto };
|
|
230
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
231
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
232
|
+
}
|
|
233
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
|
|
234
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
235
|
+
try {
|
|
236
|
+
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
237
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
238
|
+
url: {
|
|
239
|
+
appName: constants.APP_NAME,
|
|
240
|
+
path,
|
|
241
|
+
},
|
|
242
|
+
method: 'POST',
|
|
243
|
+
headers,
|
|
244
|
+
body: JSON.stringify(requestBody),
|
|
245
|
+
}, {
|
|
246
|
+
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
247
|
+
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
248
|
+
});
|
|
249
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
authorizationInternalService.logger.error({
|
|
253
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
254
|
+
method: methodName,
|
|
255
|
+
accountId,
|
|
256
|
+
error: err instanceof Error ? err.message : String(err),
|
|
257
|
+
}, `Failed in ${methodName}`);
|
|
258
|
+
throw err;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
|
|
@@ -1,54 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AuthorizationAttributesService as IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Main service class for managing resource and entity attributes.
|
|
4
|
+
* Provides access to both direct (MS) and SNS operations.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const service = new AuthorizationAttributesService();
|
|
8
|
+
*
|
|
9
|
+
* // Use direct operations
|
|
10
|
+
* await service.direct().upsertResourceAttributes(accountId, assignments);
|
|
11
|
+
*
|
|
12
|
+
* // Use SNS operations
|
|
13
|
+
* await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
5
16
|
export declare class AuthorizationAttributesService {
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private httpClient;
|
|
9
|
-
private fetchOptions;
|
|
10
|
-
private snsArn;
|
|
17
|
+
private _directService;
|
|
18
|
+
private _snsService;
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
20
|
+
* Gets the direct (MS) service instance.
|
|
21
|
+
* Initializes the service on first access (lazy initialization).
|
|
22
|
+
* @returns IAuthorizationAttributesService instance
|
|
15
23
|
*/
|
|
16
|
-
|
|
24
|
+
direct(): IAuthorizationAttributesService;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
|
|
22
|
-
* @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
|
|
26
|
+
* Gets the SNS service instance.
|
|
27
|
+
* Initializes the service on first access (lazy initialization).
|
|
28
|
+
* @returns IAuthorizationAttributesService instance
|
|
23
29
|
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
|
|
27
|
-
* @param accountId
|
|
28
|
-
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
29
|
-
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
30
|
-
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
31
|
-
*/
|
|
32
|
-
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[]): Promise<ResourceAttributeResponse>;
|
|
33
|
-
/**
|
|
34
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
35
|
-
* @param accountId
|
|
36
|
-
* @param appName - App name of the calling app
|
|
37
|
-
* @param callerActionIdentifier - action identifier
|
|
38
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
39
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
40
|
-
* */
|
|
41
|
-
updateResourceAttributesAsync(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeUpsertOperation[]): Promise<ResourceAttributeUpsertOperation[]>;
|
|
42
|
-
private sendSingleSnsMessage;
|
|
43
|
-
private static getSnsTopicArn;
|
|
44
|
-
/**
|
|
45
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
46
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
47
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
48
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
49
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
50
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
51
|
-
*/
|
|
52
|
-
asyncResourceAttributesHealthCheck(): Promise<boolean>;
|
|
30
|
+
sns(): IAuthorizationAttributesService;
|
|
53
31
|
}
|
|
54
32
|
//# sourceMappingURL=authorization-attributes-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,IAAI,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAEvI;;;;;;;;;;;;;GAaG;AACH,qBAAa,8BAA8B;IACzC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,WAAW,CAAkD;IAErE;;;;OAIG;IACH,MAAM,IAAI,+BAA+B;IAOzC;;;;OAIG;IACH,GAAG,IAAI,+BAA+B;CAMvC"}
|
|
@@ -1,185 +1,46 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const mondaySns = require('@mondaydotcomorg/monday-sns');
|
|
6
|
-
const mondayFetchApi = require('@mondaydotcomorg/monday-fetch-api');
|
|
7
|
-
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
8
|
-
const attributionsService = require('./attributions-service.js');
|
|
9
|
-
const constants_sns = require('./constants/sns.js');
|
|
10
|
-
const constants = require('./constants.js');
|
|
11
|
-
|
|
12
|
-
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
13
|
-
|
|
14
|
-
const chunk__default = /*#__PURE__*/_interopDefault(chunk);
|
|
3
|
+
const authorizationAttributesMsService = require('./authorization-attributes-ms-service.js');
|
|
4
|
+
const authorizationAttributesSnsService = require('./authorization-attributes-sns-service.js');
|
|
15
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Main service class for managing resource and entity attributes.
|
|
8
|
+
* Provides access to both direct (MS) and SNS operations.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const service = new AuthorizationAttributesService();
|
|
12
|
+
*
|
|
13
|
+
* // Use direct operations
|
|
14
|
+
* await service.direct().upsertResourceAttributes(accountId, assignments);
|
|
15
|
+
*
|
|
16
|
+
* // Use SNS operations
|
|
17
|
+
* await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
16
20
|
class AuthorizationAttributesService {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
UPSERT_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource',
|
|
20
|
-
DELETE_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource/{resourceType}/{resourceId}',
|
|
21
|
-
};
|
|
22
|
-
httpClient;
|
|
23
|
-
fetchOptions;
|
|
24
|
-
snsArn;
|
|
21
|
+
_directService = null;
|
|
22
|
+
_snsService = null;
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
24
|
+
* Gets the direct (MS) service instance.
|
|
25
|
+
* Initializes the service on first access (lazy initialization).
|
|
26
|
+
* @returns IAuthorizationAttributesService instance
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
if (!httpClient) {
|
|
34
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (!fetchOptions) {
|
|
38
|
-
fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
fetchOptions = {
|
|
42
|
-
...constants.DEFAULT_FETCH_OPTIONS,
|
|
43
|
-
...fetchOptions,
|
|
44
|
-
};
|
|
28
|
+
direct() {
|
|
29
|
+
if (this._directService === null) {
|
|
30
|
+
this._directService = new authorizationAttributesMsService.AuthorizationAttributesMsService();
|
|
45
31
|
}
|
|
46
|
-
this.
|
|
47
|
-
this.fetchOptions = fetchOptions;
|
|
48
|
-
this.snsArn = AuthorizationAttributesService.getSnsTopicArn();
|
|
32
|
+
return this._directService;
|
|
49
33
|
}
|
|
50
34
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
54
|
-
* e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
|
|
55
|
-
* @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
|
|
35
|
+
* Gets the SNS service instance.
|
|
36
|
+
* Initializes the service on first access (lazy initialization).
|
|
37
|
+
* @returns IAuthorizationAttributesService instance
|
|
56
38
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return await this.httpClient.fetch({
|
|
61
|
-
url: {
|
|
62
|
-
appName: constants.APP_NAME,
|
|
63
|
-
path: AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
64
|
-
},
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers: {
|
|
67
|
-
'Content-Type': 'application/json',
|
|
68
|
-
...attributionHeaders,
|
|
69
|
-
},
|
|
70
|
-
body: JSON.stringify({ resourceAttributeAssignments }),
|
|
71
|
-
}, this.fetchOptions);
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
75
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributes', err.status, err.message));
|
|
76
|
-
}
|
|
77
|
-
throw err;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
|
|
82
|
-
* @param accountId
|
|
83
|
-
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
84
|
-
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
85
|
-
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
86
|
-
*/
|
|
87
|
-
async deleteResourceAttributes(accountId, resource, attributeKeys) {
|
|
88
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
89
|
-
if (!resource.id) {
|
|
90
|
-
throw new Error('Resource ID is required');
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
return await this.httpClient.fetch({
|
|
94
|
-
url: {
|
|
95
|
-
appName: constants.APP_NAME,
|
|
96
|
-
path: AuthorizationAttributesService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString())
|
|
97
|
-
.replace('{resourceType}', resource.type)
|
|
98
|
-
.replace('{resourceId}', resource.id.toString()),
|
|
99
|
-
},
|
|
100
|
-
method: 'DELETE',
|
|
101
|
-
headers: {
|
|
102
|
-
'Content-Type': 'application/json',
|
|
103
|
-
...attributionHeaders,
|
|
104
|
-
},
|
|
105
|
-
body: JSON.stringify({ keys: attributeKeys }),
|
|
106
|
-
}, this.fetchOptions);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
110
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('deleteResourceAttributes', err.status, err.message));
|
|
111
|
-
}
|
|
112
|
-
throw err;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
117
|
-
* @param accountId
|
|
118
|
-
* @param appName - App name of the calling app
|
|
119
|
-
* @param callerActionIdentifier - action identifier
|
|
120
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
121
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
122
|
-
* */
|
|
123
|
-
async updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
|
|
124
|
-
const topicArn = this.snsArn;
|
|
125
|
-
const sendToSnsPromises = [];
|
|
126
|
-
const operationChucks = chunk__default.default(resourceAttributeOperations, constants_sns.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
127
|
-
for (const operationsChunk of operationChucks) {
|
|
128
|
-
sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
|
|
129
|
-
}
|
|
130
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
131
|
-
}
|
|
132
|
-
async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
|
|
133
|
-
const payload = {
|
|
134
|
-
kind: constants_sns.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
135
|
-
payload: {
|
|
136
|
-
accountId: accountId,
|
|
137
|
-
callerAppName: appName,
|
|
138
|
-
callerActionIdentifier: callerActionIdentifier,
|
|
139
|
-
operations: operations,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
try {
|
|
143
|
-
await mondaySns.sendToSns(payload, topicArn);
|
|
144
|
-
return operations;
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'Authorization resource attributes async update: failed to send operations to SNS');
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
static getSnsTopicArn() {
|
|
152
|
-
const arnFromEnv = process.env[constants_sns.SNS_ARN_ENV_VAR_NAME];
|
|
153
|
-
if (arnFromEnv) {
|
|
154
|
-
return arnFromEnv;
|
|
155
|
-
}
|
|
156
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
157
|
-
return constants_sns.SNS_DEV_TEST_NAME;
|
|
158
|
-
}
|
|
159
|
-
throw new Error('Unable to get sns topic arn from env variable');
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
163
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
164
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
165
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
166
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
167
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
168
|
-
*/
|
|
169
|
-
async asyncResourceAttributesHealthCheck() {
|
|
170
|
-
try {
|
|
171
|
-
const requestedTopicArn = this.snsArn;
|
|
172
|
-
const attributes = await mondaySns.getTopicAttributes(requestedTopicArn);
|
|
173
|
-
const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
|
|
174
|
-
if (!isHealthy) {
|
|
175
|
-
authorizationInternalService.logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service failed in health check');
|
|
176
|
-
}
|
|
177
|
-
return isHealthy;
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service got error during health check');
|
|
181
|
-
return false;
|
|
39
|
+
sns() {
|
|
40
|
+
if (this._snsService === null) {
|
|
41
|
+
this._snsService = new authorizationAttributesSnsService.AuthorizationAttributesSnsService();
|
|
182
42
|
}
|
|
43
|
+
return this._snsService;
|
|
183
44
|
}
|
|
184
45
|
}
|
|
185
46
|
|