Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
TEIIDTOOLS-307: Connects BTL to the teiid-komodo in Openshift
Browse files Browse the repository at this point in the history
* environment/*
 * Centralises references to komodoEngine and komodoRestVersion constants
 * Removes references to host and port as these are now accessible using
   api.service

* api.service.ts
 * Provides method for fetching the base url of the application

* app-settings.service.ts
 * Fetches the user profile from teiid-komodo, providing BTL with the user
   details including their workspace.
  • Loading branch information
phantomjinx committed Jan 24, 2018
1 parent b276fa1 commit 1bb9749
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 32 deletions.
18 changes: 12 additions & 6 deletions ngapp/src/app/core/api.service.ts
Expand Up @@ -29,20 +29,26 @@ export abstract class ApiService {
protected appSettings: AppSettingsService;
protected logger: LoggerService;

constructor( appSettings: AppSettingsService, logger: LoggerService ) {
constructor( appSettings: AppSettingsService, logger: LoggerService) {
this.appSettings = appSettings;
this.logger = logger;
}

/**
* Get the Auth RequestOptions
* TODO: User and password are currently hardcoded to the DSB kit server credentials (dsbUser | 1demo-user1)
* @returns the base url of the application
*/
protected getBaseUrl(): string {
return window.location.protocol + '://' + window.location.hostname;
}

/**
* Get the Auth RequestOptions if any
* Note: Since usage of the oauth-proxy no additional auth request options are necessary
*
* @returns {RequestOptions}
*/
protected getAuthRequestOptions(): RequestOptions {
const userPasswordStr = this.appSettings.getKomodoUser() + ":" + this.appSettings.getKomodoUserPassword();
const headers = new Headers({ "Authorization": "Basic " + btoa(userPasswordStr) });
return new RequestOptions({ headers });
return this.appSettings.getAuthRequestOptions();
}

/**
Expand Down
90 changes: 72 additions & 18 deletions ngapp/src/app/core/app-settings.service.ts
Expand Up @@ -16,7 +16,12 @@
*/

import { Injectable } from "@angular/core";
import { Http, Headers, RequestOptions, Response } from "@angular/http";
import { LoggerService } from "@core/logger.service";
import { LayoutType } from "@shared/layout-type.enum";
import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";
import { environment } from "@environments/environment";

