Skip to content

Commit 143eeda

Browse files
authored
feat(config): Insert a config bundle records in dynamodb to refference the config file in s3. (#2335)
* Insert a config bundle records in dynamodb to refference the config file in s3. * Add configbunle to config provider memory
1 parent 2bc0566 commit 143eeda

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

packages/cli/src/cli/config/action.import.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Env, fsa, LogConfig } from '@basemaps/shared';
2-
import { BaseConfig, ConfigBundled, ConfigProviderMemory } from '@basemaps/config';
2+
import { BaseConfig, Config, ConfigBundle, ConfigBundled, ConfigProviderMemory } from '@basemaps/config';
33
import { CommandLineAction, CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line';
44
import { Q, Updater } from './config.update.js';
55
import { invalidateCache } from '../util.js';
@@ -27,7 +27,7 @@ export class CommandImport extends CommandLineAction {
2727
this.config = this.defineStringParameter({
2828
argumentName: 'CONFIG',
2929
parameterLongName: '--config',
30-
description: 'Path of config json',
30+
description: 'Path of config json, this can be both a local path or s3 location',
3131
required: true,
3232
});
3333
this.backup = this.defineStringParameter({
@@ -49,6 +49,8 @@ export class CommandImport extends CommandLineAction {
4949
const config = this.config.value;
5050
const backup = this.backup.value;
5151
if (config == null) throw new Error('Please provide a config json');
52+
if (commit && !config.startsWith('s3://'))
53+
throw new Error('To acturally import into dynamo has to use the config file from s3.');
5254

5355
const HostPrefix = Env.isProduction() ? '' : 'dev.';
5456
const healthEndpoint = `https://${HostPrefix}basemaps.linz.govt.nz/v1/health`;
@@ -68,6 +70,17 @@ export class CommandImport extends CommandLineAction {
6870
for (const config of mem.objects.values()) this.update(config, commit);
6971
await Promise.all(this.promises);
7072

73+
if (commit) {
74+
const configBundle: ConfigBundle = {
75+
id: Config.ConfigBundle.id(configJson.id),
76+
name: Config.ConfigBundle.id(`config-${configJson.hash}.json`),
77+
path: config,
78+
hash: configJson.hash,
79+
};
80+
logger.info({ config }, 'Import:ConfigBundle');
81+
if (Config.ConfigBundle.isWriteable()) await Config.ConfigBundle.put(configBundle);
82+
}
83+
7184
if (commit && this.invalidations.length > 0) {
7285
// Lots of invalidations just invalidate everything
7386
if (this.invalidations.length > 10) {

packages/config/src/base.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Epsg } from '@basemaps/geo';
22
import { BaseConfig } from './config/base.js';
3+
import { ConfigBundle } from './config/config.bundle.js';
34
import { ConfigPrefix, ConfigPrefixes } from './config/prefix.js';
45
import { ConfigLayer, ConfigTileSet, TileSetType } from './config/tile.set.js';
56
import {
@@ -34,6 +35,10 @@ export class ConfigInstance {
3435
return this.cfg.ProcessingJob;
3536
}
3637

38+
get ConfigBundle(): BasemapsConfigObject<ConfigBundle> {
39+
return this.cfg.ConfigBundle;
40+
}
41+
3742
setConfigProvider(cfg: BasemapsConfigProvider): void {
3843
this.cfg = cfg;
3944
}
@@ -93,6 +98,7 @@ export abstract class BasemapsConfigProvider {
9398
abstract Style: BasemapsConfigObject<ConfigVectorStyle>;
9499
abstract Provider: BasemapsConfigObject<ConfigProvider>;
95100
abstract ProcessingJob: BasemapsConfigObject<ConfigProcessingJob>;
101+
abstract ConfigBundle: BasemapsConfigObject<ConfigBundle>;
96102
}
97103

98104
export abstract class BasemapsConfigObject<T extends BaseConfig> {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { BaseConfig } from './base.js';
2+
3+
export interface ConfigBundle extends BaseConfig {
4+
/** Path for the config bundle file */
5+
path: string;
6+
7+
/** Hash of the config bundle file */
8+
hash: string;
9+
}

packages/config/src/dynamo/dynamo.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ConfigTileSet } from '../config/tile.set.js';
99
import { ConfigVectorStyle } from '../config/vector.style.js';
1010
import { ConfigDynamoBase } from './dynamo.config.base.js';
1111
import { ConfigDynamoCached } from './dynamo.config.cached.js';
12+
import { ConfigBundle } from '../config/config.bundle.js';
1213

1314
export class ConfigProviderDynamo extends BasemapsConfigProvider {
1415
Prefix = ConfigPrefix;
@@ -22,6 +23,7 @@ export class ConfigProviderDynamo extends BasemapsConfigProvider {
2223
TileSet = new ConfigDynamoBase<ConfigTileSet>(this, ConfigPrefix.TileSet);
2324
Provider = new ConfigDynamoCached<ConfigProvider>(this, ConfigPrefix.Provider);
2425
ProcessingJob = new ConfigDynamoBase<ConfigProcessingJob>(this, ConfigPrefix.ProcessingJob);
26+
ConfigBundle = new ConfigDynamoBase<ConfigBundle>(this, ConfigPrefix.ConfigBundle);
2527

2628
constructor(tableName: string) {
2729
super();

packages/config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { BaseConfig } from './config/base.js';
33
export { ConfigImagery } from './config/imagery.js';
44
export { ConfigPrefix } from './config/prefix.js';
55
export { ConfigProvider } from './config/provider.js';
6+
export { ConfigBundle } from './config/config.bundle.js';
67
export {
78
JobStatus,
89
ProcessingJob,

packages/config/src/memory/memory.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ConfigProcessingJob } from '../config/processing.job.js';
99
import { ConfigProvider } from '../config/provider.js';
1010
import { ConfigTileSet, TileSetType } from '../config/tile.set.js';
1111
import { ConfigVectorStyle } from '../config/vector.style.js';
12+
import { ConfigBundle } from '../config/config.bundle.js';
1213
import { standardizeLayerName } from '../json/name.convertor.js';
1314

1415
/** bundle the configuration as a single JSON object */
@@ -51,6 +52,7 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
5152
TileSet = new MemoryConfigObject<ConfigTileSet>(this, ConfigPrefix.TileSet);
5253
Provider = new MemoryConfigObject<ConfigProvider>(this, ConfigPrefix.Provider);
5354
ProcessingJob = new MemoryConfigObject<ConfigProcessingJob>(this, ConfigPrefix.ProcessingJob);
55+
ConfigBundle = new MemoryConfigObject<ConfigBundle>(this, ConfigPrefix.ConfigBundle);
5456

5557
/** Memory cache of all objects */
5658
objects = new Map<string, BaseConfig>();

0 commit comments

Comments
 (0)