@basemaps/lambda-tiler 6.26.0 → 6.28.1
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 +53 -0
- package/build/{__test__ → __tests__}/index.test.d.ts +0 -0
- package/build/{__test__ → __tests__}/index.test.d.ts.map +1 -1
- package/build/{__test__ → __tests__}/index.test.js +0 -0
- package/build/{__test__ → __tests__}/route.test.d.ts +0 -0
- package/build/{__test__ → __tests__}/route.test.d.ts.map +1 -1
- package/build/{__test__ → __tests__}/route.test.js +0 -0
- package/build/{__test__ → __tests__}/tiff.cache.test.d.ts +0 -0
- package/build/__tests__/tiff.cache.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/tiff.cache.test.js +0 -0
- package/build/{__test__ → __tests__}/tile.cache.key.test.d.ts +0 -0
- package/build/__tests__/tile.cache.key.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/tile.cache.key.test.js +0 -0
- package/build/{__test__ → __tests__}/tile.set.cache.test.d.ts +0 -0
- package/build/__tests__/tile.set.cache.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/tile.set.cache.test.js +0 -0
- package/build/{__test__ → __tests__}/tile.set.test.d.ts +0 -0
- package/build/__tests__/tile.set.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/tile.set.test.js +0 -5
- package/build/{__test__ → __tests__}/tile.style.json.test.d.ts +0 -0
- package/build/__tests__/tile.style.json.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/tile.style.json.test.js +0 -0
- package/build/{__test__ → __tests__}/wmts.capability.test.d.ts +0 -0
- package/build/__tests__/wmts.capability.test.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/wmts.capability.test.js +36 -9
- package/build/{__test__ → __tests__}/xyz.test.d.ts +0 -0
- package/build/{__test__ → __tests__}/xyz.test.d.ts.map +1 -1
- package/build/{__test__ → __tests__}/xyz.test.js +0 -0
- package/build/{__test__ → __tests__}/xyz.util.d.ts +0 -0
- package/build/__tests__/xyz.util.d.ts.map +1 -0
- package/build/{__test__ → __tests__}/xyz.util.js +0 -0
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -3
- package/build/routes/{__test__ → __tests__}/attribution.test.d.ts +0 -0
- package/build/routes/__tests__/attribution.test.d.ts.map +1 -0
- package/build/routes/{__test__ → __tests__}/attribution.test.js +3 -2
- package/build/routes/{__test__ → __tests__}/health.test.d.ts +0 -0
- package/build/routes/__tests__/health.test.d.ts.map +1 -0
- package/build/routes/{__test__ → __tests__}/health.test.js +0 -0
- package/build/routes/{__test__ → __tests__}/imagery.test.d.ts +0 -0
- package/build/routes/__tests__/imagery.test.d.ts.map +1 -0
- package/build/routes/{__test__ → __tests__}/imagery.test.js +0 -0
- package/build/routes/__tests__/wmts.test.d.ts +2 -0
- package/build/routes/__tests__/wmts.test.d.ts.map +1 -0
- package/build/routes/__tests__/wmts.test.js +31 -0
- package/build/routes/tile.wmts.d.ts +2 -0
- package/build/routes/tile.wmts.d.ts.map +1 -1
- package/build/routes/tile.wmts.js +23 -3
- package/build/tile.set.cache.js +1 -1
- package/build/tile.set.raster.d.ts +1 -6
- package/build/tile.set.raster.d.ts.map +1 -1
- package/build/tile.set.raster.js +12 -22
- package/build/tile.set.vector.d.ts.map +1 -1
- package/build/tile.set.vector.js +3 -1
- package/build/wmts.capability.d.ts +12 -6
- package/build/wmts.capability.d.ts.map +1 -1
- package/build/wmts.capability.js +12 -11
- package/package.json +13 -14
- package/scripts/create.deployment.package.mjs +3 -3
- package/src/{__test__ → __tests__}/index.test.ts +0 -0
- package/src/{__test__ → __tests__}/route.test.ts +0 -0
- package/src/{__test__ → __tests__}/tiff.cache.test.ts +0 -0
- package/src/{__test__ → __tests__}/tile.cache.key.test.ts +0 -0
- package/src/{__test__ → __tests__}/tile.set.cache.test.ts +0 -0
- package/src/{__test__ → __tests__}/tile.set.test.ts +0 -7
- package/src/{__test__ → __tests__}/tile.style.json.test.ts +0 -0
- package/src/{__test__ → __tests__}/wmts.capability.test.ts +39 -8
- package/src/{__test__ → __tests__}/xyz.test.ts +0 -0
- package/src/{__test__ → __tests__}/xyz.util.ts +0 -0
- package/src/index.ts +2 -3
- package/src/routes/{__test__ → __tests__}/attribution.test.ts +3 -2
- package/src/routes/{__test__ → __tests__}/health.test.ts +0 -0
- package/src/routes/{__test__ → __tests__}/imagery.test.ts +0 -0
- package/src/routes/__tests__/wmts.test.ts +40 -0
- package/src/routes/tile.wmts.ts +23 -3
- package/src/tile.set.cache.ts +1 -1
- package/src/tile.set.raster.ts +12 -21
- package/src/tile.set.vector.ts +2 -1
- package/src/wmts.capability.ts +21 -15
- package/tsconfig.tsbuildinfo +1 -1
- package/build/__test__/tiff.cache.test.d.ts.map +0 -1
- package/build/__test__/tile.cache.key.test.d.ts.map +0 -1
- package/build/__test__/tile.import.test.d.ts +0 -2
- package/build/__test__/tile.import.test.d.ts.map +0 -1
- package/build/__test__/tile.import.test.js +0 -115
- package/build/__test__/tile.set.cache.test.d.ts.map +0 -1
- package/build/__test__/tile.set.test.d.ts.map +0 -1
- package/build/__test__/tile.style.json.test.d.ts.map +0 -1
- package/build/__test__/wmts.capability.test.d.ts.map +0 -1
- package/build/__test__/xyz.util.d.ts.map +0 -1
- package/build/import/imagery.find.d.ts +0 -17
- package/build/import/imagery.find.d.ts.map +0 -1
- package/build/import/imagery.find.js +0 -38
- package/build/import/make.cog.d.ts +0 -5
- package/build/import/make.cog.d.ts.map +0 -1
- package/build/import/make.cog.js +0 -21
- package/build/routes/__test__/attribution.test.d.ts.map +0 -1
- package/build/routes/__test__/health.test.d.ts.map +0 -1
- package/build/routes/__test__/imagery.test.d.ts.map +0 -1
- package/build/routes/import.d.ts +0 -9
- package/build/routes/import.d.ts.map +0 -1
- package/build/routes/import.js +0 -62
- package/src/__test__/tile.import.test.ts +0 -140
- package/src/import/imagery.find.ts +0 -60
- package/src/import/make.cog.ts +0 -29
- package/src/routes/import.ts +0 -67
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
|
|
2
|
-
import { TileMatrixSet } from '@basemaps/geo';
|
|
3
|
-
import { RoleConfig } from './imagery.find.js';
|
|
4
|
-
export declare function getJobCreationContext(path: string, tileMatrix: TileMatrixSet, role: RoleConfig, files: string[]): Promise<JobCreationContext>;
|
|
5
|
-
//# sourceMappingURL=make.cog.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make.cog.d.ts","sourceRoot":"","sources":["../../src/import/make.cog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,kBAAkB,CAAC,CAkB7B"}
|
package/build/import/make.cog.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Env } from '@basemaps/shared';
|
|
2
|
-
export async function getJobCreationContext(path, tileMatrix, role, files) {
|
|
3
|
-
const bucket = Env.get(Env.ImportImageryBucket);
|
|
4
|
-
if (bucket == null)
|
|
5
|
-
throw new Error('Output AWS s3 bucket Not Found.');
|
|
6
|
-
const ctx = {
|
|
7
|
-
override: {
|
|
8
|
-
projection: tileMatrix.projection,
|
|
9
|
-
resampling: {
|
|
10
|
-
warp: 'bilinear',
|
|
11
|
-
overview: 'lanczos',
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
outputLocation: { type: 's3', path: `s3://${bucket}` },
|
|
15
|
-
sourceLocation: { type: 's3', path, ...role, files: files },
|
|
16
|
-
batch: true,
|
|
17
|
-
tileMatrix,
|
|
18
|
-
oneCogCovering: false,
|
|
19
|
-
};
|
|
20
|
-
return ctx;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attribution.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/attribution.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"health.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/health.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imagery.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/imagery.test.ts"],"names":[],"mappings":""}
|
package/build/routes/import.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
2
|
-
/**
|
|
3
|
-
* Trigger import imagery job by this endpoint
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
|
|
7
|
-
*/
|
|
8
|
-
export declare function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
|
|
9
|
-
//# sourceMappingURL=import.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/routes/import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASnF;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAmDhF"}
|
package/build/routes/import.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
|
|
2
|
-
import { Config, fsa } from '@basemaps/shared';
|
|
3
|
-
import { createHash } from 'crypto';
|
|
4
|
-
import { findImagery, RoleRegister } from '../import/imagery.find.js';
|
|
5
|
-
import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo';
|
|
6
|
-
import { getJobCreationContext } from '../import/make.cog.js';
|
|
7
|
-
import { CogJobFactory } from '@basemaps/cli';
|
|
8
|
-
/**
|
|
9
|
-
* Trigger import imagery job by this endpoint
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
|
|
13
|
-
*/
|
|
14
|
-
export async function Import(req) {
|
|
15
|
-
const path = req.query.get('path');
|
|
16
|
-
const projection = req.query.get('p');
|
|
17
|
-
// Parse projection as target, default to process both NZTM2000Quad
|
|
18
|
-
let targetTms = Nztm2000Tms;
|
|
19
|
-
if (projection != null) {
|
|
20
|
-
const tileMatrix = TileMatrixSets.find(projection);
|
|
21
|
-
if (tileMatrix == null)
|
|
22
|
-
return new LambdaHttpResponse(404, 'Target projection Not found');
|
|
23
|
-
targetTms = tileMatrix;
|
|
24
|
-
}
|
|
25
|
-
// Find the imagery from s3
|
|
26
|
-
if (path == null || !path.startsWith('s3://'))
|
|
27
|
-
return new LambdaHttpResponse(400, `Invalid s3 path: ${path}`);
|
|
28
|
-
const role = await RoleRegister.findRole(path);
|
|
29
|
-
if (role == null)
|
|
30
|
-
return new LambdaHttpResponse(403, 'Unable to Access the s3 bucket');
|
|
31
|
-
const files = await findImagery(path);
|
|
32
|
-
if (files.length === 0)
|
|
33
|
-
return new LambdaHttpResponse(404, 'Imagery Not Found');
|
|
34
|
-
// Prepare Cog jobs
|
|
35
|
-
const ctx = await getJobCreationContext(path, targetTms, role, files);
|
|
36
|
-
const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
|
|
37
|
-
const jobId = Config.ProcessingJob.id(id);
|
|
38
|
-
let jobConfig = await Config.ProcessingJob.get(jobId);
|
|
39
|
-
if (jobConfig == null) {
|
|
40
|
-
// Add id back to JobCreationContext
|
|
41
|
-
ctx.outputLocation.path = fsa.join(ctx.outputLocation.path, id);
|
|
42
|
-
// Insert Processing job config
|
|
43
|
-
jobConfig = {
|
|
44
|
-
id: jobId,
|
|
45
|
-
name: path,
|
|
46
|
-
status: 'processing',
|
|
47
|
-
};
|
|
48
|
-
if (Config.ProcessingJob.isWriteable())
|
|
49
|
-
await Config.ProcessingJob.put(jobConfig);
|
|
50
|
-
else
|
|
51
|
-
return new LambdaHttpResponse(403, 'Unable to insert the Processing Job config');
|
|
52
|
-
// Start processing job
|
|
53
|
-
await CogJobFactory.create(ctx);
|
|
54
|
-
}
|
|
55
|
-
const json = JSON.stringify(jobConfig);
|
|
56
|
-
const data = Buffer.from(json);
|
|
57
|
-
const response = new LambdaHttpResponse(200, 'ok');
|
|
58
|
-
response.header(HttpHeader.CacheControl, 'no-store');
|
|
59
|
-
response.buffer(data, 'application/json');
|
|
60
|
-
req.set('bytes', data.byteLength);
|
|
61
|
-
return response;
|
|
62
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
|
|
2
|
-
import { Nztm2000Tms } from '@basemaps/geo';
|
|
3
|
-
import { Config, Env, fsa, LogConfig } from '@basemaps/shared';
|
|
4
|
-
import o from 'ospec';
|
|
5
|
-
import { createHash } from 'crypto';
|
|
6
|
-
import sinon from 'sinon';
|
|
7
|
-
import { LambdaAlbRequest, LambdaHttpRequest } from '@linzjs/lambda';
|
|
8
|
-
import { Context } from 'aws-lambda';
|
|
9
|
-
import { Import } from '../routes/import.js';
|
|
10
|
-
import { RoleConfig } from '../import/imagery.find.js';
|
|
11
|
-
import { CogJobFactory } from '@basemaps/cli';
|
|
12
|
-
import { ConfigProcessingJob } from '@basemaps/config';
|
|
13
|
-
|
|
14
|
-
o.spec('Import', () => {
|
|
15
|
-
const sandbox = sinon.createSandbox();
|
|
16
|
-
const outputBucket = 'testOutputBucket';
|
|
17
|
-
const configBucket = 'testConfigBucket';
|
|
18
|
-
const origConfigBucket = process.env[Env.AwsRoleConfigBucket];
|
|
19
|
-
const origOutputBucket = process.env[Env.ImportImageryBucket];
|
|
20
|
-
o.beforeEach(() => {
|
|
21
|
-
process.env[Env.AwsRoleConfigBucket] = configBucket;
|
|
22
|
-
process.env[Env.ImportImageryBucket] = outputBucket;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
o.afterEach(() => {
|
|
26
|
-
process.env[Env.AwsRoleConfigBucket] = origConfigBucket;
|
|
27
|
-
process.env[Env.ImportImageryBucket] = origOutputBucket;
|
|
28
|
-
sandbox.restore();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const tileMatrix = Nztm2000Tms;
|
|
32
|
-
const bucket = 'testSourceBucket';
|
|
33
|
-
const path = `s3://${bucket}/imagery/`;
|
|
34
|
-
const role: RoleConfig = {
|
|
35
|
-
bucket,
|
|
36
|
-
accountId: '123456',
|
|
37
|
-
roleArn: 'arn:aws:iam::123456:role/read-role',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const files = [`${path}/1.tiff`, `${path}/2.tiff`];
|
|
41
|
-
async function* listFiles(): AsyncGenerator<string, any, unknown> {
|
|
42
|
-
for (const key in files) yield files[key];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const ctx: JobCreationContext = {
|
|
46
|
-
override: {
|
|
47
|
-
projection: tileMatrix.projection,
|
|
48
|
-
resampling: {
|
|
49
|
-
warp: 'bilinear',
|
|
50
|
-
overview: 'lanczos',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
outputLocation: { type: 's3' as const, path: `s3://${outputBucket}` },
|
|
54
|
-
sourceLocation: { type: 's3', path: path, ...role, files: files },
|
|
55
|
-
batch: true,
|
|
56
|
-
tileMatrix,
|
|
57
|
-
oneCogCovering: false,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
|
|
61
|
-
const jobId = Config.ProcessingJob.id(id);
|
|
62
|
-
|
|
63
|
-
function getRequest(path: string, projection: string): LambdaHttpRequest {
|
|
64
|
-
return new LambdaAlbRequest(
|
|
65
|
-
{
|
|
66
|
-
requestContext: null as any,
|
|
67
|
-
httpMethod: 'get',
|
|
68
|
-
path: '/v1/tiles/import',
|
|
69
|
-
body: null,
|
|
70
|
-
isBase64Encoded: false,
|
|
71
|
-
queryStringParameters: { path: path, p: projection },
|
|
72
|
-
},
|
|
73
|
-
{} as Context,
|
|
74
|
-
LogConfig.get(),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
o('should return projection not found', async () => {
|
|
79
|
-
// Given ... wrong projection
|
|
80
|
-
const req = getRequest(path, '0000');
|
|
81
|
-
|
|
82
|
-
// When ... Then ...
|
|
83
|
-
const res = await Import(req);
|
|
84
|
-
o(res.body).equals('{"status":404,"message":"Target projection Not found"}');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
o('should return Invalid s3 location', async () => {
|
|
88
|
-
// Given... wrong s3 path
|
|
89
|
-
const req = getRequest('s3::testbucket/', '2193');
|
|
90
|
-
|
|
91
|
-
// When ...Then ...
|
|
92
|
-
const res = await Import(req);
|
|
93
|
-
o(res.body).equals('{"status":400,"message":"Invalid s3 path: s3::testbucket/"}');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
o('should return Unable to access bucket', async () => {
|
|
97
|
-
// Given... different bucket have no access role
|
|
98
|
-
sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
|
|
99
|
-
const req = getRequest(`s3://wrong-bucket/imagery/`, '2193');
|
|
100
|
-
|
|
101
|
-
// When ...Then ...
|
|
102
|
-
const res = await Import(req);
|
|
103
|
-
o(res.body).equals('{"status":403,"message":"Unable to Access the s3 bucket"}');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
o('should return Imagery not found', async () => {
|
|
107
|
-
// Given... none imagery find from bucket
|
|
108
|
-
sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
|
|
109
|
-
sandbox.stub(fsa, 'list').callsFake(async function* () {
|
|
110
|
-
yield `${path}1.json`;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const req = getRequest(path, '2193');
|
|
114
|
-
|
|
115
|
-
// When ...Then ...
|
|
116
|
-
const res = await Import(req);
|
|
117
|
-
o(res.body).equals('{"status":404,"message":"Imagery Not Found"}');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
o('should return 200 with existing import', async () => {
|
|
121
|
-
// Given... different bucket have no access role
|
|
122
|
-
sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
|
|
123
|
-
sandbox.stub(fsa, 'list').callsFake(listFiles);
|
|
124
|
-
sandbox.stub(CogJobFactory, 'create').resolves(undefined);
|
|
125
|
-
|
|
126
|
-
const jobConfig = {
|
|
127
|
-
id: jobId,
|
|
128
|
-
name: path,
|
|
129
|
-
status: 'complete',
|
|
130
|
-
} as ConfigProcessingJob;
|
|
131
|
-
sandbox.stub(Config.ProcessingJob, 'get').resolves(jobConfig);
|
|
132
|
-
const req = getRequest(path, '2193');
|
|
133
|
-
|
|
134
|
-
// When ...Then ...
|
|
135
|
-
const res = await Import(req);
|
|
136
|
-
o(res.status).equals(200);
|
|
137
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
138
|
-
o(JSON.parse(body)).deepEquals(jobConfig);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { AwsCredentials } from '@chunkd/source-aws-v2';
|
|
2
|
-
import { fsa } from '@chunkd/fs';
|
|
3
|
-
import { Env } from '@basemaps/shared';
|
|
4
|
-
|
|
5
|
-
export interface RoleConfig {
|
|
6
|
-
bucket: string;
|
|
7
|
-
accountId: string;
|
|
8
|
-
roleArn: string;
|
|
9
|
-
externalId?: string;
|
|
10
|
-
roleSessionDuration?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface BucketConfig {
|
|
14
|
-
v: number;
|
|
15
|
-
buckets: RoleConfig[];
|
|
16
|
-
version: string;
|
|
17
|
-
package: string;
|
|
18
|
-
hash: string;
|
|
19
|
-
updatedAt: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class RoleRegister {
|
|
23
|
-
/** Get all imagery source aws roles */
|
|
24
|
-
static async _loadRoles(): Promise<RoleConfig[]> {
|
|
25
|
-
const configBucket = Env.get(Env.AwsRoleConfigBucket);
|
|
26
|
-
if (configBucket == null) return [];
|
|
27
|
-
const configPath = `s3://${configBucket}/config.json`;
|
|
28
|
-
const config: BucketConfig = await fsa.readJson(configPath);
|
|
29
|
-
const roles = [];
|
|
30
|
-
for (const role of config.buckets) {
|
|
31
|
-
fsa.register(
|
|
32
|
-
's3://' + role.bucket,
|
|
33
|
-
AwsCredentials.fsFromRole(role.roleArn, role.externalId, role.roleSessionDuration),
|
|
34
|
-
);
|
|
35
|
-
roles.push(role);
|
|
36
|
-
}
|
|
37
|
-
return roles;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static _loadRolesPromise: Promise<RoleConfig[]> | undefined;
|
|
41
|
-
static loadRoles(): Promise<RoleConfig[]> {
|
|
42
|
-
if (RoleRegister._loadRolesPromise == null) RoleRegister._loadRolesPromise = this._loadRoles();
|
|
43
|
-
return RoleRegister._loadRolesPromise;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static async findRole(path: string): Promise<RoleConfig | undefined> {
|
|
47
|
-
const roles = await this.loadRoles();
|
|
48
|
-
return roles.find((f) => path.startsWith(`s3://${f.bucket}`));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Search for the imagery across all of our buckets */
|
|
53
|
-
export async function findImagery(path: string): Promise<string[]> {
|
|
54
|
-
const files: string[] = [];
|
|
55
|
-
for await (const key of fsa.list(path)) {
|
|
56
|
-
const searchKey = key.toLowerCase();
|
|
57
|
-
if (searchKey.endsWith('.tif') || searchKey.endsWith('.tiff')) files.push(key);
|
|
58
|
-
}
|
|
59
|
-
return files;
|
|
60
|
-
}
|
package/src/import/make.cog.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
|
|
2
|
-
import { TileMatrixSet } from '@basemaps/geo';
|
|
3
|
-
import { Env } from '@basemaps/shared';
|
|
4
|
-
import { RoleConfig } from './imagery.find.js';
|
|
5
|
-
|
|
6
|
-
export async function getJobCreationContext(
|
|
7
|
-
path: string,
|
|
8
|
-
tileMatrix: TileMatrixSet,
|
|
9
|
-
role: RoleConfig,
|
|
10
|
-
files: string[],
|
|
11
|
-
): Promise<JobCreationContext> {
|
|
12
|
-
const bucket = Env.get(Env.ImportImageryBucket);
|
|
13
|
-
if (bucket == null) throw new Error('Output AWS s3 bucket Not Found.');
|
|
14
|
-
const ctx: JobCreationContext = {
|
|
15
|
-
override: {
|
|
16
|
-
projection: tileMatrix.projection,
|
|
17
|
-
resampling: {
|
|
18
|
-
warp: 'bilinear',
|
|
19
|
-
overview: 'lanczos',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
outputLocation: { type: 's3' as const, path: `s3://${bucket}` },
|
|
23
|
-
sourceLocation: { type: 's3', path, ...role, files: files },
|
|
24
|
-
batch: true,
|
|
25
|
-
tileMatrix,
|
|
26
|
-
oneCogCovering: false,
|
|
27
|
-
};
|
|
28
|
-
return ctx;
|
|
29
|
-
}
|
package/src/routes/import.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
2
|
-
import { Config, fsa } from '@basemaps/shared';
|
|
3
|
-
import { createHash } from 'crypto';
|
|
4
|
-
import { findImagery, RoleRegister } from '../import/imagery.find.js';
|
|
5
|
-
import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo';
|
|
6
|
-
import { getJobCreationContext } from '../import/make.cog.js';
|
|
7
|
-
import { ConfigProcessingJob } from '@basemaps/config';
|
|
8
|
-
import { CogJobFactory } from '@basemaps/cli';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Trigger import imagery job by this endpoint
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
|
|
15
|
-
*/
|
|
16
|
-
export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
17
|
-
const path = req.query.get('path');
|
|
18
|
-
const projection = req.query.get('p');
|
|
19
|
-
|
|
20
|
-
// Parse projection as target, default to process both NZTM2000Quad
|
|
21
|
-
let targetTms = Nztm2000Tms;
|
|
22
|
-
if (projection != null) {
|
|
23
|
-
const tileMatrix = TileMatrixSets.find(projection);
|
|
24
|
-
if (tileMatrix == null) return new LambdaHttpResponse(404, 'Target projection Not found');
|
|
25
|
-
targetTms = tileMatrix;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Find the imagery from s3
|
|
29
|
-
if (path == null || !path.startsWith('s3://')) return new LambdaHttpResponse(400, `Invalid s3 path: ${path}`);
|
|
30
|
-
const role = await RoleRegister.findRole(path);
|
|
31
|
-
if (role == null) return new LambdaHttpResponse(403, 'Unable to Access the s3 bucket');
|
|
32
|
-
const files = await findImagery(path);
|
|
33
|
-
if (files.length === 0) return new LambdaHttpResponse(404, 'Imagery Not Found');
|
|
34
|
-
|
|
35
|
-
// Prepare Cog jobs
|
|
36
|
-
const ctx = await getJobCreationContext(path, targetTms, role, files);
|
|
37
|
-
|
|
38
|
-
const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
|
|
39
|
-
const jobId = Config.ProcessingJob.id(id);
|
|
40
|
-
let jobConfig = await Config.ProcessingJob.get(jobId);
|
|
41
|
-
if (jobConfig == null) {
|
|
42
|
-
// Add id back to JobCreationContext
|
|
43
|
-
ctx.outputLocation.path = fsa.join(ctx.outputLocation.path, id);
|
|
44
|
-
|
|
45
|
-
// Insert Processing job config
|
|
46
|
-
jobConfig = {
|
|
47
|
-
id: jobId,
|
|
48
|
-
name: path,
|
|
49
|
-
status: 'processing',
|
|
50
|
-
} as ConfigProcessingJob;
|
|
51
|
-
|
|
52
|
-
if (Config.ProcessingJob.isWriteable()) await Config.ProcessingJob.put(jobConfig);
|
|
53
|
-
else return new LambdaHttpResponse(403, 'Unable to insert the Processing Job config');
|
|
54
|
-
|
|
55
|
-
// Start processing job
|
|
56
|
-
await CogJobFactory.create(ctx);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const json = JSON.stringify(jobConfig);
|
|
60
|
-
const data = Buffer.from(json);
|
|
61
|
-
|
|
62
|
-
const response = new LambdaHttpResponse(200, 'ok');
|
|
63
|
-
response.header(HttpHeader.CacheControl, 'no-store');
|
|
64
|
-
response.buffer(data, 'application/json');
|
|
65
|
-
req.set('bytes', data.byteLength);
|
|
66
|
-
return response;
|
|
67
|
-
}
|