Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Storage Name into Tenants Custom Data #9339

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions server/historian/packages/historian-base/src/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ export async function createGitService(
const token = parseToken(tenantId, authorization);
const details = await tenantService.getTenant(tenantId, token, allowDisabledTenant);
const customData: ITenantCustomDataExternal = details.customData;
const writeToExternalStorage = !!customData.externalStorageData;
const writeToExternalStorage = !!customData?.externalStorageData;
const storageName = customData?.storageName;
const decoded = jwt.decode(token) as ITokenClaims;
const service = new RestGitService(
details.storage,
writeToExternalStorage,
tenantId,
decoded.documentId,
cache,
asyncLocalStorage);
asyncLocalStorage,
storageName);

return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface ITenant {
*/
export interface ITenantCustomDataExternal extends ITenantCustomData {
externalStorageData?: IExternalStorage;
storageName?: string;
}

export interface IExternalStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ export class RestGitService {
private readonly tenantId: string,
private readonly documentId: string,
private readonly cache?: ICache,
private readonly asyncLocalStorage?: AsyncLocalStorage<string>) {
const defaultHeaders: OutgoingHttpHeaders = {
"User-Agent": userAgent,
"Storage-Routing-Id": this.getStorageRoutingHeaderValue(),
};
private readonly asyncLocalStorage?: AsyncLocalStorage<string>,
private readonly storageName? : string) {
let defaultHeaders: OutgoingHttpHeaders;
if (storageName !== undefined) {
defaultHeaders = {
"User-Agent": userAgent,
"Storage-Routing-Id": this.getStorageRoutingHeaderValue(),
"Storage-Name": this.storageName,
};
} else {
defaultHeaders = {
"User-Agent": userAgent,
"Storage-Routing-Id": this.getStorageRoutingHeaderValue(),
};
}
if (storage.credentials) {
const token = Buffer.from(`${storage.credentials.user}:${storage.credentials.password}`);
defaultHeaders.Authorization = `Basic ${token.toString("base64")}`;
Expand All @@ -75,12 +85,15 @@ export class RestGitService {
`Created RestGitService: ${JSON.stringify({
"BaseUrl": storage.url,
"Storage-Routing-Id": this.getStorageRoutingHeaderValue(),
"Storage-Name": this.storageName,
tianzhu007 marked this conversation as resolved.
Show resolved Hide resolved
})}`,
);

Lumberjack.info(
`Created RestGitService: ${JSON.stringify({
"BaseUrl": storage.url,
"Storage-Routing-Id": this.getStorageRoutingHeaderValue(),
"Storage-Name": this.storageName,
})}`,
this.lumberProperties,
);
Expand Down