Skip to content

Commit ed4e6e9

Browse files
authored
Merge pull request #105 from github/fixUpdaterConfigInit
update the config in constructor
2 parents d4c8b84 + af1bf80 commit ed4e6e9

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/updater.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { BaseFetcher, Fetcher } from './fetcher';
55
import { Metadata, Targets } from './models';
66
import { TargetFile } from './models/file';
77
import { TrustedMetadataStore } from './store';
8-
import { updaterConfig } from './utils/config';
8+
import { Config, defaultConfig } from './utils/config';
99
import { MetadataKind } from './utils/types';
1010

11-
interface UodaterOptions {
11+
interface UpdaterOptions {
1212
metadataDir: string;
1313
metadataBaseUrl: string;
1414
targetDir?: string;
1515
targetBaseUrl?: string;
1616
fetcher?: BaseFetcher;
17+
config?: Config;
1718
}
1819

1920
interface Delegation {
@@ -27,12 +28,18 @@ export class Updater {
2728
private targetDir?: string;
2829
private targetBaseUrl?: string;
2930
private trustedSet: TrustedMetadataStore;
30-
private config: typeof updaterConfig;
31+
private config: Config;
3132
private fetcher: BaseFetcher;
3233

33-
constructor(options: UodaterOptions) {
34-
const { metadataDir, metadataBaseUrl, targetDir, targetBaseUrl, fetcher } =
35-
options;
34+
constructor(options: UpdaterOptions) {
35+
const {
36+
metadataDir,
37+
metadataBaseUrl,
38+
targetDir,
39+
targetBaseUrl,
40+
fetcher,
41+
config,
42+
} = options;
3643

3744
this.dir = metadataDir;
3845
this.metadataBaseUrl = metadataBaseUrl;
@@ -41,13 +48,10 @@ export class Updater {
4148
this.targetBaseUrl = targetBaseUrl;
4249

4350
const data = this.loadLocalMetadata(MetadataKind.Root);
44-
this.trustedSet = new TrustedMetadataStore(data);
45-
this.config = updaterConfig;
4651

52+
this.trustedSet = new TrustedMetadataStore(data);
53+
this.config = { ...defaultConfig, ...config };
4754
this.fetcher = fetcher || new Fetcher(this.config.fetchTimeout);
48-
49-
// self._trusted_set = trusted_metadata_set.TrustedMetadataSet(data)
50-
// self.config = config or UpdaterConfig()
5155
}
5256

5357
public async refresh() {

src/utils/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const updaterConfig = {
1+
export const defaultConfig = {
22
maxRootRotations: 32,
33
maxDelegations: 32,
44
rootMaxLength: 512000, //bytes
@@ -8,3 +8,5 @@ export const updaterConfig = {
88
prefixTargetsWithHash: true,
99
fetchTimeout: 100000, // milliseconds
1010
};
11+
12+
export type Config = typeof defaultConfig;

0 commit comments

Comments
 (0)