@basemaps/lambda-tiler 7.16.0 → 8.1.0
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 +19 -0
- package/build/__tests__/index.test.js +24 -2
- package/build/__tests__/index.test.js.map +1 -1
- package/build/routes/version.d.ts +2 -2
- package/build/routes/version.js +17 -1
- package/build/routes/version.js.map +1 -1
- package/build/util/__test__/validate.test.js +15 -0
- package/build/util/__test__/validate.test.js.map +1 -1
- package/build/util/validate.d.ts +2 -0
- package/build/util/validate.js +15 -1
- package/build/util/validate.js.map +1 -1
- package/dist/index.js +56116 -51565
- package/dist/node_modules/.package-lock.json +7 -7
- package/dist/node_modules/detect-libc/package.json +3 -2
- package/dist/node_modules/semver/bin/semver.js +2 -0
- package/dist/node_modules/semver/classes/comparator.js +2 -0
- package/dist/node_modules/semver/classes/index.js +2 -0
- package/dist/node_modules/semver/classes/range.js +2 -0
- package/dist/node_modules/semver/classes/semver.js +4 -3
- package/dist/node_modules/semver/functions/clean.js +2 -0
- package/dist/node_modules/semver/functions/cmp.js +2 -0
- package/dist/node_modules/semver/functions/coerce.js +2 -0
- package/dist/node_modules/semver/functions/compare-build.js +2 -0
- package/dist/node_modules/semver/functions/compare-loose.js +2 -0
- package/dist/node_modules/semver/functions/compare.js +2 -0
- package/dist/node_modules/semver/functions/diff.js +2 -0
- package/dist/node_modules/semver/functions/eq.js +2 -0
- package/dist/node_modules/semver/functions/gt.js +2 -0
- package/dist/node_modules/semver/functions/gte.js +2 -0
- package/dist/node_modules/semver/functions/inc.js +2 -0
- package/dist/node_modules/semver/functions/lt.js +2 -0
- package/dist/node_modules/semver/functions/lte.js +2 -0
- package/dist/node_modules/semver/functions/major.js +2 -0
- package/dist/node_modules/semver/functions/minor.js +2 -0
- package/dist/node_modules/semver/functions/neq.js +2 -0
- package/dist/node_modules/semver/functions/parse.js +2 -0
- package/dist/node_modules/semver/functions/patch.js +2 -0
- package/dist/node_modules/semver/functions/prerelease.js +2 -0
- package/dist/node_modules/semver/functions/rcompare.js +2 -0
- package/dist/node_modules/semver/functions/rsort.js +2 -0
- package/dist/node_modules/semver/functions/satisfies.js +2 -0
- package/dist/node_modules/semver/functions/sort.js +2 -0
- package/dist/node_modules/semver/functions/valid.js +2 -0
- package/dist/node_modules/semver/index.js +2 -0
- package/dist/node_modules/semver/internal/constants.js +2 -0
- package/dist/node_modules/semver/internal/debug.js +2 -0
- package/dist/node_modules/semver/internal/identifiers.js +2 -0
- package/dist/node_modules/semver/internal/lrucache.js +2 -0
- package/dist/node_modules/semver/internal/parse-options.js +2 -0
- package/dist/node_modules/semver/internal/re.js +8 -4
- package/dist/node_modules/semver/package.json +3 -3
- package/dist/node_modules/semver/preload.js +2 -0
- package/dist/node_modules/semver/ranges/gtr.js +2 -0
- package/dist/node_modules/semver/ranges/intersects.js +2 -0
- package/dist/node_modules/semver/ranges/ltr.js +2 -0
- package/dist/node_modules/semver/ranges/max-satisfying.js +2 -0
- package/dist/node_modules/semver/ranges/min-satisfying.js +2 -0
- package/dist/node_modules/semver/ranges/min-version.js +2 -0
- package/dist/node_modules/semver/ranges/outside.js +2 -0
- package/dist/node_modules/semver/ranges/simplify.js +2 -0
- package/dist/node_modules/semver/ranges/subset.js +2 -0
- package/dist/node_modules/semver/ranges/to-comparators.js +2 -0
- package/dist/node_modules/semver/ranges/valid.js +2 -0
- package/dist/package-lock.json +8 -8
- package/dist/package.json +1 -1
- package/package.json +10 -10
- package/src/__tests__/index.test.ts +30 -2
- package/src/routes/version.ts +22 -2
- package/src/util/__test__/validate.test.ts +18 -0
- package/src/util/validate.ts +18 -1
- package/tsconfig.tsbuildinfo +1 -1
package/src/routes/version.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BasemapsConfigProvider, ConfigProviderMemory } from '@basemaps/config';
|
|
2
|
+
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { ConfigLoader } from '../util/config.loader.js';
|
|
5
|
+
|
|
6
|
+
function getConfigHash(cfg: BasemapsConfigProvider): { id: string; hash?: string } | undefined {
|
|
7
|
+
if (!ConfigProviderMemory.is(cfg)) return undefined;
|
|
8
|
+
if (cfg.id == null) return undefined;
|
|
9
|
+
return { id: cfg.id, hash: cfg.hash };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function versionGet(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
13
|
+
const config = await ConfigLoader.load(req);
|
|
4
14
|
const response = new LambdaHttpResponse(200, 'ok');
|
|
5
15
|
response.header(HttpHeader.CacheControl, 'no-store');
|
|
6
16
|
response.json({
|
|
@@ -9,16 +19,26 @@ export function versionGet(): Promise<LambdaHttpResponse> {
|
|
|
9
19
|
* @example "v6.42.1"
|
|
10
20
|
*/
|
|
11
21
|
version: process.env['GIT_VERSION'] ?? 'dev',
|
|
22
|
+
|
|
12
23
|
/**
|
|
13
24
|
* Full git commit hash
|
|
14
25
|
* @example "e4231b1ee62c276c8657c56677ced02681dfe5d6"
|
|
15
26
|
*/
|
|
16
27
|
hash: process.env['GIT_HASH'],
|
|
28
|
+
|
|
17
29
|
/**
|
|
30
|
+
*
|
|
18
31
|
* The exact build that this release was run from
|
|
19
32
|
* @example "1658821493-3"
|
|
20
33
|
*/
|
|
21
34
|
buildId: process.env['BUILD_ID'],
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configuration id that was used to power this config
|
|
38
|
+
* @example { "id": "cb_01JTQ7ZK49F8EY4N5DRJ3XFT73", hash: "HcByZ8WS2zpaTxFJp6wSKg2eUpwahLqAGEQdcDxKxqp6" }
|
|
39
|
+
*/
|
|
40
|
+
config: getConfigHash(config),
|
|
22
41
|
});
|
|
42
|
+
|
|
23
43
|
return Promise.resolve(response);
|
|
24
44
|
}
|
|
@@ -6,6 +6,24 @@ import { GoogleTms, Nztm2000QuadTms, Nztm2000Tms } from '@basemaps/geo';
|
|
|
6
6
|
import { mockUrlRequest } from '../../__tests__/xyz.util.js';
|
|
7
7
|
import { Validate } from '../validate.js';
|
|
8
8
|
|
|
9
|
+
describe('Validate.blockedApiKeys', () => {
|
|
10
|
+
const validApiKey = 'c01jswmpe1yn3mwne7e0ggtp8vg';
|
|
11
|
+
it('should disable api keys', () => {
|
|
12
|
+
const req = mockUrlRequest('/v1/blank', `api=${validApiKey}`);
|
|
13
|
+
const parsedKey = Validate.apiKey(req);
|
|
14
|
+
assert.equal(parsedKey, validApiKey);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should disable api keys', () => {
|
|
18
|
+
const req = mockUrlRequest('/v1/blank', `api=${validApiKey}`);
|
|
19
|
+
Validate.blockedApiKeys.add(validApiKey);
|
|
20
|
+
assert.throws(() => Validate.apiKey(req));
|
|
21
|
+
|
|
22
|
+
Validate.blockedApiKeys.delete(validApiKey);
|
|
23
|
+
assert.equal(Validate.apiKey(req), validApiKey);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
9
27
|
describe('GetImageFormats', () => {
|
|
10
28
|
it('should parse all formats', () => {
|
|
11
29
|
const req = mockUrlRequest('/v1/blank', 'format=png&format=jpeg');
|
package/src/util/validate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigTileSetRaster, ConfigTileSetRasterOutput } from '@basemaps/config';
|
|
2
2
|
import { ImageFormat, LatLon, Projection, TileMatrixSet, TileMatrixSets } from '@basemaps/geo';
|
|
3
|
-
import { Const, isValidApiKey, truncateApiKey } from '@basemaps/shared';
|
|
3
|
+
import { Const, Env, isValidApiKey, LogConfig, truncateApiKey } from '@basemaps/shared';
|
|
4
4
|
import { getImageFormat } from '@basemaps/tiler';
|
|
5
5
|
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
6
6
|
|
|
@@ -23,7 +23,19 @@ export interface TileMatrixRequest {
|
|
|
23
23
|
Params: { tileMatrix?: string };
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function getBlockedApiKeys(): string[] {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(Env.get(Env.BlockedApiKeys) ?? '[]') as string[];
|
|
29
|
+
} catch (e) {
|
|
30
|
+
LogConfig.get().error(`"$${Env.BlockedApiKeys}" is invalid`);
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
export const Validate = {
|
|
36
|
+
/** list of API Keys that have been disabled */
|
|
37
|
+
blockedApiKeys: new Set<string>(getBlockedApiKeys()),
|
|
38
|
+
|
|
27
39
|
/**
|
|
28
40
|
* Validate that the api key exists and is valid
|
|
29
41
|
*
|
|
@@ -36,6 +48,11 @@ export const Validate = {
|
|
|
36
48
|
if (!valid.valid) throw new LambdaHttpResponse(400, 'API Key Invalid: ' + valid.message);
|
|
37
49
|
// Truncate the API Key so we are not logging the full key
|
|
38
50
|
req.set('api', truncateApiKey(apiKey));
|
|
51
|
+
|
|
52
|
+
if (this.blockedApiKeys.has(apiKey as string)) {
|
|
53
|
+
throw new LambdaHttpResponse(429, 'Too many requests! Please contact basemaps@linz.govt.nz for a developer key');
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
return apiKey as string;
|
|
40
57
|
},
|
|
41
58
|
|