-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceConfig.ts
More file actions
30 lines (30 loc) · 1.44 KB
/
ServiceConfig.ts
File metadata and controls
30 lines (30 loc) · 1.44 KB
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
// Copyright (c) Laserfiche.
// Licensed under the MIT License. See LICENSE in the project root for license information.
import 'dotenv/config';
import { authorizationTypeEnum as authType } from './AuthorizationType.js';
import { AccessKey, createFromBase64EncodedAccessKey } from '@laserfiche/lf-api-client-core';
const authorizationType: authType = (process.env.AUTHORIZATION_TYPE ?? authType.None) as authType;
let servicePrincipalKey: string;
let OAuthAccessKey: AccessKey;
let accessKeyBase64: string;
let username: string;
let password: string;
let baseUrl: string;
if (!authorizationType) {
throw new Error(`Unable to load AUTHORIZATION_TYPE from .env`);
}
const repositoryId: string = process.env.REPOSITORY_ID ?? '';
if (authorizationType === authType.CloudAccessKey) {
servicePrincipalKey = process.env.SERVICE_PRINCIPAL_KEY ?? '';
accessKeyBase64 = process.env.ACCESS_KEY ?? '';
OAuthAccessKey = createFromBase64EncodedAccessKey(accessKeyBase64 ?? '');
} else if (authorizationType === authType.APIServerUsernamePassword) {
username = process.env.APISERVER_USERNAME ?? '';
password = process.env.APISERVER_PASSWORD ?? '';
baseUrl = process.env.APISERVER_REPOSITORY_API_BASE_URL ?? '';
} else {
throw new Error(
`"Invalid value for 'AUTHORIZATION_TYPE'. It can only be 'CLOUD_ACCESS_KEY' or 'API_SERVER_USERNAME_PASSWORD'."`
);
}
export { OAuthAccessKey, servicePrincipalKey, repositoryId, authorizationType, username, password, baseUrl };