Repository: metron Updated Branches: refs/heads/master fcd644ca7 -> 3c4c069b6
METRON-1875 Expose configurable global settings in the Alerts UI (merrimanr) closes apache/metron#1266 Project: http://git-wip-us.apache.org/repos/asf/metron/repo Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/3c4c069b Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/3c4c069b Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/3c4c069b Branch: refs/heads/master Commit: 3c4c069b6f29824122dd93ac6f234ef1d0363e9d Parents: fcd644c Author: merrimanr <[email protected]> Authored: Fri Nov 16 14:38:44 2018 -0600 Committer: rmerriman <[email protected]> Committed: Fri Nov 16 14:38:44 2018 -0600 ---------------------------------------------------------------------- .../docker/rpm-docker/SPECS/metron.spec | 1 + .../table-view/table-view.component.spec.ts | 11 +++++- .../tree-view/tree-view.component.spec.ts | 11 +++++- .../metron-alerts/src/app/app.module.ts | 11 +++--- .../pcap-panel/pcap-panel.component.spec.ts | 9 +++++ .../src/app/pcap/service/pcap.service.spec.ts | 13 ++++++- .../src/app/pcap/service/pcap.service.ts | 17 ++++---- .../src/app/service/alerts.service.ts | 5 ++- .../src/app/service/app-config.service.ts | 41 ++++++++++++++++++++ .../src/app/service/authentication.service.ts | 10 +++-- .../src/app/service/column-names.service.ts | 4 -- .../src/app/service/global-config.service.ts | 5 ++- .../src/app/service/meta-alert.service.ts | 11 +++--- .../src/app/service/search.service.ts | 11 +++--- .../src/app/service/update.service.ts | 9 +++-- .../metron-alerts/src/assets/app-config.json | 3 ++ 16 files changed, 129 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec ---------------------------------------------------------------------- diff --git a/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec index 14c08a1..2839ffa 100644 --- a/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec +++ b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec @@ -540,6 +540,7 @@ This package installs the Metron Alerts UI %{metron_home} %attr(0644,root,root) %{metron_home}/web/alerts-ui/assets/fonts/Roboto/LICENSE.txt %attr(0644,root,root) %{metron_home}/web/alerts-ui/assets/fonts/Roboto/*.ttf %attr(0644,root,root) %{metron_home}/web/alerts-ui/assets/images/* +%attr(0644,root,root) %{metron_home}/web/alerts-ui/assets/app-config.json # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/alerts/alerts-list/table-view/table-view.component.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/table-view/table-view.component.spec.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/table-view/table-view.component.spec.ts index 2d7af57..8f2b4c4 100644 --- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/table-view/table-view.component.spec.ts +++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/table-view/table-view.component.spec.ts @@ -31,12 +31,20 @@ import { UpdateService } from '../../../service/update.service'; import { GlobalConfigService } from '../../../service/global-config.service'; import { MetaAlertService } from '../../../service/meta-alert.service'; import { DialogService } from 'app/service/dialog.service'; +import { AppConfigService } from '../../../service/app-config.service'; @Component({selector: 'metron-table-pagination', template: ''}) class MetronTablePaginationComponent { @Input() pagination = 0; } +class FakeAppConfigService { + + getApiRoot() { + return '/api/v1' + } +} + describe('TableViewComponent', () => { let component: TableViewComponent; let fixture: ComponentFixture<TableViewComponent>; @@ -50,7 +58,8 @@ describe('TableViewComponent', () => { UpdateService, GlobalConfigService, MetaAlertService, - DialogService + DialogService, + { provide: AppConfigService, useClass: FakeAppConfigService } ], declarations: [ MetronTableDirective, http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/alerts/alerts-list/tree-view/tree-view.component.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/tree-view/tree-view.component.spec.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/tree-view/tree-view.component.spec.ts index fda2b78..3fc145f 100644 --- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/tree-view/tree-view.component.spec.ts +++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/tree-view/tree-view.component.spec.ts @@ -32,6 +32,14 @@ import { UpdateService } from '../../../service/update.service'; import { GlobalConfigService } from '../../../service/global-config.service'; import { MetaAlertService } from '../../../service/meta-alert.service'; import { DialogService } from 'app/service/dialog.service'; +import { AppConfigService } from '../../../service/app-config.service'; + +class FakeAppConfigService { + + getApiRoot() { + return '/api/v1' + } +} describe('TreeViewComponent', () => { let component: TreeViewComponent; @@ -45,7 +53,8 @@ describe('TreeViewComponent', () => { UpdateService, GlobalConfigService, MetaAlertService, - DialogService + DialogService, + { provide: AppConfigService, useClass: FakeAppConfigService } ], declarations: [ MetronTableDirective, http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/app.module.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/app.module.ts b/metron-interface/metron-alerts/src/app/app.module.ts index a605b80..7abc2ae 100644 --- a/metron-interface/metron-alerts/src/app/app.module.ts +++ b/metron-interface/metron-alerts/src/app/app.module.ts @@ -48,13 +48,11 @@ import { GlobalConfigService } from './service/global-config.service'; import { DefaultHeadersInterceptor } from './http-interceptors/default-headers.interceptor'; import { DialogService } from './service/dialog.service'; import { MetronDialogComponent } from './shared/metron-dialog/metron-dialog.component'; - - - import {PcapModule} from './pcap/pcap.module'; +import { AppConfigService } from './service/app-config.service'; -export function initConfig(config: ColumnNamesService) { - return () => config.list(); +export function initConfig(appConfigService: AppConfigService) { + return () => appConfigService.loadAppConfig(); } @NgModule({ @@ -78,9 +76,10 @@ export function initConfig(config: ColumnNamesService) { SwitchModule, PcapModule ], - providers: [{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ColumnNamesService], multi: true }, + providers: [{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [AppConfigService], multi: true }, { provide: DataSource, useClass: ElasticSearchLocalstorageImpl }, { provide: HTTP_INTERCEPTORS, useClass: DefaultHeadersInterceptor, multi: true }, + AppConfigService, AuthenticationService, AuthGuard, LoginGuard, http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts index 29bd649..963b877 100644 --- a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts +++ b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts @@ -28,6 +28,7 @@ import { PcapRequest } from '../model/pcap.request'; import { of, defer } from 'rxjs'; import { RestError } from '../../model/rest-error'; import { ConfirmationPopoverModule } from 'angular-confirmation-popover'; +import { AppConfigService } from '../../service/app-config.service'; @Component({ selector: 'app-pcap-filters', @@ -60,6 +61,13 @@ class FakePcapService { } } +class FakeAppConfigService { + + getApiRoot() { + return '/api/v1' + } +} + describe('PcapPanelComponent', () => { let component: PcapPanelComponent; let fixture: ComponentFixture<PcapPanelComponent>; @@ -77,6 +85,7 @@ describe('PcapPanelComponent', () => { ], providers: [ { provide: PcapService, useClass: FakePcapService }, + { provide: AppConfigService, useClass: FakeAppConfigService } ] }) .compileComponents(); http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.spec.ts b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.spec.ts index 383c047..98537c2 100644 --- a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.spec.ts +++ b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.spec.ts @@ -33,6 +33,7 @@ import { PcapStatusResponse } from '../model/pcap-status-response'; import { PcapRequest } from '../model/pcap.request'; import { fakePdml, fakePacket } from '../model/pdml.mock'; import { fakePcapStatusResponse, fakePcapRequest } from '../model/pcap.mock'; +import { AppConfigService } from '../../service/app-config.service'; const jobId = 'job_1234567890123_4567'; let pdmlJsonMock = fakePdml; @@ -42,11 +43,21 @@ let mockBackend: HttpTestingController; pdmlJsonMock['pdml']['packet'].push(fakePacket); +class FakeAppConfigService { + + getApiRoot() { + return '/api/v1' + } +} + describe('PcapService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], - providers: [PcapService] + providers: [ + PcapService, + { provide: AppConfigService, useClass: FakeAppConfigService } + ] }); injector = getTestBed(); pcapService = injector.get(PcapService); http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts index d6fe767..eb6f045 100644 --- a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts +++ b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts @@ -25,6 +25,7 @@ import { HttpUtil } from '../../utils/httpUtil'; import { PcapRequest } from '../model/pcap.request'; import { Pdml } from '../model/pdml'; import { PcapStatusResponse } from '../model/pcap-status-response'; +import { AppConfigService } from '../../service/app-config.service'; @Injectable() export class PcapService { @@ -34,7 +35,7 @@ export class PcapService { 'X-Requested-With': 'XMLHttpRequest' }; - constructor(private http: HttpClient) {} + constructor(private http: HttpClient, private appConfigService: AppConfigService) {} public pollStatus(id: string): Observable<{}> { return interval(this.statusInterval * 1000).pipe( @@ -47,47 +48,47 @@ export class PcapService { public submitRequest( pcapRequest: PcapRequest ): Observable<PcapStatusResponse> { - return this.http.post('/api/v1/pcap/fixed', pcapRequest).pipe( + return this.http.post(this.appConfigService.getApiRoot() + '/pcap/fixed', pcapRequest).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError) ); } public getStatus(id: string): Observable<PcapStatusResponse> { - return this.http.get(`/api/v1/pcap/${id}`).pipe( + return this.http.get(this.appConfigService.getApiRoot() + `/pcap/${id}`).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError) ); } public getRunningJob(): Observable<PcapStatusResponse[]> { - return this.http.get(`/api/v1/pcap?state=RUNNING`).pipe( + return this.http.get(this.appConfigService.getApiRoot() + '/pcap?state=RUNNING').pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError) ); } public getPackets(id: string, pageId: number): Observable<Pdml> { - return this.http.get(`/api/v1/pcap/${id}/pdml?page=${pageId}`).pipe( + return this.http.get(this.appConfigService.getApiRoot() + `/pcap/${id}/pdml?page=${pageId}`).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError) ); } public getPcapRequest(id: string): Observable<PcapRequest> { - return this.http.get(`/api/v1/pcap/${id}/config`).pipe( + return this.http.get(this.appConfigService.getApiRoot() + `/pcap/${id}/config`).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError) ); } public getDownloadUrl(id: string, pageId: number) { - return `/api/v1/pcap/${id}/raw?page=${pageId}`; + return this.appConfigService.getApiRoot() + `/pcap/${id}/raw?page=${pageId}`; } public cancelQuery(queryId: string) { return this.http - .delete(`/api/v1/pcap/kill/${queryId}`) + .delete(this.appConfigService.getApiRoot() + `/pcap/kill/${queryId}`) .pipe(catchError(HttpUtil.handleError)); } } http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/alerts.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/alerts.service.ts b/metron-interface/metron-alerts/src/app/service/alerts.service.ts index 3a329ab..755b14e 100644 --- a/metron-interface/metron-alerts/src/app/service/alerts.service.ts +++ b/metron-interface/metron-alerts/src/app/service/alerts.service.ts @@ -22,14 +22,15 @@ import {Alert} from '../model/alert'; import { HttpClient } from '@angular/common/http'; import {HttpUtil} from '../utils/httpUtil'; import { RestError } from '../model/rest-error'; +import {AppConfigService} from './app-config.service'; @Injectable() export class AlertsService { - constructor(private http: HttpClient) {} + constructor(private http: HttpClient, private appConfigService: AppConfigService) {} public escalate(alerts: Alert[]): Observable<Object | RestError> { - return this.http.post('/api/v1/alerts/ui/escalate', alerts).pipe( + return this.http.post(this.appConfigService.getApiRoot() + '/alerts/ui/escalate', alerts).pipe( catchError(HttpUtil.handleError)); } } http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/app-config.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/app-config.service.ts b/metron-interface/metron-alerts/src/app/service/app-config.service.ts new file mode 100644 index 0000000..0445f35 --- /dev/null +++ b/metron-interface/metron-alerts/src/app/service/app-config.service.ts @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +@Injectable() +export class AppConfigService { + + private appConfig; + + constructor(private http: HttpClient) { } + + loadAppConfig() { + return this.http.get('assets/app-config.json') + // APP_INITIALIZER only supports promises + .toPromise() + .then(data => { + this.appConfig = data; + }); + } + + getApiRoot() { + return this.appConfig['apiRoot']; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/authentication.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/authentication.service.ts b/metron-interface/metron-alerts/src/app/service/authentication.service.ts index ad81b94..7739be1 100644 --- a/metron-interface/metron-alerts/src/app/service/authentication.service.ts +++ b/metron-interface/metron-alerts/src/app/service/authentication.service.ts @@ -22,13 +22,14 @@ import {Router} from '@angular/router'; import { ReplaySubject } from 'rxjs'; import { GlobalConfigService } from './global-config.service'; import { DataSource } from './data-source'; +import { AppConfigService } from './app-config.service'; @Injectable() export class AuthenticationService { private static USER_NOT_VERIFIED = 'USER-NOT-VERIFIED'; private currentUser: string = AuthenticationService.USER_NOT_VERIFIED; - loginUrl = '/api/v1/user'; + loginUrl = this.appConfigService.getApiRoot() + '/user'; logoutUrl = '/logout'; onLoginEvent: ReplaySubject<boolean> = new ReplaySubject<boolean>(); $onLoginEvent = this.onLoginEvent.asObservable(); @@ -36,12 +37,13 @@ export class AuthenticationService { constructor(private http: HttpClient, private router: Router, private globalConfigService: GlobalConfigService, - private dataSource: DataSource) { + private dataSource: DataSource, + private appConfigService: AppConfigService) { this.init(); } public init() { - this.getCurrentUser({responseType: 'text'}).subscribe((response) => { + this.getCurrentUser({ headers: new HttpHeaders({'Accept': 'text/plain'}), responseType: 'text'}).subscribe((response) => { this.currentUser = response.toString(); if (this.currentUser) { this.onLoginEvent.next(true); @@ -54,7 +56,7 @@ export class AuthenticationService { public login(username: string, password: string, onError): void { let credentials = btoa(username + ':' + password); - this.getCurrentUser({ headers: new HttpHeaders({'Authorization': `Basic ${credentials}`}), responseType: 'text' }) + this.getCurrentUser({ headers: new HttpHeaders({'Authorization': `Basic ${credentials}`, 'Accept': 'text/plain'}), responseType: 'text' }) .subscribe((response) => { this.currentUser = response.toString(); this.router.navigateByUrl('/alerts-list'); http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/column-names.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/column-names.service.ts b/metron-interface/metron-alerts/src/app/service/column-names.service.ts index d270fd8..afdcd1c 100644 --- a/metron-interface/metron-alerts/src/app/service/column-names.service.ts +++ b/metron-interface/metron-alerts/src/app/service/column-names.service.ts @@ -59,10 +59,6 @@ export class ColumnNamesService { constructor(private dataSource: DataSource) {} - list(): Promise<ColumnNames[]> { - return this.dataSource.getAlertTableColumnNames().toPromise(); - } - save(columns: ColumnNames[]): Observable<{}> { return this.dataSource.saveAlertTableColumnNames(columns); } http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/global-config.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/global-config.service.ts b/metron-interface/metron-alerts/src/app/service/global-config.service.ts index 14ec3f3..c6ed131 100644 --- a/metron-interface/metron-alerts/src/app/service/global-config.service.ts +++ b/metron-interface/metron-alerts/src/app/service/global-config.service.ts @@ -21,14 +21,15 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import {HttpUtil} from '../utils/httpUtil'; +import { AppConfigService } from './app-config.service'; @Injectable() export class GlobalConfigService { - url = 'api/v1/global/config'; + url = this.appConfigService.getApiRoot() + '/global/config'; private globalConfig = {}; - constructor(private http: HttpClient) {} + constructor(private http: HttpClient, private appConfigService: AppConfigService) {} public get(): Observable<{}> { return this.http.get(this.url).pipe( http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/meta-alert.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/meta-alert.service.ts b/metron-interface/metron-alerts/src/app/service/meta-alert.service.ts index c1b7a5b..59ea0a7 100644 --- a/metron-interface/metron-alerts/src/app/service/meta-alert.service.ts +++ b/metron-interface/metron-alerts/src/app/service/meta-alert.service.ts @@ -26,6 +26,7 @@ import {Alert} from '../model/alert'; import { HttpClient } from '@angular/common/http'; import {MetaAlertCreateRequest} from '../model/meta-alert-create-request'; import {MetaAlertAddRemoveRequest} from '../model/meta-alert-add-remove-request'; +import { AppConfigService } from './app-config.service'; @Injectable() export class MetaAlertService { @@ -33,7 +34,7 @@ export class MetaAlertService { alertChangedSource = new Subject<MetaAlertAddRemoveRequest>(); alertChanged$ = this.alertChangedSource.asObservable(); - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private appConfigService: AppConfigService) { } get selectedAlerts(): Alert[] { @@ -45,13 +46,13 @@ export class MetaAlertService { } public create(metaAlertCreateRequest: MetaAlertCreateRequest): Observable<{}> { - let url = '/api/v1/metaalert/create'; + let url = this.appConfigService.getApiRoot() + '/metaalert/create'; return this.http.post(url, metaAlertCreateRequest).pipe( catchError(HttpUtil.handleError)); } public addAlertsToMetaAlert(metaAlertAddRemoveRequest: MetaAlertAddRemoveRequest) { - let url = '/api/v1/metaalert/add/alert'; + let url = this.appConfigService.getApiRoot() + '/metaalert/add/alert'; return this.http.post(url, metaAlertAddRemoveRequest).pipe( catchError(HttpUtil.handleError), map(result => { @@ -61,7 +62,7 @@ export class MetaAlertService { } public removeAlertsFromMetaAlert(metaAlertAddRemoveRequest: MetaAlertAddRemoveRequest) { - let url = '/api/v1/metaalert/remove/alert'; + let url = this.appConfigService.getApiRoot() + '/metaalert/remove/alert'; return this.http.post(url, metaAlertAddRemoveRequest).pipe( catchError(HttpUtil.handleError), map(result => { @@ -71,7 +72,7 @@ export class MetaAlertService { } public updateMetaAlertStatus(guid: string, status: string) { - let url = `/api/v1/metaalert/update/status/${guid}/${status}`; + let url = this.appConfigService.getApiRoot() + `/metaalert/update/status/${guid}/${status}`; return this.http.post(url, {}).pipe( catchError(HttpUtil.handleError), map(result => { http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/search.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/search.service.ts b/metron-interface/metron-alerts/src/app/service/search.service.ts index 7e88966..e599a88 100644 --- a/metron-interface/metron-alerts/src/app/service/search.service.ts +++ b/metron-interface/metron-alerts/src/app/service/search.service.ts @@ -30,6 +30,7 @@ import { RestError } from '../model/rest-error'; import {INDEXES} from '../utils/constants'; import {ColumnMetadata} from '../model/column-metadata'; import {QueryBuilder} from '../alerts/alerts-list/query-builder'; +import { AppConfigService } from './app-config.service'; @Injectable() export class SearchService { @@ -52,10 +53,10 @@ export class SearchService { } constructor(private http: HttpClient, - private ngZone: NgZone) { } + private ngZone: NgZone, private appConfigService: AppConfigService) { } groups(groupRequest: GroupRequest): Observable<GroupResult> { - let url = '/api/v1/search/group'; + let url = this.appConfigService.getApiRoot() + '/search/group'; return this.http.post(url, groupRequest).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError), @@ -63,7 +64,7 @@ export class SearchService { } public getAlert(sourceType: string, alertId: string): Observable<AlertSource> { - let url = '/api/v1/search/findOne'; + let url = this.appConfigService.getApiRoot() + '/search/findOne'; let requestSchema = { guid: alertId, sensorType: sourceType}; return this.http.post(url, requestSchema).pipe( map(HttpUtil.extractData), @@ -72,7 +73,7 @@ export class SearchService { } public getColumnMetaData(): Observable<RestError | ColumnMetadata[]> { - let url = '/api/v1/search/column/metadata'; + let url = this.appConfigService.getApiRoot() + '/search/column/metadata'; return this.http.post(url, INDEXES).pipe( map(HttpUtil.extractData), map(SearchService.extractColumnNameDataFromRestApi), @@ -90,7 +91,7 @@ export class SearchService { } public search(searchRequest: SearchRequest): Observable<SearchResponse> { - let url = '/api/v1/search/search'; + let url = this.appConfigService.getApiRoot() + '/search/search'; return this.http.post(url, searchRequest).pipe( map(HttpUtil.extractData), catchError(HttpUtil.handleError), http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/app/service/update.service.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/service/update.service.ts b/metron-interface/metron-alerts/src/app/service/update.service.ts index 448d475..6ce2c73 100644 --- a/metron-interface/metron-alerts/src/app/service/update.service.ts +++ b/metron-interface/metron-alerts/src/app/service/update.service.ts @@ -28,6 +28,7 @@ import {Utils} from '../utils/utils'; import {Patch} from '../model/patch'; import { GlobalConfigService } from './global-config.service'; import {CommentAddRemoveRequest} from "../model/comment-add-remove-request"; +import { AppConfigService } from './app-config.service'; @Injectable() export class UpdateService { @@ -38,14 +39,14 @@ export class UpdateService { alertCommentChangedSource = new Subject<CommentAddRemoveRequest>(); alertCommentChanged$ = this.alertCommentChangedSource.asObservable(); - constructor(private http: HttpClient, private globalConfigService: GlobalConfigService) { + constructor(private http: HttpClient, private globalConfigService: GlobalConfigService, private appConfigService: AppConfigService) { this.globalConfigService.get().subscribe((config: {}) => { this.sourceType = config['source.type.field']; }); } public addComment(commentRequest: CommentAddRemoveRequest, fireChangeListener = true): Observable<{}> { - let url = '/api/v1/update/add/comment'; + let url = this.appConfigService.getApiRoot() + '/update/add/comment'; return this.http.post(url, commentRequest).pipe( catchError(HttpUtil.handleError), map(result => { @@ -57,7 +58,7 @@ export class UpdateService { } public removeComment(commentRequest: CommentAddRemoveRequest, fireChangeListener = true): Observable<{}> { - let url = '/api/v1/update/remove/comment'; + let url = this.appConfigService.getApiRoot() + '/update/remove/comment'; return this.http.post(url, commentRequest).pipe( catchError(HttpUtil.handleError), map(result => { @@ -69,7 +70,7 @@ export class UpdateService { } public patch(patchRequest: PatchRequest, fireChangeListener = true): Observable<{}> { - let url = '/api/v1/update/patch'; + let url = this.appConfigService.getApiRoot() + '/update/patch'; return this.http.patch(url, patchRequest).pipe( catchError(HttpUtil.handleError), map(result => { http://git-wip-us.apache.org/repos/asf/metron/blob/3c4c069b/metron-interface/metron-alerts/src/assets/app-config.json ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/assets/app-config.json b/metron-interface/metron-alerts/src/assets/app-config.json new file mode 100644 index 0000000..7fa734d --- /dev/null +++ b/metron-interface/metron-alerts/src/assets/app-config.json @@ -0,0 +1,3 @@ +{ + "apiRoot": "/api/v1" +} \ No newline at end of file