@Injectable()
export class AppSettingsService {
Expand All @@ -30,20 +35,24 @@ export class AppSettingsService {
public readonly GIT_REPO_PATH_KEY = "repo-path-property";
public readonly GIT_REPO_FILE_PATH_KEY = "file-path-property";

private readonly komodoRoot = "tko:komodo/tko:workspace";

// TODO: temporary location for user and password
private readonly komodoUser = "dsbUser";
private readonly komodoUserPassword = "1demo-user1";

// Map to maintain the target git repository properties
private readonly gitRepoProperties: Map<string, string>;

private static readonly userProfileUrl = environment.komodoServiceUrl + "/userProfile";

// page layouts
private svcPageLayout: LayoutType = LayoutType.CARD;
private connPageLayout: LayoutType = LayoutType.CARD;

constructor() {
private http: Http;
private logger: LoggerService;

private userProfile: Object;

constructor(http: Http, logger: LoggerService) {
this.http = http;
this.logger = logger;

// TODO: The git repository properties will be picked up based on the Openshift install location
this.gitRepoProperties = new Map<string, string>();
this.gitRepoProperties.set(this.GIT_REPO_PATH_KEY, "https://github.com/GIT_USER/GIT_REPO");
Expand All @@ -52,30 +61,75 @@ export class AppSettingsService {
this.gitRepoProperties.set(this.GIT_REPO_PASSWORD_KEY, "MY_PASS");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_NAME_KEY, "MY_USER");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_EMAIL_KEY, "USER@SOMEWHERE.COM");

//
// Do a call to fetch the user profile on init of service.
// The fetchProfile method returns an observable
// which we subscribe to and on completion assigns the variable
// values accordingly
//
this.fetchUserProfile().subscribe(
(profile) => {
this.userProfile = profile;
},
(error) => {
this.logger.error( "[fetchUserProfile] Error: %o", error );
});
}

/*
* Get the komodo workspace path for the current user
* @returns {string} the komodo workspace path
private handleError(error: Response): ErrorObservable {
this.logger.error( this.constructor.name + "::handleError" );
return Observable.throw(error);
}

private fetchUserProfile(): Observable<Object> {
return this.http.get(AppSettingsService.userProfileUrl, this.getAuthRequestOptions())
.map((response) => {
const userInfo = response.json();
return userInfo.Information;
})
.catch((error) => this.handleError(error));
}

/**
* Get the Auth RequestOptions if any
* Note: Since usage of the oauth-proxy no additional auth request options are necessary
*
* @returns {RequestOptions}
*/
public getKomodoUserWorkspacePath( ): string {
return this.komodoRoot + "/" + this.komodoUser;
public getAuthRequestOptions(): RequestOptions {
const headers = new Headers({});
return new RequestOptions({ headers });
}

/*
* Get the logged in komodo user
* @returns {string} the komodo user
*/
public getKomodoUser( ): string {
return this.komodoUser;
public getKomodoUser(): string {
if (! this.userProfile)
throw new Error('Failed to retrieve the user profile so cannot provide a user name');

let komodoUser = this.userProfile['User Name'];
if (! komodoUser)
throw new Error('Failed to retrieve the user name from the user profile');

return komodoUser;
}

/*
* Get the logged in komodo user password
* @returns {string} the komodo user password
* Get the komodo workspace path for the current user
* @returns {string} the komodo workspace path
*/
public getKomodoUserPassword( ): string {
return this.komodoUserPassword;
public getKomodoUserWorkspacePath(): string {
if (! this.userProfile)
throw new Error('Failed to retrieve the user profile so cannot provide a workspace path');

let workspace = this.userProfile['Workspace'];
if (! workspace)
throw new Error('Failed to retrieve the workspace path from the user profile');

return workspace;
}

/*
Expand Down
16 changes: 12 additions & 4 deletions ngapp/src/environments/environment.prod.ts
Expand Up @@ -17,23 +17,31 @@

import { DataservicesConstants } from "@dataservices/shared/dataservices-constants";

export const komodoEngine = "vdb-builder";

export const komodoRestVersion = "v1";

export const environment = {

production: true,

komodoEngine: komodoEngine,

komodoRestVersion: komodoRestVersion,

// the home page path
homePagePath: DataservicesConstants.dataservicesRootPath,

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
komodoImportExportUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/importexport",

// REST URL - Komodo workspace
komodoWorkspaceUrl: "https://localhost:8443/vdb-builder/v1/workspace",
komodoWorkspaceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/workspace",

// REST URL - Komodo teiid server
komodoTeiidUrl: "https://localhost:8443/vdb-builder/v1/teiid",
komodoTeiidUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/teiid",

// REST URL - Komodo service
komodoServiceUrl: "https://localhost:8443/vdb-builder/v1/service",
komodoServiceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/service"

};
16 changes: 12 additions & 4 deletions ngapp/src/environments/environment.ts
Expand Up @@ -21,22 +21,30 @@ import { DataservicesConstants } from "@dataservices/shared/dataservices-constan
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const komodoEngine = "vdb-builder";

export const komodoRestVersion = "v1";

export const environment = {
production: false,

komodoEngine: komodoEngine,

komodoRestVersion: komodoRestVersion,

// the home page path
homePagePath: DataservicesConstants.dataservicesRootPath,

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
komodoImportExportUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/importexport",

// REST URL - Komodo workspace
komodoWorkspaceUrl: "https://localhost:8443/vdb-builder/v1/workspace",
komodoWorkspaceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/workspace",

// REST URL - Komodo teiid server
komodoTeiidUrl: "https://localhost:8443/vdb-builder/v1/teiid",
komodoTeiidUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/teiid",

// REST URL - Komodo service
komodoServiceUrl: "https://localhost:8443/vdb-builder/v1/service",
komodoServiceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/service"

};

0 comments on commit 1bb9749

Please sign in to comment.