@adobe/spacecat-shared-data-access 1.41.2 → 1.41.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/dto/api-key.js +2 -2
- package/src/index.d.ts +4 -4
- package/src/index.js +3 -3
- package/src/models/api-key.js +3 -3
- package/src/service/api-key/accessPatterns.js +9 -8
- package/src/service/api-key/index.js +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.41.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.41.2...@adobe/spacecat-shared-data-access-v1.41.3) (2024-08-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* refactor hashed api key and query to retrieve API key ([#325](https://github.com/adobe/spacecat-shared/issues/325)) ([a99fc76](https://github.com/adobe/spacecat-shared/commit/a99fc76963fdcd6bce8de7d5b315dbefbb03fd95))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-data-access-v1.41.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.41.1...@adobe/spacecat-shared-data-access-v1.41.2) (2024-08-14)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/dto/api-key.js
CHANGED
|
@@ -21,7 +21,7 @@ export const ApiKeyDto = {
|
|
|
21
21
|
* imsOrgId: *, expiresAt: *}}
|
|
22
22
|
*/
|
|
23
23
|
toDynamoItem: (apiKey) => ({
|
|
24
|
-
|
|
24
|
+
hashedApiKey: apiKey.getHashedApiKey(),
|
|
25
25
|
name: apiKey.getName(),
|
|
26
26
|
imsUserId: apiKey.getImsUserId(),
|
|
27
27
|
imsOrgId: apiKey.getImsOrgId(),
|
|
@@ -38,7 +38,7 @@ export const ApiKeyDto = {
|
|
|
38
38
|
*/
|
|
39
39
|
fromDynamoItem: (dynamoItem) => {
|
|
40
40
|
const apiKeyData = {
|
|
41
|
-
|
|
41
|
+
hashedApiKey: dynamoItem.hashedApiKey,
|
|
42
42
|
name: dynamoItem.name,
|
|
43
43
|
imsUserId: dynamoItem.imsUserId,
|
|
44
44
|
imsOrgId: dynamoItem.imsOrgId,
|
package/src/index.d.ts
CHANGED
|
@@ -546,7 +546,7 @@ export interface ApiKey {
|
|
|
546
546
|
/**
|
|
547
547
|
* Retrieves the hashed key value of the API Key.
|
|
548
548
|
*/
|
|
549
|
-
|
|
549
|
+
getHashedApiKey: () => string;
|
|
550
550
|
|
|
551
551
|
/**
|
|
552
552
|
* Retrieves the name of the API Key.
|
|
@@ -773,8 +773,8 @@ export interface DataAccess {
|
|
|
773
773
|
jobId: string,
|
|
774
774
|
status: string,
|
|
775
775
|
) => Promise<ImportUrl[]>;
|
|
776
|
-
|
|
777
|
-
|
|
776
|
+
getApiKeyByHashedApiKey: (
|
|
777
|
+
hashedApiKey: string,
|
|
778
778
|
) => Promise<ApiKey | null>;
|
|
779
779
|
createNewApiKey: (
|
|
780
780
|
apiKeyData: object,
|
|
@@ -832,7 +832,7 @@ interface DataAccessConfig {
|
|
|
832
832
|
indexNameAllImportJobsByStatus: string,
|
|
833
833
|
indexNameAllImportJobsByDateRange: string,
|
|
834
834
|
indexNameAllImportUrlsByJobIdAndStatus: string,
|
|
835
|
-
|
|
835
|
+
indexNameApiKeyByHashedApiKey: string,
|
|
836
836
|
pkAllSites: string;
|
|
837
837
|
pkAllLatestAudits: string;
|
|
838
838
|
pkAllOrganizations: string;
|
package/src/index.js
CHANGED
|
@@ -37,7 +37,7 @@ const INDEX_NAME_ALL_SITES_ORGANIZATIONS = 'spacecat-services-all-sites-organiza
|
|
|
37
37
|
const INDEX_NAME_ALL_IMPORT_JOBS_BY_STATUS = 'spacecat-services-all-import-jobs-by-status-dev';
|
|
38
38
|
const INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE = 'spacecat-services-all-import-jobs-by-date-range-dev';
|
|
39
39
|
const INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS = 'spacecat-services-all-import-urls-by-job-id-and-status-dev';
|
|
40
|
-
const
|
|
40
|
+
const INDEX_NAME_API_KEY_BY_HASHED_API_KEY = 'spacecat-services-api-key-by-hashed-api-key-dev';
|
|
41
41
|
|
|
42
42
|
const PK_ALL_SITES = 'ALL_SITES';
|
|
43
43
|
const PK_ALL_CONFIGURATIONS = 'ALL_CONFIGURATIONS';
|
|
@@ -75,7 +75,7 @@ export default function dataAccessWrapper(fn) {
|
|
|
75
75
|
DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE = INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE,
|
|
76
76
|
DYNAMO_INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS =
|
|
77
77
|
INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS,
|
|
78
|
-
|
|
78
|
+
DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_API_KEY = INDEX_NAME_API_KEY_BY_HASHED_API_KEY,
|
|
79
79
|
} = context.env;
|
|
80
80
|
|
|
81
81
|
context.dataAccess = createDataAccess({
|
|
@@ -101,7 +101,7 @@ export default function dataAccessWrapper(fn) {
|
|
|
101
101
|
indexNameAllImportJobsByStatus: DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_STATUS,
|
|
102
102
|
indexNameAllImportJobsByDateRange: DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE,
|
|
103
103
|
indexNameImportUrlsByJobIdAndStatus: DYNAMO_INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS,
|
|
104
|
-
|
|
104
|
+
indexNameApiKeyByHashedApiKey: DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_API_KEY,
|
|
105
105
|
pkAllSites: PK_ALL_SITES,
|
|
106
106
|
pkAllOrganizations: PK_ALL_ORGANIZATIONS,
|
|
107
107
|
pkAllLatestAudits: PK_ALL_LATEST_AUDITS,
|
package/src/models/api-key.js
CHANGED
|
@@ -21,7 +21,7 @@ const scopeNames = ['sites.read_all', 'sites.write_all', 'organizations.read_all
|
|
|
21
21
|
const ApiKey = (data) => {
|
|
22
22
|
const self = Base(data);
|
|
23
23
|
|
|
24
|
-
self.
|
|
24
|
+
self.getHashedApiKey = () => self.state.hashedApiKey;
|
|
25
25
|
self.getName = () => self.state.name;
|
|
26
26
|
self.getImsUserId = () => self.state.imsUserId;
|
|
27
27
|
self.getImsOrgId = () => self.state.imsOrgId;
|
|
@@ -41,8 +41,8 @@ const ApiKey = (data) => {
|
|
|
41
41
|
export const createApiKey = (data) => {
|
|
42
42
|
const newState = { ...data };
|
|
43
43
|
|
|
44
|
-
if (!hasText(newState.
|
|
45
|
-
throw new Error(`Invalid Hashed Key: ${newState.
|
|
44
|
+
if (!hasText(newState.hashedApiKey)) {
|
|
45
|
+
throw new Error(`Invalid Hashed API Key: ${newState.hashedApiKey}`);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (!hasText(newState.name)) {
|
|
@@ -14,25 +14,26 @@ import { ApiKeyDto } from '../../dto/api-key.js';
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Get ApiKey by Hashed Key
|
|
17
|
-
* @param {string}
|
|
17
|
+
* @param {string} hashedApiKey
|
|
18
18
|
* @param {DynamoClient} dynamoClient
|
|
19
19
|
* @param {Object} config
|
|
20
20
|
* @param {Logger} log
|
|
21
21
|
* @returns {Promise<ApiKeyDto>}
|
|
22
22
|
*/
|
|
23
|
-
export const
|
|
24
|
-
const
|
|
23
|
+
export const getApiKeyByHashedApiKey = async (hashedApiKey, dynamoClient, log, config) => {
|
|
24
|
+
const items = await dynamoClient.query({
|
|
25
25
|
TableName: config.tableNameApiKeys,
|
|
26
|
-
IndexName: config.
|
|
27
|
-
KeyConditionExpression: '#
|
|
26
|
+
IndexName: config.indexNameApiKeyByHashedApiKey,
|
|
27
|
+
KeyConditionExpression: '#hashedApiKey = :hashedApiKey',
|
|
28
28
|
ExpressionAttributeNames: {
|
|
29
|
-
'#
|
|
29
|
+
'#hashedApiKey': 'hashedApiKey',
|
|
30
30
|
},
|
|
31
31
|
ExpressionAttributeValues: {
|
|
32
|
-
':
|
|
32
|
+
':hashedApiKey': hashedApiKey,
|
|
33
33
|
},
|
|
34
|
+
Limit: 1,
|
|
34
35
|
});
|
|
35
|
-
return
|
|
36
|
+
return items.length > 0 ? ApiKeyDto.fromDynamoItem(items[0]) : null;
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -10,9 +10,14 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { createNewApiKey,
|
|
13
|
+
import { createNewApiKey, getApiKeyByHashedApiKey } from './accessPatterns.js';
|
|
14
14
|
|
|
15
15
|
export const apiKeyFunctions = (dynamoClient, config, log) => ({
|
|
16
|
-
|
|
16
|
+
getApiKeyByHashedApiKey: (hashedApiKey) => getApiKeyByHashedApiKey(
|
|
17
|
+
hashedApiKey,
|
|
18
|
+
dynamoClient,
|
|
19
|
+
log,
|
|
20
|
+
config,
|
|
21
|
+
),
|
|
17
22
|
createNewApiKey: (apiKey) => createNewApiKey(apiKey, dynamoClient, config, log),
|
|
18
23
|
});
|