@fluidframework/routerlicious-driver 2.0.0-internal.2.2.0 → 2.0.0-internal.2.3.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/.eslintrc.js +1 -1
- package/dist/cache.d.ts +3 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +7 -2
- package/dist/cache.js.map +1 -1
- package/dist/documentService.d.ts +4 -2
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +18 -39
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +16 -5
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +1 -1
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +2 -1
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +6 -0
- package/dist/errorUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/restWrapper.d.ts +8 -5
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +33 -38
- package/dist/restWrapper.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +1 -1
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/cache.d.ts +3 -0
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +7 -2
- package/lib/cache.js.map +1 -1
- package/lib/documentService.d.ts +4 -2
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +18 -20
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +16 -5
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +1 -1
- package/lib/documentStorageService.js.map +1 -1
- package/lib/errorUtils.d.ts +2 -1
- package/lib/errorUtils.d.ts.map +1 -1
- package/lib/errorUtils.js +6 -0
- package/lib/errorUtils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/restWrapper.d.ts +8 -5
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +33 -38
- package/lib/restWrapper.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +1 -1
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +13 -11
- package/src/cache.ts +11 -1
- package/src/documentService.ts +26 -28
- package/src/documentServiceFactory.ts +30 -13
- package/src/documentStorageService.ts +1 -1
- package/src/errorUtils.ts +7 -2
- package/src/packageVersion.ts +1 -1
- package/src/restWrapper.ts +49 -37
- package/src/shreddedSummaryDocumentStorageService.ts +1 -1
- package/src/wholeSummaryDocumentStorageService.ts +1 -1
package/src/documentService.ts
CHANGED
|
@@ -40,7 +40,6 @@ export class DocumentService implements api.IDocumentService {
|
|
|
40
40
|
|
|
41
41
|
private storageManager: GitManager | undefined;
|
|
42
42
|
private noCacheStorageManager: GitManager | undefined;
|
|
43
|
-
private ordererRestWrapper: RestWrapper | undefined;
|
|
44
43
|
|
|
45
44
|
public get resolvedUrl() {
|
|
46
45
|
return this._resolvedUrl;
|
|
@@ -56,6 +55,8 @@ export class DocumentService implements api.IDocumentService {
|
|
|
56
55
|
protected tokenProvider: ITokenProvider,
|
|
57
56
|
protected tenantId: string,
|
|
58
57
|
protected documentId: string,
|
|
58
|
+
protected ordererRestWrapper: RouterliciousOrdererRestWrapper,
|
|
59
|
+
private readonly documentStorageServicePolicies: api.IDocumentStorageServicePolicies,
|
|
59
60
|
private readonly driverPolicies: IRouterliciousDriverPolicies,
|
|
60
61
|
private readonly blobCache: ICache<ArrayBufferLike>,
|
|
61
62
|
private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion>,
|
|
@@ -116,18 +117,11 @@ export class DocumentService implements api.IDocumentService {
|
|
|
116
117
|
// Initialize storageManager and noCacheStorageManager
|
|
117
118
|
const storageManager = await getStorageManager();
|
|
118
119
|
const noCacheStorageManager = await getStorageManager(true);
|
|
119
|
-
const documentStorageServicePolicies: api.IDocumentStorageServicePolicies = {
|
|
120
|
-
caching: this.driverPolicies.enablePrefetch
|
|
121
|
-
? api.LoaderCachingPolicy.Prefetch
|
|
122
|
-
: api.LoaderCachingPolicy.NoCaching,
|
|
123
|
-
minBlobSize: this.driverPolicies.aggregateBlobsSmallerThanBytes,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
120
|
this.documentStorageService = new DocumentStorageService(
|
|
127
121
|
this.documentId,
|
|
128
122
|
storageManager,
|
|
129
123
|
this.logger,
|
|
130
|
-
documentStorageServicePolicies,
|
|
124
|
+
this.documentStorageServicePolicies,
|
|
131
125
|
this.driverPolicies,
|
|
132
126
|
this.blobCache,
|
|
133
127
|
this.snapshotTreeCache,
|
|
@@ -147,10 +141,9 @@ export class DocumentService implements api.IDocumentService {
|
|
|
147
141
|
|
|
148
142
|
const getRestWrapper = async (): Promise<RestWrapper> => {
|
|
149
143
|
const shouldUpdateDiscoveredSessionInfo = this.shouldUpdateDiscoveredSessionInfo();
|
|
144
|
+
|
|
150
145
|
if (shouldUpdateDiscoveredSessionInfo) {
|
|
151
146
|
await this.refreshDiscovery();
|
|
152
|
-
}
|
|
153
|
-
if (!this.ordererRestWrapper || shouldUpdateDiscoveredSessionInfo) {
|
|
154
147
|
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
155
148
|
this.ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
156
149
|
this.tenantId,
|
|
@@ -187,27 +180,32 @@ export class DocumentService implements api.IDocumentService {
|
|
|
187
180
|
*/
|
|
188
181
|
public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
|
|
189
182
|
const connect = async (refreshToken?: boolean) => {
|
|
183
|
+
let ordererToken = this.ordererRestWrapper.getToken();
|
|
190
184
|
if (this.shouldUpdateDiscoveredSessionInfo()) {
|
|
191
185
|
await this.refreshDiscovery();
|
|
192
186
|
}
|
|
193
187
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
188
|
+
if (refreshToken) {
|
|
189
|
+
ordererToken = await PerformanceEvent.timedExecAsync(
|
|
190
|
+
this.logger,
|
|
191
|
+
{
|
|
192
|
+
eventName: "GetDeltaStreamToken",
|
|
193
|
+
docId: this.documentId,
|
|
194
|
+
details: JSON.stringify({
|
|
195
|
+
refreshToken,
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
198
|
+
async () => {
|
|
199
|
+
const newOrdererToken = await this.tokenProvider.fetchOrdererToken(
|
|
200
|
+
this.tenantId,
|
|
201
|
+
this.documentId,
|
|
202
|
+
refreshToken,
|
|
203
|
+
);
|
|
204
|
+
this.ordererRestWrapper.setToken(newOrdererToken);
|
|
205
|
+
return newOrdererToken;
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
211
209
|
|
|
212
210
|
return PerformanceEvent.timedExecAsync(
|
|
213
211
|
this.logger,
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "@fluidframework/common-utils";
|
|
7
7
|
import {
|
|
8
|
+
FiveDaysMs,
|
|
8
9
|
IDocumentService,
|
|
9
10
|
IDocumentServiceFactory,
|
|
11
|
+
IDocumentStorageServicePolicies,
|
|
10
12
|
IFluidResolvedUrl,
|
|
11
13
|
IResolvedUrl,
|
|
14
|
+
LoaderCachingPolicy,
|
|
12
15
|
} from "@fluidframework/driver-definitions";
|
|
13
16
|
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
14
17
|
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
@@ -30,6 +33,8 @@ import { ICache, InMemoryCache, NullCache } from "./cache";
|
|
|
30
33
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
31
34
|
import { ISnapshotTreeVersion } from "./definitions";
|
|
32
35
|
|
|
36
|
+
const maximumSnapshotCacheDurationMs: FiveDaysMs = 432_000_000; // 5 days in ms
|
|
37
|
+
|
|
33
38
|
const defaultRouterliciousDriverPolicies: IRouterliciousDriverPolicies = {
|
|
34
39
|
enablePrefetch: true,
|
|
35
40
|
maxConcurrentStorageRequests: 100,
|
|
@@ -55,13 +60,16 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
55
60
|
private readonly tokenProvider: ITokenProvider,
|
|
56
61
|
driverPolicies: Partial<IRouterliciousDriverPolicies> = {},
|
|
57
62
|
) {
|
|
63
|
+
// Use the maximum allowed by the policy (IDocumentStorageServicePolicies.maximumCacheDurationMs set below)
|
|
64
|
+
const snapshotCacheExpiryMs: FiveDaysMs = maximumSnapshotCacheDurationMs;
|
|
65
|
+
|
|
58
66
|
this.driverPolicies = {
|
|
59
67
|
...defaultRouterliciousDriverPolicies,
|
|
60
68
|
...driverPolicies,
|
|
61
69
|
};
|
|
62
70
|
this.blobCache = new InMemoryCache<ArrayBufferLike>();
|
|
63
71
|
this.snapshotTreeCache = this.driverPolicies.enableInternalSummaryCaching
|
|
64
|
-
? new InMemoryCache<ISnapshotTreeVersion>()
|
|
72
|
+
? new InMemoryCache<ISnapshotTreeVersion>(snapshotCacheExpiryMs)
|
|
65
73
|
: new NullCache<ISnapshotTreeVersion>();
|
|
66
74
|
}
|
|
67
75
|
|
|
@@ -209,7 +217,6 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
209
217
|
session?: ISession,
|
|
210
218
|
): Promise<IDocumentService> {
|
|
211
219
|
ensureFluidResolvedUrl(resolvedUrl);
|
|
212
|
-
|
|
213
220
|
const parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
214
221
|
const [, tenantId, documentId] = parsedUrl.pathname.split("/");
|
|
215
222
|
if (!documentId || !tenantId) {
|
|
@@ -218,20 +225,20 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
218
225
|
}
|
|
219
226
|
const logger2 = ChildLogger.create(logger, "RouterliciousDriver", { all: { driverVersion } });
|
|
220
227
|
|
|
228
|
+
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
229
|
+
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
230
|
+
tenantId,
|
|
231
|
+
documentId,
|
|
232
|
+
this.tokenProvider,
|
|
233
|
+
logger2,
|
|
234
|
+
rateLimiter,
|
|
235
|
+
this.driverPolicies.enableRestLess,
|
|
236
|
+
);
|
|
237
|
+
|
|
221
238
|
const discoverFluidResolvedUrl = async (): Promise<IFluidResolvedUrl> => {
|
|
222
239
|
if (!this.driverPolicies.enableDiscovery) {
|
|
223
240
|
return resolvedUrl;
|
|
224
241
|
}
|
|
225
|
-
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
226
|
-
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
227
|
-
tenantId,
|
|
228
|
-
documentId,
|
|
229
|
-
this.tokenProvider,
|
|
230
|
-
logger2,
|
|
231
|
-
rateLimiter,
|
|
232
|
-
this.driverPolicies.enableRestLess,
|
|
233
|
-
resolvedUrl.endpoints.ordererUrl,
|
|
234
|
-
);
|
|
235
242
|
|
|
236
243
|
const discoveredSession = await PerformanceEvent.timedExecAsync(
|
|
237
244
|
logger2,
|
|
@@ -242,7 +249,7 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
242
249
|
async () => {
|
|
243
250
|
// The service responds with the current document session associated with the container.
|
|
244
251
|
return ordererRestWrapper.get<ISession>(
|
|
245
|
-
|
|
252
|
+
`${resolvedUrl.endpoints.ordererUrl}/documents/${tenantId}/session/${documentId}`);
|
|
246
253
|
});
|
|
247
254
|
return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
|
|
248
255
|
};
|
|
@@ -259,6 +266,14 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
259
266
|
`All endpoints urls must be provided. [ordererUrl:${ordererUrl}][deltaStorageUrl:${deltaStorageUrl}]`);
|
|
260
267
|
}
|
|
261
268
|
|
|
269
|
+
const documentStorageServicePolicies: IDocumentStorageServicePolicies = {
|
|
270
|
+
caching: this.driverPolicies.enablePrefetch
|
|
271
|
+
? LoaderCachingPolicy.Prefetch
|
|
272
|
+
: LoaderCachingPolicy.NoCaching,
|
|
273
|
+
minBlobSize: this.driverPolicies.aggregateBlobsSmallerThanBytes,
|
|
274
|
+
maximumCacheDurationMs: maximumSnapshotCacheDurationMs,
|
|
275
|
+
};
|
|
276
|
+
|
|
262
277
|
return new DocumentService(
|
|
263
278
|
fluidResolvedUrl,
|
|
264
279
|
ordererUrl,
|
|
@@ -269,6 +284,8 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
269
284
|
this.tokenProvider,
|
|
270
285
|
tenantId,
|
|
271
286
|
documentId,
|
|
287
|
+
ordererRestWrapper,
|
|
288
|
+
documentStorageServicePolicies,
|
|
272
289
|
this.driverPolicies,
|
|
273
290
|
this.blobCache,
|
|
274
291
|
this.snapshotTreeCache,
|
|
@@ -74,7 +74,7 @@ export class DocumentStorageService extends DocumentStorageServiceProxy {
|
|
|
74
74
|
public readonly id: string,
|
|
75
75
|
public manager: GitManager,
|
|
76
76
|
logger: ITelemetryLogger,
|
|
77
|
-
policies: IDocumentStorageServicePolicies
|
|
77
|
+
policies: IDocumentStorageServicePolicies,
|
|
78
78
|
driverPolicies?: IRouterliciousDriverPolicies,
|
|
79
79
|
blobCache?: ICache<ArrayBufferLike>,
|
|
80
80
|
snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
|
package/src/errorUtils.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { pkgVersion as driverVersion } from "./packageVersion";
|
|
|
14
14
|
|
|
15
15
|
export enum R11sErrorType {
|
|
16
16
|
fileNotFoundOrAccessDeniedError = "fileNotFoundOrAccessDeniedError",
|
|
17
|
+
sslCertError = "sslCertError",
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -65,8 +66,12 @@ export function createR11sNetworkError(
|
|
|
65
66
|
// If a service is temporarily down or a browser resource limit is reached, RestWrapper will throw
|
|
66
67
|
// a network error with no status code (e.g. err:ERR_CONN_REFUSED or err:ERR_FAILED) and
|
|
67
68
|
// the error message will start with NetworkError as defined in restWrapper.ts
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
// If there exists a self-signed SSL certificates error, throw a NonRetryableError
|
|
70
|
+
// TODO: instead of relying on string matching, filter error based on the error code like we do for websocket connections
|
|
71
|
+
if (errorMessage.includes("failed, reason: self signed certificate")) {
|
|
72
|
+
return new NonRetryableError(errorMessage, R11sErrorType.sslCertError, props);
|
|
73
|
+
}
|
|
74
|
+
return new GenericNetworkError(errorMessage, errorMessage.startsWith("NetworkError"), props);
|
|
70
75
|
case 401:
|
|
71
76
|
// The first 401 is manually retried in RouterliciousRestWrapper with a refreshed token,
|
|
72
77
|
// so we treat repeat 401s the same as 403.
|
package/src/packageVersion.ts
CHANGED
package/src/restWrapper.ts
CHANGED
|
@@ -21,10 +21,11 @@ import type { AxiosRequestConfig, AxiosRequestHeaders } from "axios";
|
|
|
21
21
|
import safeStringify from "json-stringify-safe";
|
|
22
22
|
import { v4 as uuid } from "uuid";
|
|
23
23
|
import { throwR11sNetworkError } from "./errorUtils";
|
|
24
|
-
import { ITokenProvider } from "./tokens";
|
|
24
|
+
import { ITokenProvider, ITokenResponse } from "./tokens";
|
|
25
25
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
26
26
|
|
|
27
|
-
type AuthorizationHeaderGetter = (
|
|
27
|
+
type AuthorizationHeaderGetter = (token: ITokenResponse) => string;
|
|
28
|
+
type TokenFetcher = (refresh?: boolean) => Promise<ITokenResponse>;
|
|
28
29
|
|
|
29
30
|
const axiosRequestConfigToFetchRequestConfig = (requestConfig: AxiosRequestConfig): [RequestInfo, RequestInit] => {
|
|
30
31
|
const requestInfo: string = requestConfig.baseURL !== undefined
|
|
@@ -41,12 +42,13 @@ const axiosRequestConfigToFetchRequestConfig = (requestConfig: AxiosRequestConfi
|
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
export class RouterliciousRestWrapper extends RestWrapper {
|
|
44
|
-
private authorizationHeader: string | undefined;
|
|
45
45
|
private readonly restLess = new RestLessClient();
|
|
46
46
|
|
|
47
47
|
constructor(
|
|
48
48
|
logger: ITelemetryLogger,
|
|
49
49
|
private readonly rateLimiter: RateLimiter,
|
|
50
|
+
private token: ITokenResponse,
|
|
51
|
+
private readonly fetchRefreshedToken: TokenFetcher,
|
|
50
52
|
private readonly getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
51
53
|
private readonly useRestLess: boolean,
|
|
52
54
|
baseurl?: string,
|
|
@@ -55,10 +57,6 @@ export class RouterliciousRestWrapper extends RestWrapper {
|
|
|
55
57
|
super(baseurl, defaultQueryString);
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
public async load() {
|
|
59
|
-
this.authorizationHeader = await this.getAuthorizationHeader();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
60
|
protected async request<T>(requestConfig: AxiosRequestConfig, statusCode: number, canRetry = true): Promise<T> {
|
|
63
61
|
const config = {
|
|
64
62
|
...requestConfig,
|
|
@@ -88,7 +86,7 @@ export class RouterliciousRestWrapper extends RestWrapper {
|
|
|
88
86
|
// Failure
|
|
89
87
|
if (response.status === 401 && canRetry) {
|
|
90
88
|
// Refresh Authorization header and retry once
|
|
91
|
-
this.
|
|
89
|
+
this.token = await this.fetchRefreshedToken(true /* refreshToken */);
|
|
92
90
|
return this.request<T>(config, statusCode, false);
|
|
93
91
|
}
|
|
94
92
|
if (response.status === 429 && responseBody?.retryAfter > 0) {
|
|
@@ -120,21 +118,31 @@ export class RouterliciousRestWrapper extends RestWrapper {
|
|
|
120
118
|
"x-correlation-id": correlationId as string,
|
|
121
119
|
"x-driver-version": driverVersion,
|
|
122
120
|
// NOTE: If this.authorizationHeader is undefined, should "Authorization" be removed entirely?
|
|
123
|
-
"Authorization": this.
|
|
121
|
+
"Authorization": this.getAuthorizationHeader(this.token),
|
|
124
122
|
};
|
|
125
123
|
}
|
|
124
|
+
|
|
125
|
+
public getToken(): ITokenResponse {
|
|
126
|
+
return this.token;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public setToken(token: ITokenResponse) {
|
|
130
|
+
this.token = token;
|
|
131
|
+
}
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
export class RouterliciousStorageRestWrapper extends RouterliciousRestWrapper {
|
|
129
135
|
private constructor(
|
|
130
136
|
logger: ITelemetryLogger,
|
|
131
137
|
rateLimiter: RateLimiter,
|
|
138
|
+
token: ITokenResponse,
|
|
139
|
+
fetchToken: TokenFetcher,
|
|
132
140
|
getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
133
141
|
useRestLess: boolean,
|
|
134
142
|
baseurl?: string,
|
|
135
143
|
defaultQueryString: ParsedUrlQueryInput = {},
|
|
136
144
|
) {
|
|
137
|
-
super(logger, rateLimiter, getAuthorizationHeader, useRestLess, baseurl, defaultQueryString);
|
|
145
|
+
super(logger, rateLimiter, token, fetchToken, getAuthorizationHeader, useRestLess, baseurl, defaultQueryString);
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
public static async load(
|
|
@@ -149,7 +157,8 @@ export class RouterliciousStorageRestWrapper extends RouterliciousRestWrapper {
|
|
|
149
157
|
const defaultQueryString = {
|
|
150
158
|
token: `${fromUtf8ToBase64(tenantId)}`,
|
|
151
159
|
};
|
|
152
|
-
|
|
160
|
+
|
|
161
|
+
const fetchStorageToken = async (refreshToken?: boolean): Promise<ITokenResponse> => {
|
|
153
162
|
return PerformanceEvent.timedExecAsync(
|
|
154
163
|
logger,
|
|
155
164
|
{
|
|
@@ -163,25 +172,26 @@ export class RouterliciousStorageRestWrapper extends RouterliciousRestWrapper {
|
|
|
163
172
|
documentId,
|
|
164
173
|
refreshToken
|
|
165
174
|
);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
user: tenantId,
|
|
169
|
-
};
|
|
170
|
-
return getAuthorizationTokenFromCredentials(credentials);
|
|
175
|
+
|
|
176
|
+
return storageToken;
|
|
171
177
|
}
|
|
172
178
|
);
|
|
173
179
|
};
|
|
174
180
|
|
|
181
|
+
const getAuthorizationHeader: AuthorizationHeaderGetter = (token: ITokenResponse): string => {
|
|
182
|
+
const credentials = {
|
|
183
|
+
password: token.jwt,
|
|
184
|
+
user: tenantId,
|
|
185
|
+
};
|
|
186
|
+
return getAuthorizationTokenFromCredentials(credentials);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const storagetoken = await fetchStorageToken();
|
|
190
|
+
|
|
175
191
|
const restWrapper = new RouterliciousStorageRestWrapper(
|
|
176
|
-
logger, rateLimiter,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} catch (e) {
|
|
180
|
-
logger.sendErrorEvent({
|
|
181
|
-
eventName: "R11sRestWrapperLoadFailure",
|
|
182
|
-
}, e);
|
|
183
|
-
await restWrapper.load();
|
|
184
|
-
}
|
|
192
|
+
logger, rateLimiter, storagetoken,
|
|
193
|
+
fetchStorageToken, getAuthorizationHeader, useRestLess, baseurl, defaultQueryString);
|
|
194
|
+
|
|
185
195
|
return restWrapper;
|
|
186
196
|
}
|
|
187
197
|
}
|
|
@@ -190,12 +200,14 @@ export class RouterliciousOrdererRestWrapper extends RouterliciousRestWrapper {
|
|
|
190
200
|
private constructor(
|
|
191
201
|
logger: ITelemetryLogger,
|
|
192
202
|
rateLimiter: RateLimiter,
|
|
203
|
+
token: ITokenResponse,
|
|
204
|
+
fetchToken: TokenFetcher,
|
|
193
205
|
getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
194
206
|
useRestLess: boolean,
|
|
195
207
|
baseurl?: string,
|
|
196
208
|
defaultQueryString: ParsedUrlQueryInput = {},
|
|
197
209
|
) {
|
|
198
|
-
super(logger, rateLimiter, getAuthorizationHeader, useRestLess, baseurl, defaultQueryString);
|
|
210
|
+
super(logger, rateLimiter, token, fetchToken, getAuthorizationHeader, useRestLess, baseurl, defaultQueryString);
|
|
199
211
|
}
|
|
200
212
|
|
|
201
213
|
public static async load(
|
|
@@ -207,7 +219,11 @@ export class RouterliciousOrdererRestWrapper extends RouterliciousRestWrapper {
|
|
|
207
219
|
useRestLess: boolean,
|
|
208
220
|
baseurl?: string,
|
|
209
221
|
): Promise<RouterliciousOrdererRestWrapper> {
|
|
210
|
-
const getAuthorizationHeader: AuthorizationHeaderGetter =
|
|
222
|
+
const getAuthorizationHeader: AuthorizationHeaderGetter = (token: ITokenResponse): string => {
|
|
223
|
+
return `Basic ${token.jwt}`;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const fetchOrdererToken = async (refreshToken?: boolean): Promise<ITokenResponse> => {
|
|
211
227
|
return PerformanceEvent.timedExecAsync(
|
|
212
228
|
logger,
|
|
213
229
|
{
|
|
@@ -220,21 +236,17 @@ export class RouterliciousOrdererRestWrapper extends RouterliciousRestWrapper {
|
|
|
220
236
|
documentId,
|
|
221
237
|
refreshToken,
|
|
222
238
|
);
|
|
223
|
-
|
|
239
|
+
|
|
240
|
+
return ordererToken;
|
|
224
241
|
}
|
|
225
242
|
);
|
|
226
243
|
};
|
|
227
244
|
|
|
245
|
+
const newtoken = await fetchOrdererToken();
|
|
246
|
+
|
|
228
247
|
const restWrapper = new RouterliciousOrdererRestWrapper(
|
|
229
|
-
logger, rateLimiter, getAuthorizationHeader, useRestLess, baseurl);
|
|
230
|
-
|
|
231
|
-
await restWrapper.load();
|
|
232
|
-
} catch (e) {
|
|
233
|
-
logger.sendErrorEvent({
|
|
234
|
-
eventName: "R11sRestWrapperLoadFailure",
|
|
235
|
-
}, e);
|
|
236
|
-
await restWrapper.load();
|
|
237
|
-
}
|
|
248
|
+
logger, rateLimiter, newtoken, fetchOrdererToken, getAuthorizationHeader, useRestLess, baseurl);
|
|
249
|
+
|
|
238
250
|
return restWrapper;
|
|
239
251
|
}
|
|
240
252
|
}
|
|
@@ -63,7 +63,7 @@ export class ShreddedSummaryDocumentStorageService implements IDocumentStorageSe
|
|
|
63
63
|
protected readonly id: string,
|
|
64
64
|
protected readonly manager: GitManager,
|
|
65
65
|
protected readonly logger: ITelemetryLogger,
|
|
66
|
-
public readonly policies: IDocumentStorageServicePolicies
|
|
66
|
+
public readonly policies: IDocumentStorageServicePolicies,
|
|
67
67
|
driverPolicies?: IRouterliciousDriverPolicies,
|
|
68
68
|
blobCache?: ICache<ArrayBufferLike>,
|
|
69
69
|
snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
|
|
@@ -53,7 +53,7 @@ export class WholeSummaryDocumentStorageService implements IDocumentStorageServi
|
|
|
53
53
|
protected readonly id: string,
|
|
54
54
|
protected readonly manager: GitManager,
|
|
55
55
|
protected readonly logger: ITelemetryLogger,
|
|
56
|
-
public readonly policies: IDocumentStorageServicePolicies
|
|
56
|
+
public readonly policies: IDocumentStorageServicePolicies,
|
|
57
57
|
private readonly driverPolicies?: IRouterliciousDriverPolicies,
|
|
58
58
|
private readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),
|
|
59
59
|
private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> = new InMemoryCache(),
|