@certik/skynet 0.11.2 → 0.11.4
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 +8 -0
- package/api.js +1 -1
- package/dynamodb.js +3 -17
- package/env.js +19 -0
- package/package.json +1 -1
- package/s3.js +2 -8
- package/sqs.js +3 -7
package/CHANGELOG.md
CHANGED
package/api.js
CHANGED
|
@@ -42,7 +42,7 @@ async function logEndMiddleware(req, res, next) {
|
|
|
42
42
|
const apiKeyMiddleware = (key) => {
|
|
43
43
|
async function requireAPIKey(req, res, next) {
|
|
44
44
|
try {
|
|
45
|
-
const apiKey = req.get("x-api-key");
|
|
45
|
+
const apiKey = req.get("x-api-key") || req.query["api-key"]; // api key present either in header or query string
|
|
46
46
|
|
|
47
47
|
if (!apiKey) {
|
|
48
48
|
inline.log("request without api key");
|
package/dynamodb.js
CHANGED
|
@@ -8,29 +8,15 @@ import {
|
|
|
8
8
|
UpdateCommand,
|
|
9
9
|
} from "@aws-sdk/lib-dynamodb";
|
|
10
10
|
import { DynamoDBClient, DescribeTableCommand } from "@aws-sdk/client-dynamodb";
|
|
11
|
-
import {
|
|
11
|
+
import { getAWSSDKConfig } from "./env.js";
|
|
12
12
|
import { wait } from "./availability.js";
|
|
13
13
|
|
|
14
14
|
function getDynamoDB() {
|
|
15
|
-
return new DynamoDBClient(
|
|
16
|
-
credentials: {
|
|
17
|
-
accessKeyId: getAWSAccessKeyId(),
|
|
18
|
-
secretAccessKey: getAWSSecretAccessKey(),
|
|
19
|
-
},
|
|
20
|
-
region: getAWSRegion(),
|
|
21
|
-
});
|
|
15
|
+
return new DynamoDBClient(getAWSSDKConfig());
|
|
22
16
|
}
|
|
23
17
|
|
|
24
18
|
function getDocClient() {
|
|
25
|
-
return DynamoDBDocumentClient.from(
|
|
26
|
-
new DynamoDBClient({
|
|
27
|
-
credentials: {
|
|
28
|
-
accessKeyId: getAWSAccessKeyId(),
|
|
29
|
-
secretAccessKey: getAWSSecretAccessKey(),
|
|
30
|
-
},
|
|
31
|
-
region: getAWSRegion(),
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
19
|
+
return DynamoDBDocumentClient.from(new DynamoDBClient(getAWSSDKConfig()));
|
|
34
20
|
}
|
|
35
21
|
|
|
36
22
|
function mergeQueries(q1, q2) {
|
package/env.js
CHANGED
|
@@ -6,6 +6,24 @@ function getAWSSecretAccessKey() {
|
|
|
6
6
|
return ensureAndGet(["SKYNET_AWS_SECRET_ACCESS_KEY"], undefined);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
function getAWSSDKConfig() {
|
|
10
|
+
const region = getAWSRegion();
|
|
11
|
+
const accessKeyId = getAWSAccessKeyId();
|
|
12
|
+
const secretAccessKey = getAWSSecretAccessKey();
|
|
13
|
+
|
|
14
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
15
|
+
return { region };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
region,
|
|
20
|
+
credentials: {
|
|
21
|
+
accessKeyId,
|
|
22
|
+
secretAccessKey,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
9
27
|
function getAWSRegion() {
|
|
10
28
|
return ensureAndGet(["SKYNET_AWS_REGION"], "us-east-1");
|
|
11
29
|
}
|
|
@@ -56,6 +74,7 @@ export {
|
|
|
56
74
|
getEnvOrThrow,
|
|
57
75
|
getAWSAccessKeyId,
|
|
58
76
|
getAWSSecretAccessKey,
|
|
77
|
+
getAWSSDKConfig,
|
|
59
78
|
getAWSRegion,
|
|
60
79
|
getEnvironment,
|
|
61
80
|
isProduction,
|
package/package.json
CHANGED
package/s3.js
CHANGED
|
@@ -7,16 +7,10 @@ import {
|
|
|
7
7
|
ListObjectsV2Command,
|
|
8
8
|
NotFound,
|
|
9
9
|
} from "@aws-sdk/client-s3";
|
|
10
|
-
import {
|
|
10
|
+
import { getAWSSDKConfig } from "./env.js";
|
|
11
11
|
|
|
12
12
|
function getS3() {
|
|
13
|
-
return new S3Client(
|
|
14
|
-
credentials: {
|
|
15
|
-
accessKeyId: getAWSAccessKeyId(),
|
|
16
|
-
secretAccessKey: getAWSSecretAccessKey(),
|
|
17
|
-
},
|
|
18
|
-
region: getAWSRegion(),
|
|
19
|
-
});
|
|
13
|
+
return new S3Client(getAWSSDKConfig());
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
async function readFile(bucketName, key, verbose = false) {
|
package/sqs.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SQSClient } from "@aws-sdk/client-sqs";
|
|
2
|
+
import { getAWSSDKConfig } from "./env.js";
|
|
3
3
|
|
|
4
4
|
export function getSQS() {
|
|
5
|
-
return new
|
|
6
|
-
accessKeyId: getAWSAccessKeyId(),
|
|
7
|
-
secretAccessKey: getAWSSecretAccessKey(),
|
|
8
|
-
region: getAWSRegion(),
|
|
9
|
-
});
|
|
5
|
+
return new SQSClient(getAWSSDKConfig());
|
|
10
6
|
}
|