Skip to content
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
27 changes: 15 additions & 12 deletions src/core/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ export class ProfileService {

public async findProfile(profileName: string): Promise<Profile> {
return new Promise<Profile>((resolve, reject) => {
this.mapCelonisEnvProfile();
this.checkIfMissingProfile(profileName, reject);
try {
if (process.env.TEAM_URL && process.env.API_TOKEN) {
resolve(this.buildProfileFromEnvVariables());
} else {
if (!this.checkIfMissingProfile(profileName)) {
const file = fs.readFileSync(
path.resolve(this.profileContainerPath, this.constructProfileFileName(profileName)),
{ encoding: "utf-8" }
);
const profile : Profile = JSON.parse(file);
this.refreshProfile(profile)
.then(() => resolve(profile));
} else if (process.env.TEAM_URL && process.env.API_TOKEN) {
resolve(this.buildProfileFromEnvVariables());
} else if (process.env.CELONIS_URL && process.env.CELONIS_API_TOKEN) {
this.mapCelonisEnvProfile();
resolve(this.buildProfileFromEnvVariables());
} else {
reject(`The profile ${profileName} couldn't be resolved due to missing environment variables.`);
}
} catch (e) {
reject(`The profile ${profileName} couldn't be resolved.`);
Expand Down Expand Up @@ -298,18 +301,18 @@ export class ProfileService {
})
}

private checkIfMissingProfile(profileName: string, reject: any): void {
if (!profileName && (!process.env.TEAM_URL || !process.env.API_TOKEN)) {
reject("Profile not found");
private checkIfMissingProfile(profileName: string): boolean {
if (!profileName) {
return true;
}
}

private mapCelonisEnvProfile(): void {
if (!process.env.CELONIS_URL) {
return;
let celonisUrl = process.env.CELONIS_URL;
if (!celonisUrl.startsWith("http://") && !celonisUrl.startsWith("https://")) {
celonisUrl = `https://${celonisUrl}`;
}

process.env.TEAM_URL = process.env.CELONIS_URL;
process.env.TEAM_URL = celonisUrl;

if (process.env.CELONIS_API_TOKEN) {
process.env.API_TOKEN = process.env.CELONIS_API_TOKEN;
Expand Down
Loading
Loading