-
Notifications
You must be signed in to change notification settings - Fork 0
/
Args.ts
201 lines (189 loc) · 6.43 KB
/
Args.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import type { AccessToken } from "@itwin/core-bentley";
import { Logger } from "@itwin/core-bentley";
import type { NodeCliAuthorizationConfiguration } from "@itwin/node-cli-authorization";
import { LoggerCategories } from "./LoggerCategory";
import * as fs from "fs";
import * as path from "path";
interface Validatable {
isValid: boolean;
}
/**
* Defines the schema of the .json argument file used to initialize ConnectorRunner
*/
export interface AllArgsProps {
version: "0.0.1";
jobArgs: JobArgsProps;
hubArgs?: HubArgsProps;
}
export interface JobArgsProps {
source: string;
stagingDir?: string;
revisionHeader?: string;
dbType?: "briefcase" | "snapshot" | "standalone";
activityId?: string;
issuesDbDir?: string;
loggerConfigJSONFile?: string;
synchConfigFile?: string;
errorFile?: string;
shouldUnmapSource?: boolean;
connectorArgs?: { [otherArg: string]: any };
}
/**
* Arguments specific to a connector job
*/
export class JobArgs implements JobArgsProps, Validatable {
/** Source File
*/
public source: string;
/** Staging Directory
*/
public stagingDir: string = path.join(__dirname, "staging");
/** Revision Header
*/
public revisionHeader: string = "JSFWK";
/** Database Type
*/
public dbType: "briefcase" | "snapshot" | "standalone" = "briefcase";
/** Activity Id
*/
public activityId?: string;
/** Issues Database Directory (optional)
*/
public issuesDbDir?: string;
/** Logger Configuration File (optional)
*/
public loggerConfigJSONFile?: string;
/** Error File
*/
public errorFile: string;
/** Pass true to update the domain schemas
*/
public updateDomainSchemas: boolean = true;
/** Pass true to update db profile
*/
public updateDbProfile: boolean = true;
/** Synchronization Config File (optional)
*/
public synchConfigFile?: string;
/** Pass true to unmap the source file (optional)
*/
public shouldUnmapSource?: boolean = false;
/** Arguments to be passed through to Connector (optional)
*/
public connectorArgs?: { [otherArg: string]: any };
constructor(props: JobArgsProps) {
this.source = props.source;
this.stagingDir = props.stagingDir ?? this.stagingDir;
this.revisionHeader = props.revisionHeader ?? this.revisionHeader;
this.dbType = props.dbType ?? this.dbType;
this.activityId = props.activityId;
this.issuesDbDir = props.issuesDbDir;
this.loggerConfigJSONFile = props.loggerConfigJSONFile;
this.connectorArgs = props.connectorArgs;
this.errorFile = props.errorFile ?? path.join(this.stagingDir, "error.json");
this.synchConfigFile = props.synchConfigFile;
this.shouldUnmapSource = props.shouldUnmapSource;
}
public get isValid() {
if (!this.source) {
Logger.logError(LoggerCategories.Framework, "JobArgs.source is missing");
return false;
}
if (this.loggerConfigJSONFile && !fs.existsSync(this.loggerConfigJSONFile)) {
Logger.logError(LoggerCategories.Framework, "JobArgs.loggerConfigJSONFile does not exist");
return false;
}
return true;
}
}
export type ConnectRegion = "0" | "102" | "103";
export interface HubArgsProps {
briefcaseFile?: string;
briefcaseId?: number;
projectGuid: string;
iModelGuid: string;
region?: ConnectRegion;
tokenCallbackUrl?: string;
doInteractiveSignIn?: boolean;
maxLockRetries?: number;
maxLockRetryWaitSeconds?: number;
}
/**
* Arguments specific to iModelHub used in a connector job
*/
export class HubArgs implements HubArgsProps, Validatable {
/** Briefcase File
*/
public briefcaseFile?: string;
/** Briefcase Id (optional)
*/
public briefcaseId?: number;
/** Project Guid
*/
public projectGuid: string;
/** iModel Guid
*/
public iModelGuid: string;
/** Connect Region "0" | "102" | "103"
*/
public region: ConnectRegion = "0";
/** Node Cli Authorization Configuration (optional)
*/
public clientConfig?: NodeCliAuthorizationConfiguration;
/** Token Callback Url (optional)
*/
public tokenCallbackUrl?: string;
/** Token Callback (optional)
*/
public tokenCallback?: () => Promise<AccessToken>;
/** Whether or not to require input from user to authenticate
*/
public doInteractiveSignIn: boolean = false;
/** Number of attempts to obtain a lock before failing
*/
public maxLockRetries = 3;
/** Number of seconds to wait before retrying to obtain lock
*/
public maxLockRetryWaitSeconds = 5;
constructor(props: HubArgsProps) {
this.briefcaseFile = props.briefcaseFile;
this.briefcaseId = props.briefcaseId;
this.projectGuid = props.projectGuid;
this.iModelGuid = props.iModelGuid;
this.region = props.region ?? this.region;
this.tokenCallbackUrl = props.tokenCallbackUrl;
if (props.maxLockRetries !== undefined)
this.maxLockRetries = props.maxLockRetries;
if (props.maxLockRetryWaitSeconds !== undefined)
this.maxLockRetryWaitSeconds = props.maxLockRetryWaitSeconds;
if (props.doInteractiveSignIn !== undefined)
this.doInteractiveSignIn = props.doInteractiveSignIn;
}
public get isValid(): boolean {
if (this.briefcaseFile && !fs.existsSync(this.briefcaseFile)) {
Logger.logError(LoggerCategories.Framework, "HubArgs.briefcaseFile does not exist");
return false;
}
if (!this.iModelGuid) {
Logger.logError(LoggerCategories.Framework, "HubArgs.iModelGuid is not defined or has invalid value");
return false;
}
if (!this.projectGuid) {
Logger.logError(LoggerCategories.Framework, "HubArgs.projectGuid is not defined or has invalid value");
return false;
}
if (this.doInteractiveSignIn && !this.clientConfig) {
Logger.logError(LoggerCategories.Framework, "HubArgs.clientConfig must be defined if HubArgs.doInteractiveSignIn=true");
return false;
}
if (!this.doInteractiveSignIn && !this.tokenCallbackUrl && !this.tokenCallback) {
Logger.logError(LoggerCategories.Framework, "HubArgs.tokenCallback or HubArgs.tokenCallbackUrl must be defined if HubArgs.doInteractiveSignIn=false");
return false;
}
return true;
}
}