diff --git a/src/portal/server/src/mock-api.ts b/src/portal/server/src/mock-api.ts index d489127c3..ef39f5655 100644 --- a/src/portal/server/src/mock-api.ts +++ b/src/portal/server/src/mock-api.ts @@ -1,6 +1,7 @@ import express from "express"; import { Express } from 'express'; import * as Controllers from '../controllers'; +import { CURRENT_BASE_HREF } from "../../src/lib/utils/utils"; const mockApi: Express = express(); @@ -9,7 +10,7 @@ mockApi.get('/', (req, res) => { res.send('Hello World!'); }); -mockApi.get('/api/scanners', Controllers.getScanner); +mockApi.get(CURRENT_BASE_HREF + '/scanners', Controllers.getScanner); mockApi.listen(3000, () => { console.log('Api server listening on port 3000!'); diff --git a/src/portal/src/app/account/account-settings/account-settings-modal-service.service.ts b/src/portal/src/app/account/account-settings/account-settings-modal-service.service.ts index 2a497248a..bf290ff6f 100644 --- a/src/portal/src/app/account/account-settings/account-settings-modal-service.service.ts +++ b/src/portal/src/app/account/account-settings/account-settings-modal-service.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { catchError, map } from 'rxjs/operators'; import { throwError as observableThrowError, Observable } from 'rxjs'; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; @@ -11,7 +12,7 @@ export class AccountSettingsModalService { constructor(private http: HttpClient) { } saveNewCli(userId, secretObj): Observable { - return this.http.put(`/api/users/${userId}/cli_secret`, secretObj).pipe( map(response => response) + return this.http.put(`${ CURRENT_BASE_HREF }/users/${userId}/cli_secret`, secretObj).pipe( map(response => response) , catchError(error => observableThrowError(error))); } } diff --git a/src/portal/src/app/account/password-setting/password-setting.service.spec.ts b/src/portal/src/app/account/password-setting/password-setting.service.spec.ts index 9a20127de..6e5cb0c32 100644 --- a/src/portal/src/app/account/password-setting/password-setting.service.spec.ts +++ b/src/portal/src/app/account/password-setting/password-setting.service.spec.ts @@ -1,6 +1,7 @@ import { TestBed, inject, getTestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { PasswordSettingService } from './password-setting.service'; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; describe('PasswordSettingService', () => { let injector: TestBed; @@ -32,7 +33,7 @@ describe('PasswordSettingService', () => { expect(res).toEqual(null); }); - const req = httpMock.expectOne('/api/users/1/password'); + const req = httpMock.expectOne(CURRENT_BASE_HREF + '/users/1/password'); expect(req.request.method).toBe('PUT'); req.flush(null); }); diff --git a/src/portal/src/app/account/password-setting/password-setting.service.ts b/src/portal/src/app/account/password-setting/password-setting.service.ts index ae03e777e..3f86e175d 100644 --- a/src/portal/src/app/account/password-setting/password-setting.service.ts +++ b/src/portal/src/app/account/password-setting/password-setting.service.ts @@ -16,9 +16,9 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { PasswordSetting } from './password-setting'; -import { HTTP_FORM_OPTIONS, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_FORM_OPTIONS, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils"; -const passwordChangeEndpoint = "/api/users/:user_id/password"; +const passwordChangeEndpoint = CURRENT_BASE_HREF + "/users/:user_id/password"; const sendEmailEndpoint = "/c/sendEmail"; const resetPasswordEndpoint = "/c/reset"; diff --git a/src/portal/src/app/app-config.service.spec.ts b/src/portal/src/app/app-config.service.spec.ts index 44eacda88..85ae194c2 100644 --- a/src/portal/src/app/app-config.service.spec.ts +++ b/src/portal/src/app/app-config.service.spec.ts @@ -4,6 +4,7 @@ import { CookieService } from 'ngx-cookie'; import { AppConfigService } from './app-config.service'; import { AppConfig } from './app-config'; import { Component } from '@angular/core'; +import { CURRENT_BASE_HREF } from "../lib/utils/utils"; describe('AppConfigService', () => { let injector: TestBed; @@ -35,7 +36,7 @@ describe('AppConfigService', () => { expect(res).toEqual(systeminfo); }); - const req = httpMock.expectOne('/api/systeminfo'); + const req = httpMock.expectOne(CURRENT_BASE_HREF + '/systeminfo'); expect(req.request.method).toBe('GET'); req.flush(systeminfo); expect(service.getConfig()).toEqual(systeminfo); diff --git a/src/portal/src/app/app-config.service.ts b/src/portal/src/app/app-config.service.ts index 5e82b0039..276a197c4 100644 --- a/src/portal/src/app/app-config.service.ts +++ b/src/portal/src/app/app-config.service.ts @@ -19,9 +19,9 @@ import { CookieKeyOfAdmiral, HarborQueryParamKey } from './shared/shared.const'; import { maintainUrlQueryParmas } from './shared/shared.utils'; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; -import { HTTP_GET_OPTIONS } from "../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS } from "../lib/utils/utils"; import { CONFIG_AUTH_MODE } from "../lib/entities/shared.const"; -export const systemInfoEndpoint = "/api/systeminfo"; +export const systemInfoEndpoint = CURRENT_BASE_HREF + "/systeminfo"; /** * Declare service to handle the bootstrap options * diff --git a/src/portal/src/app/app.module.ts b/src/portal/src/app/app.module.ts index 83dd219fe..9c530b644 100644 --- a/src/portal/src/app/app.module.ts +++ b/src/portal/src/app/app.module.ts @@ -45,7 +45,6 @@ import { LabelsComponent } from './labels/labels.component'; import { ProjectQuotasComponent } from './project-quotas/project-quotas.component'; import { HarborLibraryModule } from "../lib/harbor-library.module"; import { HTTP_INTERCEPTORS } from '@angular/common/http'; -import { BaseHrefInterceptService } from "./base-href-intercept.service"; registerLocaleData(zh, 'zh-cn'); registerLocaleData(es, 'es-es'); @@ -99,7 +98,6 @@ export function getCurrentLanguage(translateService: TranslateService) { multi: true }, { provide: LOCALE_ID, useValue: "en-US" }, - { provide: HTTP_INTERCEPTORS, useClass: BaseHrefInterceptService, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: InterceptHttpService, multi: true } ], diff --git a/src/portal/src/app/base-href-intercept.service.spec.ts b/src/portal/src/app/base-href-intercept.service.spec.ts deleted file mode 100644 index bd7d791c0..000000000 --- a/src/portal/src/app/base-href-intercept.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { BaseHrefInterceptService } from "./base-href-intercept.service"; - - -describe('BaseHrefSwitchService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [ - BaseHrefInterceptService - ] - }); - }); - - it('should be created', () => { - const service: BaseHrefInterceptService = TestBed.get(BaseHrefInterceptService); - expect(service).toBeTruthy(); - }); -}); diff --git a/src/portal/src/app/base-href-intercept.service.ts b/src/portal/src/app/base-href-intercept.service.ts deleted file mode 100644 index b8e69aa45..000000000 --- a/src/portal/src/app/base-href-intercept.service.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Injectable } from '@angular/core'; -import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; -import { Observable } from "rxjs"; - -const BASE_HREF = '/api'; -enum APILevels { - 'V1.0' = '', - 'V2.0' = '/v2.0' -} -@Injectable() -export class BaseHrefInterceptService implements HttpInterceptor { - intercept(req: HttpRequest, next: HttpHandler): Observable { - let url: string = req.url; - // use API level v2.0 - if (url && url.indexOf(BASE_HREF) !== -1 && url.indexOf(BASE_HREF + APILevels["V2.0"]) === -1) { - url = BASE_HREF + APILevels["V2.0"] + url.split(BASE_HREF)[1]; - } - const apiReq = req.clone({url}); - return next.handle(apiReq); - } -} - diff --git a/src/portal/src/app/base/global-search/global-search.service.spec.ts b/src/portal/src/app/base/global-search/global-search.service.spec.ts index d3789e49b..6cb314ff7 100644 --- a/src/portal/src/app/base/global-search/global-search.service.spec.ts +++ b/src/portal/src/app/base/global-search/global-search.service.spec.ts @@ -3,6 +3,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { GlobalSearchService } from './global-search.service'; import { Injector } from '@angular/core'; import { SearchResults } from './search-results'; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; describe('GlobalSearchService', () => { let injector: TestBed; @@ -31,7 +32,7 @@ describe('GlobalSearchService', () => { expect(res).toEqual(new SearchResults()); }); - const req = httpMock.expectOne('/api/search?q=library'); + const req = httpMock.expectOne(CURRENT_BASE_HREF + '/search?q=library'); expect(req.request.method).toBe('GET'); req.flush(new SearchResults()); }); diff --git a/src/portal/src/app/base/global-search/global-search.service.ts b/src/portal/src/app/base/global-search/global-search.service.ts index 3788b385b..00a59e83f 100644 --- a/src/portal/src/app/base/global-search/global-search.service.ts +++ b/src/portal/src/app/base/global-search/global-search.service.ts @@ -16,9 +16,9 @@ import { HttpClient } from '@angular/common/http'; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { SearchResults } from './search-results'; -import { HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; -const searchEndpoint = "/api/search"; +const searchEndpoint = CURRENT_BASE_HREF + "/search"; /** * Declare service to handle the global search * diff --git a/src/portal/src/app/config/config.service.ts b/src/portal/src/app/config/config.service.ts index 9687f1855..9082d02ef 100644 --- a/src/portal/src/app/config/config.service.ts +++ b/src/portal/src/app/config/config.service.ts @@ -16,12 +16,12 @@ import { HttpClient } from '@angular/common/http'; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { Configuration } from "../../lib/components/config/config"; -import { HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils"; -const configEndpoint = "/api/configurations"; -const emailEndpoint = "/api/email/ping"; -const ldapEndpoint = "/api/ldap/ping"; -const oidcEndpoint = "/api/system/oidc/ping"; +const configEndpoint = CURRENT_BASE_HREF + "/configurations"; +const emailEndpoint = CURRENT_BASE_HREF + "/email/ping"; +const ldapEndpoint = CURRENT_BASE_HREF + "/ldap/ping"; +const oidcEndpoint = CURRENT_BASE_HREF + "/system/oidc/ping"; @Injectable() export class ConfigurationService { diff --git a/src/portal/src/app/config/scanner/config-scanner.service.ts b/src/portal/src/app/config/scanner/config-scanner.service.ts index 40187177a..a113514df 100644 --- a/src/portal/src/app/config/scanner/config-scanner.service.ts +++ b/src/portal/src/app/config/scanner/config-scanner.service.ts @@ -4,6 +4,7 @@ import { forkJoin, Observable, throwError as observableThrowError } from "rxjs"; import { catchError, map } from "rxjs/operators"; import { HttpClient } from "@angular/common/http"; import { ScannerMetadata } from "./scanner-metadata"; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; export const SCANNERS_DOC: string = "https://github.com/goharbor/harbor/blob/master/docs/harbor_compatibility_list.md"; @@ -13,35 +14,35 @@ export class ConfigScannerService { constructor( private http: HttpClient) {} getScannersByName(name: string): Observable { name = encodeURIComponent(name); - return this.http.get(`/api/scanners?ex_name=${name}`) + return this.http.get(`${ CURRENT_BASE_HREF }/scanners?ex_name=${name}`) .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response as Scanner[])); } getScannersByEndpointUrl(endpointUrl: string): Observable { endpointUrl = encodeURIComponent(endpointUrl); - return this.http.get(`/api/scanners?ex_url=${endpointUrl}`) + return this.http.get(`${ CURRENT_BASE_HREF }/scanners?ex_url=${endpointUrl}`) .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response as Scanner[])); } testEndpointUrl(testValue: any): Observable { - return this.http.post(`/api/scanners/ping`, testValue) + return this.http.post(`${ CURRENT_BASE_HREF }/scanners/ping`, testValue) .pipe(catchError(error => observableThrowError(error))); } addScanner(scanner: Scanner): Observable { - return this.http.post('/api/scanners', scanner ) + return this.http.post(CURRENT_BASE_HREF + '/scanners', scanner ) .pipe(catchError(error => observableThrowError(error))); } getScanners(): Observable { - return this.http.get('/api/scanners') + return this.http.get(CURRENT_BASE_HREF + '/scanners') .pipe(map(response => response as Scanner[])) .pipe(catchError(error => observableThrowError(error))); } updateScanner(scanner: Scanner): Observable { - return this.http.put(`/api/scanners/${scanner.uuid}`, scanner ) + return this.http.put(`${ CURRENT_BASE_HREF }/scanners/${scanner.uuid}`, scanner ) .pipe(catchError(error => observableThrowError(error))); } deleteScanner(scanner: Scanner): Observable { - return this.http.delete(`/api/scanners/${scanner.uuid}`) + return this.http.delete(`${ CURRENT_BASE_HREF }/scanners/${scanner.uuid}`) .pipe(catchError(error => observableThrowError(error))); } deleteScanners(scanners: Scanner[]): Observable { @@ -54,25 +55,25 @@ export class ConfigScannerService { } } getProjectScanner(projectId: number): Observable { - return this.http.get(`/api/projects/${projectId}/scanner`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}/scanner`) .pipe(map(response => response as Scanner)) .pipe(catchError(error => observableThrowError(error))); } updateProjectScanner(projectId: number , uid: string): Observable { - return this.http.put(`/api/projects/${projectId}/scanner` , {uuid: uid}) + return this.http.put(`${ CURRENT_BASE_HREF }/projects/${projectId}/scanner` , {uuid: uid}) .pipe(catchError(error => observableThrowError(error))); } getScannerMetadata(uid: string): Observable { - return this.http.get(`/api/scanners/${uid}/metadata`) + return this.http.get(`${ CURRENT_BASE_HREF }/scanners/${uid}/metadata`) .pipe(map(response => response as ScannerMetadata)) .pipe(catchError(error => observableThrowError(error))); } setAsDefault(uid: string): Observable { - return this.http.patch(`/api/scanners/${uid}`, {is_default: true} ) + return this.http.patch(`${ CURRENT_BASE_HREF }/scanners/${uid}`, {is_default: true} ) .pipe(catchError(error => observableThrowError(error))); } getProjectScanners(projectId: number) { - return this.http.get(`/api/projects/${projectId}/scanner/candidates`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}/scanner/candidates`) .pipe(map(response => response as Scanner[])) .pipe(catchError(error => observableThrowError(error))); } diff --git a/src/portal/src/app/group/group.service.ts b/src/portal/src/app/group/group.service.ts index 003df66a6..9876b4ec6 100644 --- a/src/portal/src/app/group/group.service.ts +++ b/src/portal/src/app/group/group.service.ts @@ -3,10 +3,10 @@ import {catchError, map} from 'rxjs/operators'; import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { UserGroup } from "./group"; -import { HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils"; -const userGroupEndpoint = "/api/usergroups"; -const ldapGroupSearchEndpoint = "/api/ldap/groups/search?groupname="; +const userGroupEndpoint = CURRENT_BASE_HREF + "/usergroups"; +const ldapGroupSearchEndpoint = CURRENT_BASE_HREF + "/ldap/groups/search?groupname="; @Injectable() export class GroupService { diff --git a/src/portal/src/app/log/audit-log.service.ts b/src/portal/src/app/log/audit-log.service.ts index 8551d86be..7bcea24ff 100644 --- a/src/portal/src/app/log/audit-log.service.ts +++ b/src/portal/src/app/log/audit-log.service.ts @@ -18,10 +18,14 @@ import {map, catchError} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http'; import { AuditLog } from './audit-log'; -import { buildHttpRequestOptions, buildHttpRequestOptionsWithObserveResponse } from "../../lib/utils/utils"; +import { + buildHttpRequestOptions, + buildHttpRequestOptionsWithObserveResponse, + CURRENT_BASE_HREF +} from "../../lib/utils/utils"; import { RequestQueryParams } from "../../lib/services"; -export const logEndpoint = '/api/logs'; +export const logEndpoint = CURRENT_BASE_HREF + '/logs'; @Injectable() export class AuditLogService { @@ -46,7 +50,7 @@ export class AuditLogService { params = params.set('page_size', queryParam.page_size); } return this.http - .get>(`/api/projects/${queryParam.project_id}/logs` + .get>(`${ CURRENT_BASE_HREF }/projects/${queryParam.project_id}/logs` , buildHttpRequestOptionsWithObserveResponse(params)).pipe( catchError(error => observableThrowError(error)), ); } diff --git a/src/portal/src/app/project/member/member.service.ts b/src/portal/src/app/project/member/member.service.ts index ef7c94b34..b1d34d4c1 100644 --- a/src/portal/src/app/project/member/member.service.ts +++ b/src/portal/src/app/project/member/member.service.ts @@ -17,7 +17,7 @@ import { User } from '../../user/user'; import { Member } from './member'; import {throwError as observableThrowError, Observable } from "rxjs"; import {map, catchError} from 'rxjs/operators'; -import { HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils"; @Injectable() export class MemberService { @@ -26,7 +26,7 @@ export class MemberService { listMembers(projectId: number, entity_name: string): Observable { return this.http - .get(`/api/projects/${projectId}/members?entityname=${entity_name}`, HTTP_GET_OPTIONS).pipe( + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/members?entityname=${entity_name}`, HTTP_GET_OPTIONS).pipe( map(response => response as Member[]), catchError(error => observableThrowError(error)), ); } @@ -41,7 +41,7 @@ export class MemberService { return; } return this.http.post( - `/api/projects/${projectId}/members`, + `${ CURRENT_BASE_HREF }/projects/${projectId}/members`, { role_id: roleId, member_user: member_user @@ -52,7 +52,7 @@ export class MemberService { addGroupMember(projectId: number, group: any, roleId: number): Observable { return this.http - .post(`/api/projects/${projectId}/members`, + .post(`${ CURRENT_BASE_HREF }/projects/${projectId}/members`, { role_id: roleId, member_group: group}, HTTP_JSON_OPTIONS).pipe( catchError(error => observableThrowError(error)), ); @@ -60,13 +60,13 @@ export class MemberService { changeMemberRole(projectId: number, userId: number, roleId: number): Observable { return this.http - .put(`/api/projects/${projectId}/members/${userId}`, { role_id: roleId }, HTTP_JSON_OPTIONS) + .put(`${ CURRENT_BASE_HREF }/projects/${projectId}/members/${userId}`, { role_id: roleId }, HTTP_JSON_OPTIONS) .pipe(catchError(error => observableThrowError(error))); } deleteMember(projectId: number, memberId: number): Observable { return this.http - .delete(`/api/projects/${projectId}/members/${memberId}`) + .delete(`${ CURRENT_BASE_HREF }/projects/${projectId}/members/${memberId}`) .pipe(catchError(error => observableThrowError(error))); } } diff --git a/src/portal/src/app/project/repository/artifact-list-page/artifact-list-page.component.spec.ts b/src/portal/src/app/project/repository/artifact-list-page/artifact-list-page.component.spec.ts index 5c0e02d2e..029ea59c3 100644 --- a/src/portal/src/app/project/repository/artifact-list-page/artifact-list-page.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact-list-page/artifact-list-page.component.spec.ts @@ -13,6 +13,7 @@ import { AppConfigService } from "../../../app-config.service"; import { ArtifactService } from "../../../../../ng-swagger-gen/services/artifact.service"; import { ArtifactDefaultService } from "../artifact/artifact.service"; import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config"; +import { CURRENT_BASE_HREF } from "../../../../lib/utils/utils"; describe('ArtifactListPageComponent', () => { let component: ArtifactListPageComponent; @@ -70,7 +71,7 @@ describe('ArtifactListPageComponent', () => { } }; const config: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(async(() => { TestBed.configureTestingModule({ diff --git a/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-additions.component.spec.ts b/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-additions.component.spec.ts index e52b6667c..08317b904 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-additions.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-additions.component.spec.ts @@ -3,17 +3,18 @@ import { ArtifactAdditionsComponent } from './artifact-additions.component'; import { AdditionLinks } from "../../../../../../ng-swagger-gen/models/addition-links"; import { IServiceConfig, SERVICE_CONFIG } from "../../../../../lib/entities/service.config"; import { ProjectModule } from "../../../project.module"; +import { CURRENT_BASE_HREF } from "../../../../../lib/utils/utils"; describe('ArtifactAdditionsComponent', () => { const mockedAdditionLinks: AdditionLinks = { vulnerabilities: { absolute: false, - href: "api/v2/test" + href: CURRENT_BASE_HREF + "/test" } }; const config: IServiceConfig = { - baseEndpoint: "/api/v2" + baseEndpoint: CURRENT_BASE_HREF }; let component: ArtifactAdditionsComponent; let fixture: ComponentFixture; diff --git a/src/portal/src/app/project/repository/artifact/artifact-additions/dependencies/dependencies.component.spec.ts b/src/portal/src/app/project/repository/artifact/artifact-additions/dependencies/dependencies.component.spec.ts index 645fa7bd5..ca39bf9a9 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-additions/dependencies/dependencies.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-additions/dependencies/dependencies.component.spec.ts @@ -7,6 +7,7 @@ import { ArtifactDependency } from "../models"; import { AdditionLink } from "../../../../../../../ng-swagger-gen/models/addition-link"; import { IServiceConfig, SERVICE_CONFIG } from "../../../../../../lib/entities/service.config"; import { ErrorHandler } from "../../../../../../lib/utils/error-handler"; +import { CURRENT_BASE_HREF } from "../../../../../../lib/utils/utils"; describe('DependenciesComponent', () => { @@ -35,7 +36,7 @@ describe('DependenciesComponent', () => { href: '/test' }; const config: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(async(() => { TestBed.configureTestingModule({ diff --git a/src/portal/src/app/project/repository/artifact/artifact-additions/summary/summary.component.spec.ts b/src/portal/src/app/project/repository/artifact/artifact-additions/summary/summary.component.spec.ts index d773d8846..48416c1de 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-additions/summary/summary.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-additions/summary/summary.component.spec.ts @@ -7,6 +7,7 @@ import { AdditionLink } from "../../../../../../../ng-swagger-gen/models/additio import { IServiceConfig, SERVICE_CONFIG } from "../../../../../../lib/entities/service.config"; import { ErrorHandler } from "../../../../../../lib/utils/error-handler"; import { ProjectModule } from "../../../../project.module"; +import { CURRENT_BASE_HREF } from "../../../../../../lib/utils/utils"; describe('SummaryComponent', () => { let component: SummaryComponent; @@ -160,7 +161,7 @@ describe('SummaryComponent', () => { } }; const config: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(async(() => { TestBed.configureTestingModule({ diff --git a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts index dc8b1c6a9..bf62bcdea 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts @@ -9,6 +9,7 @@ import { SharedModule } from "../../../../../lib/utils/shared/shared.module"; import { ErrorHandler } from "../../../../../lib/utils/error-handler"; import { TagService } from "../../../../../lib/services"; import { OperationService } from "../../../../../lib/components/operation/operation.service"; +import { CURRENT_BASE_HREF } from "../../../../../lib/utils/utils"; describe('ArtifactTagComponent', () => { @@ -22,7 +23,7 @@ describe('ArtifactTagComponent', () => { deleteTag: () => of(null), }; const config: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(async(() => { TestBed.configureTestingModule({ diff --git a/src/portal/src/app/project/repository/artifact/artifact.service.spec.ts b/src/portal/src/app/project/repository/artifact/artifact.service.spec.ts index be8fc8729..78e26df4e 100644 --- a/src/portal/src/app/project/repository/artifact/artifact.service.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact.service.spec.ts @@ -2,11 +2,12 @@ import { TestBed, inject } from '@angular/core/testing'; import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config"; import { SharedModule } from "../../../../lib/utils/shared/shared.module"; import { TagDefaultService, TagService } from "../../../../lib/services"; +import { CURRENT_BASE_HREF } from "../../../../lib/utils/utils"; describe('TagService', () => { const mockConfig: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(() => { diff --git a/src/portal/src/app/project/repository/artifact/artifact.service.ts b/src/portal/src/app/project/repository/artifact/artifact.service.ts index 3cf5ca417..4e1a2a183 100644 --- a/src/portal/src/app/project/repository/artifact/artifact.service.ts +++ b/src/portal/src/app/project/repository/artifact/artifact.service.ts @@ -5,7 +5,7 @@ import { Observable, throwError as observableThrowError, Subject } from "rxjs"; import { Manifest, RequestQueryParams } from "../../../../lib/services"; import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config"; import { - buildHttpRequestOptionsWithObserveResponse, + buildHttpRequestOptionsWithObserveResponse, CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../../lib/utils/utils"; @@ -122,10 +122,10 @@ export class ArtifactDefaultService extends ArtifactService { super(); this._baseUrl = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint - : "/api/repositories"; + : CURRENT_BASE_HREF + "/repositories"; this._labelUrl = this.config.labelEndpoint ? this.config.labelEndpoint - : "/api/labels"; + : CURRENT_BASE_HREF + "/labels"; } @@ -138,7 +138,7 @@ export class ArtifactDefaultService extends ArtifactService { } // queryParams = queryParams.set("detail", "true"); - let url: string = `/api/v2.0/projects/${project_id}/repositories/${repositoryName}/artifacts`; + let url: string = `${ CURRENT_BASE_HREF }/projects/${project_id}/repositories/${repositoryName}/artifacts`; // /api/v2/projects/{project_id}/repositories/{repositoryName}/artifacts return this.http .get>(url, buildHttpRequestOptionsWithObserveResponse(queryParams)) @@ -164,7 +164,7 @@ export class ArtifactDefaultService extends ArtifactService { if (!artifactDigest) { return observableThrowError("Bad argument"); } - let url = `/api/v2.0/projects/${projectName}/repositories/${repositoryName}/artifacts/${artifactDigest}`; + let url = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${artifactDigest}`; return this.http.get(url).pipe(catchError(error => observableThrowError(error))) as Observable; } public deleteArtifact( @@ -176,7 +176,7 @@ export class ArtifactDefaultService extends ArtifactService { return observableThrowError("Bad argument"); } - let url: string = `/api/v2.0/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}`; + let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}`; return this.http .delete(url, HTTP_JSON_OPTIONS) .pipe(map(response => response) @@ -195,7 +195,7 @@ export class ArtifactDefaultService extends ArtifactService { } let _addLabelToImageUrl = ` - /api/v2.0/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels`; + ${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels`; return this.http .post(_addLabelToImageUrl, { id: labelId }, HTTP_JSON_OPTIONS) .pipe(catchError(error => observableThrowError(error))); @@ -212,7 +212,7 @@ export class ArtifactDefaultService extends ArtifactService { } let _addLabelToImageUrl = ` - /api/v2.0/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels/${labelId}`; + ${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels/${labelId}`; return this.http .delete(_addLabelToImageUrl) .pipe(catchError(error => observableThrowError(error))); diff --git a/src/portal/src/app/project/repository/repository-gridview.component.spec.ts b/src/portal/src/app/project/repository/repository-gridview.component.spec.ts index 481f74e21..a02ed9c22 100644 --- a/src/portal/src/app/project/repository/repository-gridview.component.spec.ts +++ b/src/portal/src/app/project/repository/repository-gridview.component.spec.ts @@ -25,6 +25,7 @@ import { ProjectModule } from "../project.module"; import { ActivatedRoute } from "@angular/router"; import { Repository as NewRepository } from "../../../../ng-swagger-gen/models/repository"; import { StrictHttpResponse as __StrictHttpResponse } from '../../../../ng-swagger-gen/strict-http-response'; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; describe('RepositoryComponentGridview (inline template)', () => { @@ -73,9 +74,9 @@ describe('RepositoryComponentGridview (inline template)', () => { let mockRepo: NewRepository[] = mockRepoData; let mockNginxRepo: NewRepository[] = mockRepoNginxData; let config: IServiceConfig = { - repositoryBaseEndpoint: '/api/repository/testing', - systemInfoEndpoint: '/api/systeminfo/testing', - targetBaseEndpoint: '/api/tag/testing' + repositoryBaseEndpoint: CURRENT_BASE_HREF + '/repository/testing', + systemInfoEndpoint: CURRENT_BASE_HREF + '/systeminfo/testing', + targetBaseEndpoint: CURRENT_BASE_HREF + '/tag/testing' }; const fakedErrorHandler = { error() { diff --git a/src/portal/src/app/project/repository/repository.service.spec.ts b/src/portal/src/app/project/repository/repository.service.spec.ts index cb0977ff5..abf780caf 100644 --- a/src/portal/src/app/project/repository/repository.service.spec.ts +++ b/src/portal/src/app/project/repository/repository.service.spec.ts @@ -3,11 +3,12 @@ import { TestBed, inject } from '@angular/core/testing'; import { RepositoryService, RepositoryDefaultService } from './repository.service'; import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config"; import { SharedModule } from "../../../lib/utils/shared/shared.module"; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; describe('RepositoryService', () => { const mockConfig: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; let config: IServiceConfig; @@ -37,7 +38,7 @@ describe('RepositoryService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.repositoryBaseEndpoint).toEqual("/api/repositories/testing"); + expect(config.repositoryBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/repositories/testing"); }); }); diff --git a/src/portal/src/app/project/repository/repository.service.ts b/src/portal/src/app/project/repository/repository.service.ts index 0474077fa..a2fd60662 100644 --- a/src/portal/src/app/project/repository/repository.service.ts +++ b/src/portal/src/app/project/repository/repository.service.ts @@ -4,7 +4,11 @@ import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { Repository, RepositoryItem, RequestQueryParams } from "../../../lib/services"; import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config"; -import { buildHttpRequestOptionsWithObserveResponse, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils"; +import { + buildHttpRequestOptionsWithObserveResponse, + CURRENT_BASE_HREF, + HTTP_JSON_OPTIONS +} from "../../../lib/utils/utils"; /** * Define service methods for handling the repository related things. @@ -86,7 +90,7 @@ export class RepositoryDefaultService extends RepositoryService { if (repositoryName && repositoryName.trim() !== '') { queryParams = queryParams.set('q', repositoryName); } - let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; + let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories'; return this.http.get>(url, buildHttpRequestOptionsWithObserveResponse(queryParams)) .pipe(map(response => { let result: Repository = { @@ -123,7 +127,7 @@ export class RepositoryDefaultService extends RepositoryService { queryParams = new RequestQueryParams(); } - let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; + let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories'; let url = `${baseUrl}/${repositoryName}`; return this.http.put(url, { 'description': description }, HTTP_JSON_OPTIONS) .pipe(map(response => response) @@ -134,7 +138,7 @@ export class RepositoryDefaultService extends RepositoryService { if (!repositoryName) { return observableThrowError('Bad argument'); } - let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; + let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories'; url = `${url}/${repositoryName}`; return this.http.delete(url, HTTP_JSON_OPTIONS) diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.spec.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.spec.ts index ab09e0e00..370f1a7a5 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.spec.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.spec.ts @@ -11,7 +11,7 @@ import { ScanningResultService, VulnerabilitySummary } from "../../../../lib/services"; -import { VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; import { SharedModule } from "../../../../lib/utils/shared/shared.module"; import { ErrorHandler } from "../../../../lib/utils/error-handler"; import { ChannelService } from "../../../../lib/services/channel.service"; @@ -22,7 +22,7 @@ describe('ResultBarChartComponent (inline template)', () => { let fixture: ComponentFixture; let serviceConfig: IServiceConfig; let testConfig: IServiceConfig = { - vulnerabilityScanningBaseEndpoint: "/api/vulnerability/testing" + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing" }; let mockData: VulnerabilitySummary = { scan_status: VULNERABILITY_SCAN_STATUS.SUCCESS, @@ -75,7 +75,7 @@ describe('ResultBarChartComponent (inline template)', () => { it('should be created', () => { expect(component).toBeTruthy(); expect(serviceConfig).toBeTruthy(); - expect(serviceConfig.vulnerabilityScanningBaseEndpoint).toEqual("/api/vulnerability/testing"); + expect(serviceConfig.vulnerabilityScanningBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/vulnerability/testing"); }); it('should show "not scanned" if status is STOPPED', () => { diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts index ea8d38431..bae24bbbd 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts @@ -11,7 +11,12 @@ import { ScannerVo, ScanningResultService, VulnerabilitySummary } from "../../.. import { ArtifactDefaultService } from "../artifact/artifact.service"; import { ErrorHandler } from "../../../../lib/utils/error-handler"; import { ChannelService } from "../../../../lib/services/channel.service"; -import { clone, DEFAULT_SUPPORTED_MIME_TYPE, VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; +import { + clone, + CURRENT_BASE_HREF, + DEFAULT_SUPPORTED_MIME_TYPE, + VULNERABILITY_SCAN_STATUS +} from "../../../../lib/utils/utils"; import { Artifact } from "../artifact/artifact"; @@ -200,7 +205,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { }, duration); } viewLog(): string { - return `/api/v2.0/projects/${this.projectName}/repositories/${this.repoName} + return `${ CURRENT_BASE_HREF }/projects/${this.projectName}/repositories/${this.repoName} /artifacts/${this.artifactId}/scan/${this.summary.report_id}/log`; } } diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.spec.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.spec.ts index 9a5a6a3c9..096f9e67b 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.spec.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.spec.ts @@ -13,7 +13,7 @@ import { SharedModule } from "../../../../lib/utils/shared/shared.module"; import { FilterComponent } from "../../../../lib/components/filter/filter.component"; import { ChannelService } from "../../../../lib/services/channel.service"; import { ErrorHandler } from "../../../../lib/utils/error-handler"; -import { DEFAULT_SUPPORTED_MIME_TYPE, VULNERABILITY_SEVERITY } from "../../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, DEFAULT_SUPPORTED_MIME_TYPE, VULNERABILITY_SEVERITY } from "../../../../lib/utils/utils"; describe('ResultGridComponent (inline template)', () => { let component: ResultGridComponent; let fixture: ComponentFixture; @@ -23,7 +23,7 @@ describe('ResultGridComponent (inline template)', () => { let spy: jasmine.Spy; let mockHasScanImagePermission: boolean = true; let testConfig: IServiceConfig = { - vulnerabilityScanningBaseEndpoint: "/api/vulnerability/testing" + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing" }; beforeEach(async(() => { @@ -90,7 +90,7 @@ describe('ResultGridComponent (inline template)', () => { it('should inject the SERVICE_CONFIG', () => { expect(serviceConfig).toBeTruthy(); - expect(serviceConfig.vulnerabilityScanningBaseEndpoint).toEqual("/api/vulnerability/testing"); + expect(serviceConfig.vulnerabilityScanningBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/vulnerability/testing"); }); it('should inject and call the ScanningResultService', () => { diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-tip.component.spec.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-tip.component.spec.ts index 51bb20a65..c1104e618 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-tip.component.spec.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-tip.component.spec.ts @@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ResultTipComponent } from './result-tip.component'; import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config"; import { UserPermissionDefaultService, UserPermissionService, VulnerabilitySummary } from "../../../../lib/services"; -import { VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; import { SharedModule } from "../../../../lib/utils/shared/shared.module"; @@ -10,7 +10,7 @@ describe('ResultTipComponent (inline template)', () => { let component: ResultTipComponent; let fixture: ComponentFixture; let testConfig: IServiceConfig = { - vulnerabilityScanningBaseEndpoint: "/api/vulnerability/testing" + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing" }; let mockData: VulnerabilitySummary = { scan_status: VULNERABILITY_SCAN_STATUS.SUCCESS, diff --git a/src/portal/src/app/project/robot-account/robot.api.repository.ts b/src/portal/src/app/project/robot-account/robot.api.repository.ts index 091d2b765..8058396f8 100644 --- a/src/portal/src/app/project/robot-account/robot.api.repository.ts +++ b/src/portal/src/app/project/robot-account/robot.api.repository.ts @@ -3,6 +3,7 @@ import { HttpClient } from "@angular/common/http"; import { throwError as observableThrowError, Observable, pipe } from "rxjs"; import { catchError, map } from "rxjs/operators"; import { Robot } from './robot'; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; @Injectable() export class RobotApiRepository { @@ -10,33 +11,33 @@ export class RobotApiRepository { public postRobot(projectId, param): Observable { return this.http - .post(`/api/projects/${projectId}/robots`, param) + .post(`${ CURRENT_BASE_HREF }/projects/${projectId}/robots`, param) .pipe(catchError(error => observableThrowError(error))); } public deleteRobot(projectId, id): Observable { return this.http - .delete(`/api/projects/${projectId}/robots/${id}`) + .delete(`${ CURRENT_BASE_HREF }/projects/${projectId}/robots/${id}`) .pipe(catchError(error => observableThrowError(error))); } public listRobot(projectId): Observable { return this.http - .get(`/api/projects/${projectId}/robots`) + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/robots`) .pipe(map(response => response as Robot[])) .pipe(catchError(error => observableThrowError(error))); } public getRobot(projectId, id): Observable { return this.http - .get(`/api/projects/${projectId}/robots/${id}`) + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/robots/${id}`) .pipe(map(response => response as Robot[])) .pipe(catchError(error => observableThrowError(error))); } public toggleDisabledAccount(projectId, id, data): Observable { return this.http - .put(`/api/projects/${projectId}/robots/${id}`, data) + .put(`${ CURRENT_BASE_HREF }/projects/${projectId}/robots/${id}`, data) .pipe(catchError(error => observableThrowError(error))); } } diff --git a/src/portal/src/app/project/tag-feature-integration/immutable-tag/immutable-tag.service.ts b/src/portal/src/app/project/tag-feature-integration/immutable-tag/immutable-tag.service.ts index f3e10e764..ce02b245b 100644 --- a/src/portal/src/app/project/tag-feature-integration/immutable-tag/immutable-tag.service.ts +++ b/src/portal/src/app/project/tag-feature-integration/immutable-tag/immutable-tag.service.ts @@ -4,7 +4,7 @@ import { ImmutableRetentionRule, RuleMetadate } from "../tag-retention/retention import { Observable, throwError as observableThrowError } from "rxjs"; import { map, catchError } from "rxjs/operators"; import { Project } from "../../project"; -import { HTTP_JSON_OPTIONS } from "../../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_JSON_OPTIONS } from "../../../../lib/utils/utils"; @Injectable() @@ -33,34 +33,34 @@ export class ImmutableTagService { } getRetentionMetadata(): Observable { - return this.http.get(`/api/retentions/metadatas`) + return this.http.get(`${ CURRENT_BASE_HREF }/retentions/metadatas`) .pipe(map(response => response as RuleMetadate)) .pipe(catchError(error => observableThrowError(error))); } getRules(projectId): Observable { - return this.http.get(`/api/projects/${projectId}/immutabletagrules`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}/immutabletagrules`) .pipe(map(response => response as ImmutableRetentionRule[])) .pipe(catchError(error => observableThrowError(error))); } createRule(projectId: number, retention: ImmutableRetentionRule) { - return this.http.post(`/api/projects/${projectId}/immutabletagrules`, retention) + return this.http.post(`${ CURRENT_BASE_HREF }/projects/${projectId}/immutabletagrules`, retention) .pipe(catchError(error => observableThrowError(error))); } updateRule(projectId, immutabletagrule: ImmutableRetentionRule) { - return this.http.put(`/api/projects/${projectId}/immutabletagrules/${immutabletagrule.id}`, immutabletagrule) + return this.http.put(`${ CURRENT_BASE_HREF }/projects/${projectId}/immutabletagrules/${immutabletagrule.id}`, immutabletagrule) .pipe(catchError(error => observableThrowError(error))); } deleteRule(projectId, ruleId) { - return this.http.delete(`/api/projects/${projectId}/immutabletagrules/${ruleId}`, HTTP_JSON_OPTIONS) + return this.http.delete(`${ CURRENT_BASE_HREF }/projects/${projectId}/immutabletagrules/${ruleId}`, HTTP_JSON_OPTIONS) .pipe(catchError(error => observableThrowError(error))); } getProjectInfo(projectId) { - return this.http.get(`/api/projects/${projectId}`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}`) .pipe(map(response => response as Project)) .pipe(catchError(error => observableThrowError(error))); } diff --git a/src/portal/src/app/project/tag-feature-integration/tag-retention/tag-retention.service.ts b/src/portal/src/app/project/tag-feature-integration/tag-retention/tag-retention.service.ts index 71ba707da..162c43bcd 100644 --- a/src/portal/src/app/project/tag-feature-integration/tag-retention/tag-retention.service.ts +++ b/src/portal/src/app/project/tag-feature-integration/tag-retention/tag-retention.service.ts @@ -17,7 +17,7 @@ import { Retention, RuleMetadate } from "./retention"; import { Observable, throwError as observableThrowError } from "rxjs"; import { map, catchError } from "rxjs/operators"; import { Project } from "../../project"; -import { buildHttpRequestOptionsWithObserveResponse } from "../../../../lib/utils/utils"; +import { buildHttpRequestOptionsWithObserveResponse, CURRENT_BASE_HREF } from "../../../../lib/utils/utils"; @Injectable() export class TagRetentionService { @@ -65,45 +65,45 @@ export class TagRetentionService { } getRetentionMetadata(): Observable { - return this.http.get(`/api/retentions/metadatas`) + return this.http.get(`${ CURRENT_BASE_HREF }/retentions/metadatas`) .pipe(map(response => response as RuleMetadate)) .pipe(catchError(error => observableThrowError(error))); } getRetention(retentionId): Observable { - return this.http.get(`/api/retentions/${retentionId}`) + return this.http.get(`${ CURRENT_BASE_HREF }/retentions/${retentionId}`) .pipe(map(response => response as Retention)) .pipe(catchError(error => observableThrowError(error))); } createRetention(retention: Retention) { - return this.http.post(`/api/retentions`, retention) + return this.http.post(`${ CURRENT_BASE_HREF }/retentions`, retention) .pipe(catchError(error => observableThrowError(error))); } updateRetention(retentionId, retention: Retention) { - return this.http.put(`/api/retentions/${retentionId}`, retention) + return this.http.put(`${ CURRENT_BASE_HREF }/retentions/${retentionId}`, retention) .pipe(catchError(error => observableThrowError(error))); } getProjectInfo(projectId) { - return this.http.get(`/api/projects/${projectId}`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}`) .pipe(map(response => response as Project)) .pipe(catchError(error => observableThrowError(error))); } runNowTrigger(retentionId) { - return this.http.post(`/api/retentions/${retentionId}/executions`, {dry_run: false}) + return this.http.post(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions`, {dry_run: false}) .pipe(catchError(error => observableThrowError(error))); } whatIfRunTrigger(retentionId) { - return this.http.post(`/api/retentions/${retentionId}/executions`, {dry_run: true}) + return this.http.post(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions`, {dry_run: true}) .pipe(catchError(error => observableThrowError(error))); } AbortRun(retentionId, executionId) { - return this.http.patch(`/api/retentions/${retentionId}/executions/${executionId}`, {action: 'stop'}) + return this.http.patch(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions/${executionId}`, {action: 'stop'}) .pipe(catchError(error => observableThrowError(error))); } @@ -113,7 +113,8 @@ export class TagRetentionService { params = params.set('page', page + '').set('page_size', pageSize + ''); } return this.http - .get>>(`/api/retentions/${retentionId}/executions`, buildHttpRequestOptionsWithObserveResponse(params)) + .get>>(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions`, + buildHttpRequestOptionsWithObserveResponse(params)) .pipe(catchError(error => observableThrowError(error)), ); } @@ -122,12 +123,12 @@ export class TagRetentionService { if (page && pageSize) { params = params.set('page', page + '').set('page_size', pageSize + ''); } - return this.http.get>>(`/api/retentions/${retentionId}/executions/${executionId}/tasks`, + return this.http.get>>(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions/${executionId}/tasks`, buildHttpRequestOptionsWithObserveResponse(params)) .pipe(catchError(error => observableThrowError(error))); } seeLog(retentionId, executionId, taskId) { - window.open(`api/retentions/${retentionId}/executions/${executionId}/tasks/${taskId}`, '_blank'); + window.open(`${ CURRENT_BASE_HREF }/retentions/${retentionId}/executions/${executionId}/tasks/${taskId}`, '_blank'); } } diff --git a/src/portal/src/app/project/webhook/webhook.service.ts b/src/portal/src/app/project/webhook/webhook.service.ts index 490942f25..e7f7a99ee 100644 --- a/src/portal/src/app/project/webhook/webhook.service.ts +++ b/src/portal/src/app/project/webhook/webhook.service.ts @@ -16,6 +16,7 @@ import { map, catchError } from "rxjs/operators"; import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { Webhook, LastTrigger } from "./webhook"; +import { CURRENT_BASE_HREF } from "../../../lib/utils/utils"; @Injectable() export class WebhookService { @@ -23,34 +24,34 @@ export class WebhookService { public listWebhook(projectId: number): Observable { return this.http - .get(`/api/projects/${projectId}/webhook/policies`) + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/webhook/policies`) .pipe(map(response => response as Webhook[])) .pipe(catchError(error => observableThrowError(error))); } public listLastTrigger(projectId: number): Observable { return this.http - .get(`/api/projects/${projectId}/webhook/lasttrigger`) + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/webhook/lasttrigger`) .pipe(map(response => response as LastTrigger[])) .pipe(catchError(error => observableThrowError(error))); } public editWebhook(projectId: number, policyId: number, data: any): Observable { return this.http - .put(`/api/projects/${projectId}/webhook/policies/${policyId}`, data) + .put(`${ CURRENT_BASE_HREF }/projects/${projectId}/webhook/policies/${policyId}`, data) .pipe(catchError(error => observableThrowError(error))); } public createWebhook(projectId: number, data: any): Observable { return this.http - .post(`/api/projects/${projectId}/webhook/policies`, data) + .post(`${ CURRENT_BASE_HREF }/projects/${projectId}/webhook/policies`, data) .pipe(catchError(error => observableThrowError(error))); } public testEndpoint(projectId: number, param): Observable { return this.http - .post(`/api/projects/${projectId}/webhook/policies/test`, param) + .post(`${ CURRENT_BASE_HREF }/projects/${projectId}/webhook/policies/test`, param) .pipe(catchError(error => observableThrowError(error))); } } diff --git a/src/portal/src/app/shared/session.service.ts b/src/portal/src/app/shared/session.service.ts index a6206c9b9..2762f093e 100644 --- a/src/portal/src/app/shared/session.service.ts +++ b/src/portal/src/app/shared/session.service.ts @@ -20,16 +20,22 @@ import { Member } from '../project/member/member'; import { SignInCredential } from './sign-in-credential'; import { enLang } from './shared.const'; import { SessionViewmodelFactory } from './session.viewmodel.factory'; -import { HTTP_FORM_OPTIONS, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS, clone } from "../../lib/utils/utils"; +import { + HTTP_FORM_OPTIONS, + HTTP_GET_OPTIONS, + HTTP_JSON_OPTIONS, + clone, + CURRENT_BASE_HREF +} from "../../lib/utils/utils"; import { FlushAll } from "../../lib/utils/cache-util"; const signInUrl = '/c/login'; -const currentUserEndpoint = "/api/users/current"; +const currentUserEndpoint = CURRENT_BASE_HREF + "/users/current"; const signOffEndpoint = "/c/log_out"; -const accountEndpoint = "/api/users/:id"; +const accountEndpoint = CURRENT_BASE_HREF + "/users/:id"; const langEndpoint = "/language"; const userExistsEndpoint = "/c/userExists"; -const renameAdminEndpoint = '/api/internal/renameadmin'; +const renameAdminEndpoint = CURRENT_BASE_HREF + '/internal/renameadmin'; const langMap = { "zh": "zh-CN", "en": "en-US" diff --git a/src/portal/src/app/shared/shared.module.ts b/src/portal/src/app/shared/shared.module.ts index aa125960f..65eb9ddda 100644 --- a/src/portal/src/app/shared/shared.module.ts +++ b/src/portal/src/app/shared/shared.module.ts @@ -46,6 +46,7 @@ import { ListChartVersionRoComponent } from "./list-chart-version-ro/list-chart- import { IServiceConfig, SERVICE_CONFIG } from "../../lib/entities/service.config"; import { ErrorHandler } from "../../lib/utils/error-handler"; import { HarborLibraryModule } from "../../lib/harbor-library.module"; +import { CURRENT_BASE_HREF } from "../../lib/utils/utils"; const uiLibConfig: IServiceConfig = { enablei18Support: true, @@ -53,24 +54,24 @@ const uiLibConfig: IServiceConfig = { langMessageLoader: "http", langMessagePathForHttpLoader: "i18n/lang/", langMessageFileSuffixForHttpLoader: "-lang.json", - systemInfoEndpoint: "/api/systeminfo", - repositoryBaseEndpoint: "/api/repositories", - logBaseEndpoint: "/api/logs", - targetBaseEndpoint: "/api/registries", - replicationBaseEndpoint: "/api/replication", - replicationRuleEndpoint: "/api/replication/policies", - vulnerabilityScanningBaseEndpoint: "/api/repositories", - projectPolicyEndpoint: "/api/projects/configs", - projectBaseEndpoint: "/api/projects", + systemInfoEndpoint: CURRENT_BASE_HREF + "/systeminfo", + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories", + logBaseEndpoint: CURRENT_BASE_HREF + "/logs", + targetBaseEndpoint: CURRENT_BASE_HREF + "/registries", + replicationBaseEndpoint: CURRENT_BASE_HREF + "/replication", + replicationRuleEndpoint: CURRENT_BASE_HREF + "/replication/policies", + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/repositories", + projectPolicyEndpoint: CURRENT_BASE_HREF + "/projects/configs", + projectBaseEndpoint: CURRENT_BASE_HREF + "/projects", localI18nMessageVariableMap: {}, - configurationEndpoint: "/api/configurations", - scanJobEndpoint: "/api/jobs/scan", - labelEndpoint: "/api/labels", - helmChartEndpoint: "/api/chartrepo", + configurationEndpoint: CURRENT_BASE_HREF + "/configurations", + scanJobEndpoint: CURRENT_BASE_HREF + "/jobs/scan", + labelEndpoint: CURRENT_BASE_HREF + "/labels", + helmChartEndpoint: CURRENT_BASE_HREF + "/chartrepo", downloadChartEndpoint: "/chartrepo", - gcEndpoint: "/api/system/gc", - ScanAllEndpoint: "/api/system/scanAll", - quotaUrl: "/api/quotas" + gcEndpoint: CURRENT_BASE_HREF + "/system/gc", + ScanAllEndpoint: CURRENT_BASE_HREF + "/system/scanAll", + quotaUrl: CURRENT_BASE_HREF + "/quotas" }; @NgModule({ diff --git a/src/portal/src/app/shared/statictics/statistics.service.ts b/src/portal/src/app/shared/statictics/statistics.service.ts index acb0b8461..3557e1969 100644 --- a/src/portal/src/app/shared/statictics/statistics.service.ts +++ b/src/portal/src/app/shared/statictics/statistics.service.ts @@ -17,11 +17,11 @@ import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { Statistics } from './statistics'; import { Volumes } from './volumes'; -import { HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; -const statisticsEndpoint = "/api/statistics"; -const volumesEndpoint = "/api/systeminfo/volumes"; +const statisticsEndpoint = CURRENT_BASE_HREF + "/statistics"; +const volumesEndpoint = CURRENT_BASE_HREF + "/systeminfo/volumes"; /** * Declare service to handle the top repositories * diff --git a/src/portal/src/app/sign-in/top-repo/top-repository.service.ts b/src/portal/src/app/sign-in/top-repo/top-repository.service.ts index d907a86d3..ce7870f33 100644 --- a/src/portal/src/app/sign-in/top-repo/top-repository.service.ts +++ b/src/portal/src/app/sign-in/top-repo/top-repository.service.ts @@ -16,9 +16,9 @@ import { HttpClient } from '@angular/common/http'; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { Repository } from "../../../lib/services"; -import { HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS } from "../../../lib/utils/utils"; -export const topRepoEndpoint = "/api/repositories/top"; +export const topRepoEndpoint = CURRENT_BASE_HREF + "/repositories/top"; /** * Declare service to handle the top repositories * diff --git a/src/portal/src/app/user/user.service.ts b/src/portal/src/app/user/user.service.ts index 9722fee7e..59a9b7f8a 100644 --- a/src/portal/src/app/user/user.service.ts +++ b/src/portal/src/app/user/user.service.ts @@ -17,12 +17,17 @@ import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { User, LDAPUser } from './user'; import LDAPUsertoUser from './user'; -import { buildHttpRequestOptionsWithObserveResponse, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils"; +import { + buildHttpRequestOptionsWithObserveResponse, + CURRENT_BASE_HREF, + HTTP_GET_OPTIONS, + HTTP_JSON_OPTIONS +} from "../../lib/utils/utils"; -const userMgmtEndpoint = '/api/users'; -const userListSearch = '/api/users/search?'; -const ldapUserEndpoint = '/api/ldap/users'; +const userMgmtEndpoint = CURRENT_BASE_HREF + '/users'; +const userListSearch = CURRENT_BASE_HREF + '/users/search?'; +const ldapUserEndpoint = CURRENT_BASE_HREF + '/ldap/users'; /** * Define related methods to handle account and session corresponding things diff --git a/src/portal/src/lib/components/config/gc/gc.component.spec.ts b/src/portal/src/lib/components/config/gc/gc.component.spec.ts index 8a925308a..da440eeab 100644 --- a/src/portal/src/lib/components/config/gc/gc.component.spec.ts +++ b/src/portal/src/lib/components/config/gc/gc.component.spec.ts @@ -10,13 +10,14 @@ import { CronScheduleComponent } from '../../cron-schedule/cron-schedule.compone import { CronTooltipComponent } from "../../cron-schedule/cron-tooltip/cron-tooltip.component"; import { of } from 'rxjs'; import { GcJobData } from './gcLog'; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; describe('GcComponent', () => { let component: GcComponent; let fixture: ComponentFixture; let gcRepoService: GcRepoService; let config: IServiceConfig = { - systemInfoEndpoint: "/api/system/gc" + systemInfoEndpoint: CURRENT_BASE_HREF + "/system/gc" }; let mockSchedule = []; let mockJobs: GcJobData[] = [ diff --git a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts index 2cfb9c0b4..9c7098fbb 100644 --- a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts +++ b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts @@ -4,12 +4,13 @@ import { SERVICE_CONFIG, IServiceConfig } from '../../../../entities/service.con import { EditQuotaQuotaInterface } from '../../../../services'; import { HarborLibraryModule } from '../../../../harbor-library.module'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { CURRENT_BASE_HREF } from "../../../../utils/utils"; describe('EditProjectQuotasComponent', () => { let component: EditProjectQuotasComponent; let fixture: ComponentFixture; let config: IServiceConfig = { - quotaUrl: "/api/quotas/testing" + quotaUrl: CURRENT_BASE_HREF + "/quotas/testing" }; const mockedEditQuota: EditQuotaQuotaInterface = { editQuota: "Edit Default Project Quotas", diff --git a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts index 51a3e2665..ad8526e21 100644 --- a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts +++ b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts @@ -12,6 +12,7 @@ import { delay } from 'rxjs/operators'; import {APP_BASE_HREF} from '@angular/common'; import { HarborLibraryModule } from '../../../harbor-library.module'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; describe('ProjectQuotasComponent', () => { let spy: jasmine.Spy; let spyUpdate: jasmine.Spy; @@ -22,7 +23,7 @@ describe('ProjectQuotasComponent', () => { let fixture: ComponentFixture; let config: IServiceConfig = { - quotaUrl: "/api/quotas/testing" + quotaUrl: CURRENT_BASE_HREF + "/quotas/testing" }; let mockQuotaList: Quota[] = [{ id: 1111, diff --git a/src/portal/src/lib/components/config/registry-config.component.spec.ts b/src/portal/src/lib/components/config/registry-config.component.spec.ts index c6afa327e..488be554a 100644 --- a/src/portal/src/lib/components/config/registry-config.component.spec.ts +++ b/src/portal/src/lib/components/config/registry-config.component.spec.ts @@ -23,6 +23,7 @@ import { } from '../../services'; import { Configuration } from './config'; import { of } from 'rxjs'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('RegistryConfigComponent (inline template)', () => { @@ -41,7 +42,7 @@ describe('RegistryConfigComponent (inline template)', () => { } }; let config: IServiceConfig = { - configurationEndpoint: '/api/configurations/testing' + configurationEndpoint: CURRENT_BASE_HREF + '/configurations/testing' }; let mockSystemInfo: SystemInfo = { "with_notary": true, diff --git a/src/portal/src/lib/components/config/replication/replication-config.component.spec.ts b/src/portal/src/lib/components/config/replication/replication-config.component.spec.ts index 01dff3f73..8b7d1792c 100644 --- a/src/portal/src/lib/components/config/replication/replication-config.component.spec.ts +++ b/src/portal/src/lib/components/config/replication/replication-config.component.spec.ts @@ -3,11 +3,12 @@ import { ReplicationConfigComponent } from "./replication-config.component"; import { HarborLibraryModule } from "../../../harbor-library.module"; import { IServiceConfig, SERVICE_CONFIG } from "../../../entities/service.config"; import { Configuration } from "../config"; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; describe('ReplicationConfigComponent', () => { let component: ReplicationConfigComponent; let fixture: ComponentFixture; const config: IServiceConfig = { - baseEndpoint: "/api/testing" + baseEndpoint: CURRENT_BASE_HREF + "/testing" }; beforeEach(() => { TestBed.configureTestingModule({ diff --git a/src/portal/src/lib/components/config/system/system-settings.component.spec.ts b/src/portal/src/lib/components/config/system/system-settings.component.spec.ts index 35f413be1..21452ffd9 100644 --- a/src/portal/src/lib/components/config/system/system-settings.component.spec.ts +++ b/src/portal/src/lib/components/config/system/system-settings.component.spec.ts @@ -7,11 +7,12 @@ import { ErrorHandler } from "../../../utils/error-handler"; import { of } from "rxjs"; import { StringValueItem } from "../config"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; describe('SystemSettingsComponent', () => { let component: SystemSettingsComponent; let fixture: ComponentFixture; const config: IServiceConfig = { - baseEndpoint: "/api/testing" + baseEndpoint: CURRENT_BASE_HREF + "/testing" }; const mockedWhitelist = { id: 1, diff --git a/src/portal/src/lib/components/config/vulnerability/scanAll.service.ts b/src/portal/src/lib/components/config/vulnerability/scanAll.service.ts index ea6216726..1946f66bd 100644 --- a/src/portal/src/lib/components/config/vulnerability/scanAll.service.ts +++ b/src/portal/src/lib/components/config/vulnerability/scanAll.service.ts @@ -5,6 +5,7 @@ import { ErrorHandler } from '../../../utils/error-handler'; import {HttpClient} from "@angular/common/http"; import {ScanningMetrics} from "../config"; import {catchError, map} from "rxjs/operators"; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; @Injectable() @@ -51,21 +52,21 @@ export class ScanAllRepoService { return this.scanApiRepository.putSchedule(param); } getScheduleMetrics(): Observable { - return this.http.get('/api/scans/schedule/metrics') + return this.http.get(CURRENT_BASE_HREF + '/scans/schedule/metrics') .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response as ScanningMetrics)); } getManualMetrics(): Observable { - return this.http.get('/api/scans/all/metrics') + return this.http.get(CURRENT_BASE_HREF + '/scans/all/metrics') .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response as ScanningMetrics)); } getScanners(): Observable { - return this.http.get('/api/scanners') + return this.http.get(CURRENT_BASE_HREF + '/scanners') .pipe(catchError(error => observableThrowError(error))); } getScannerMetadata(uid: string): Observable { - return this.http.get(`/api/scanners/${uid}/metadata`) + return this.http.get(`${ CURRENT_BASE_HREF }/scanners/${uid}/metadata`) .pipe(catchError(error => observableThrowError(error))); } } diff --git a/src/portal/src/lib/components/config/vulnerability/vulnerability-config.component.spec.ts b/src/portal/src/lib/components/config/vulnerability/vulnerability-config.component.spec.ts index e89ba6c19..4cf3c0543 100644 --- a/src/portal/src/lib/components/config/vulnerability/vulnerability-config.component.spec.ts +++ b/src/portal/src/lib/components/config/vulnerability/vulnerability-config.component.spec.ts @@ -7,11 +7,12 @@ import { IServiceConfig, SERVICE_CONFIG } from "../../../entities/service.config import { ScanningMetrics } from "../config"; import { SharedModule } from "../../../utils/shared/shared.module"; import { ErrorHandler } from "../../../utils/error-handler"; +import { CURRENT_BASE_HREF } from "../../../utils/utils"; let component: VulnerabilityConfigComponent; let fixture: ComponentFixture; let config: IServiceConfig = { - configurationEndpoint: '/api/configurations/testing' + configurationEndpoint: CURRENT_BASE_HREF + '/configurations/testing' }; let mockedSchedule = {"schedule": null}; let mockedScheduledMetrics: ScanningMetrics = { diff --git a/src/portal/src/lib/components/confirmation-dialog/confirmation-dialog.component.spec.ts b/src/portal/src/lib/components/confirmation-dialog/confirmation-dialog.component.spec.ts index cb248288c..f482f8497 100644 --- a/src/portal/src/lib/components/confirmation-dialog/confirmation-dialog.component.spec.ts +++ b/src/portal/src/lib/components/confirmation-dialog/confirmation-dialog.component.spec.ts @@ -6,6 +6,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ConfirmationTargets } from '../../entities/shared.const'; import { ConfirmationMessage } from './confirmation-message'; import { BatchInfo } from './confirmation-batch-message'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('ConfirmationDialogComponent', () => { @@ -13,7 +14,7 @@ describe('ConfirmationDialogComponent', () => { let comp: ConfirmationDialogComponent; let fixture: ComponentFixture; let config: IServiceConfig = { - configurationEndpoint: '/api/configurations/testing' + configurationEndpoint: CURRENT_BASE_HREF + '/configurations/testing' }; const deletionMessage: ConfirmationMessage = new ConfirmationMessage( "MEMBER.DELETION_TITLE", diff --git a/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.spec.ts b/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.spec.ts index 38db639e5..3b98639cd 100644 --- a/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.spec.ts +++ b/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.spec.ts @@ -21,6 +21,7 @@ import { IServiceConfig, SERVICE_CONFIG } from "../../entities/service.config"; import { of } from "rxjs"; import { HttpClient } from "@angular/common/http"; import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe("CreateEditEndpointComponent (inline template)", () => { let mockData: Endpoint = { @@ -254,7 +255,7 @@ describe("CreateEditEndpointComponent (inline template)", () => { let fixture: ComponentFixture; let config: IServiceConfig = { - systemInfoEndpoint: "/api/endpoints/testing" + systemInfoEndpoint: CURRENT_BASE_HREF + "/endpoints/testing" }; let endpointService: EndpointService; @@ -326,6 +327,6 @@ describe("CreateEditEndpointComponent (inline template)", () => { it("should endpoint be initialized", () => { fixture.detectChanges(); - expect(config.systemInfoEndpoint).toEqual("/api/endpoints/testing"); + expect(config.systemInfoEndpoint).toEqual(CURRENT_BASE_HREF + "/endpoints/testing"); }); }); diff --git a/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.ts b/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.ts index 80829b72d..eca31ae70 100644 --- a/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.ts +++ b/src/portal/src/lib/components/create-edit-endpoint/create-edit-endpoint.component.ts @@ -29,13 +29,13 @@ import { EndpointService } from "../../services/endpoint.service"; import { ErrorHandler } from "../../utils/error-handler"; import { InlineAlertComponent } from "../inline-alert/inline-alert.component"; import { Endpoint, PingEndpoint } from "../../services/interface"; -import { clone, compareValue, isEmptyObject } from "../../utils/utils"; +import { clone, compareValue, CURRENT_BASE_HREF, isEmptyObject } from "../../utils/utils"; import { HttpClient } from "@angular/common/http"; import { catchError } from "rxjs/operators"; const FAKE_PASSWORD = "rjGcfuRu"; const FAKE_JSON_KEY = "No Change"; -const METADATA_URL = "/api/replication/adapterinfos"; +const METADATA_URL = CURRENT_BASE_HREF + "/replication/adapterinfos"; @Component({ selector: "hbr-create-edit-endpoint", templateUrl: "./create-edit-endpoint.component.html", diff --git a/src/portal/src/lib/components/create-edit-label/create-edit-label.component.spec.ts b/src/portal/src/lib/components/create-edit-label/create-edit-label.component.spec.ts index 4840e9439..e84c4c588 100644 --- a/src/portal/src/lib/components/create-edit-label/create-edit-label.component.spec.ts +++ b/src/portal/src/lib/components/create-edit-label/create-edit-label.component.spec.ts @@ -10,6 +10,7 @@ import { IServiceConfig, SERVICE_CONFIG } from "../../entities/service.config"; import { CreateEditLabelComponent } from "./create-edit-label.component"; import { LabelDefaultService, LabelService } from "../../services/label.service"; import { of } from "rxjs"; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe("CreateEditLabelComponent (inline template)", () => { let mockOneData: Label = { @@ -27,7 +28,7 @@ describe("CreateEditLabelComponent (inline template)", () => { let fixture: ComponentFixture; let config: IServiceConfig = { - systemInfoEndpoint: "/api/label/testing" + systemInfoEndpoint: CURRENT_BASE_HREF + "/label/testing" }; let labelService: LabelService; diff --git a/src/portal/src/lib/components/create-edit-rule/create-edit-rule.component.spec.ts b/src/portal/src/lib/components/create-edit-rule/create-edit-rule.component.spec.ts index 8219a61ca..17886588a 100644 --- a/src/portal/src/lib/components/create-edit-rule/create-edit-rule.component.spec.ts +++ b/src/portal/src/lib/components/create-edit-rule/create-edit-rule.component.spec.ts @@ -39,6 +39,7 @@ import {LabelService} from "../../services/label.service"; import {LabelPieceComponent} from "../label-piece/label-piece.component"; import { RouterTestingModule } from '@angular/router/testing'; import { of } from "rxjs"; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe("CreateEditRuleComponent (inline template)", () => { let mockRules: ReplicationRule[] = [ @@ -221,8 +222,8 @@ describe("CreateEditRuleComponent (inline template)", () => { let config: IServiceConfig = { - replicationBaseEndpoint: "/api/replication/testing", - targetBaseEndpoint: "/api/registries/testing" + replicationBaseEndpoint: CURRENT_BASE_HREF + "/replication/testing", + targetBaseEndpoint: CURRENT_BASE_HREF + "/registries/testing" }; beforeEach(async(() => { diff --git a/src/portal/src/lib/components/endpoint/endpoint.component.spec.ts b/src/portal/src/lib/components/endpoint/endpoint.component.spec.ts index 9de37dfc3..111cd99da 100644 --- a/src/portal/src/lib/components/endpoint/endpoint.component.spec.ts +++ b/src/portal/src/lib/components/endpoint/endpoint.component.spec.ts @@ -18,7 +18,7 @@ import { import { IServiceConfig, SERVICE_CONFIG } from "../../entities/service.config"; import { OperationService } from "../operation/operation.service"; -import { click } from "../../utils/utils"; +import { click, CURRENT_BASE_HREF } from "../../utils/utils"; import { of } from "rxjs"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { HttpClient } from "@angular/common/http"; @@ -311,7 +311,7 @@ describe("EndpointComponent (inline template)", () => { let comp: EndpointComponent; let fixture: ComponentFixture; let config: IServiceConfig = { - systemInfoEndpoint: "/api/endpoints/testing" + systemInfoEndpoint: CURRENT_BASE_HREF + "/endpoints/testing" }; let endpointService: EndpointService; @@ -368,7 +368,7 @@ describe("EndpointComponent (inline template)", () => { it("should endpoint be initialized", () => { fixture.detectChanges(); - expect(config.systemInfoEndpoint).toEqual("/api/endpoints/testing"); + expect(config.systemInfoEndpoint).toEqual(CURRENT_BASE_HREF + "/endpoints/testing"); }); it("should open create endpoint modal", async(() => { diff --git a/src/portal/src/lib/components/image-name-input/image-name-input.component.spec.ts b/src/portal/src/lib/components/image-name-input/image-name-input.component.spec.ts index 63d488fc6..b0f252788 100644 --- a/src/portal/src/lib/components/image-name-input/image-name-input.component.spec.ts +++ b/src/portal/src/lib/components/image-name-input/image-name-input.component.spec.ts @@ -8,6 +8,7 @@ import { IServiceConfig, SERVICE_CONFIG } from "../../entities/service.config"; import { of } from "rxjs"; import { HttpResponse } from "@angular/common/http"; import { ChannelService } from "../../services/channel.service"; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe("ImageNameInputComponent (inline template)", () => { let comp: ImageNameInputComponent; @@ -28,7 +29,7 @@ describe("ImageNameInputComponent (inline template)", () => { ]; let config: IServiceConfig = { - projectBaseEndpoint: "/api/projects/testing" + projectBaseEndpoint: CURRENT_BASE_HREF + "/projects/testing" }; beforeEach(async(() => { diff --git a/src/portal/src/lib/components/label/label.component.spec.ts b/src/portal/src/lib/components/label/label.component.spec.ts index 1b9152c58..b5b83c77f 100644 --- a/src/portal/src/lib/components/label/label.component.spec.ts +++ b/src/portal/src/lib/components/label/label.component.spec.ts @@ -14,6 +14,7 @@ import {ErrorHandler} from "../../utils/error-handler/error-handler"; import {IServiceConfig, SERVICE_CONFIG} from "../../entities/service.config"; import { OperationService } from "../operation/operation.service"; import { of } from "rxjs"; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('LabelComponent (inline template)', () => { @@ -60,7 +61,7 @@ describe('LabelComponent (inline template)', () => { let spyOneLabel: jasmine.Spy; let config: IServiceConfig = { - systemInfoEndpoint: '/api/label/testing' + systemInfoEndpoint: CURRENT_BASE_HREF + '/label/testing' }; beforeEach(async(() => { diff --git a/src/portal/src/lib/components/list-replication-rule/list-replication-rule.component.spec.ts b/src/portal/src/lib/components/list-replication-rule/list-replication-rule.component.spec.ts index de1972b94..668faec7d 100644 --- a/src/portal/src/lib/components/list-replication-rule/list-replication-rule.component.spec.ts +++ b/src/portal/src/lib/components/list-replication-rule/list-replication-rule.component.spec.ts @@ -15,6 +15,7 @@ import { SERVICE_CONFIG, IServiceConfig } from '../../entities/service.config'; import { ReplicationService, ReplicationDefaultService } from '../../services/replication.service'; import { OperationService } from "../operation/operation.service"; import { of } from 'rxjs'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('ListReplicationRuleComponent (inline template)', () => { @@ -56,7 +57,7 @@ describe('ListReplicationRuleComponent (inline template)', () => { let spyRules: jasmine.Spy; let config: IServiceConfig = { - replicationRuleEndpoint: '/api/policies/replication/testing' + replicationRuleEndpoint: CURRENT_BASE_HREF + '/policies/replication/testing' }; beforeEach(async(() => { diff --git a/src/portal/src/lib/components/log/recent-log.component.spec.ts b/src/portal/src/lib/components/log/recent-log.component.spec.ts index ed350d48d..d1f58797c 100644 --- a/src/portal/src/lib/components/log/recent-log.component.spec.ts +++ b/src/portal/src/lib/components/log/recent-log.component.spec.ts @@ -9,7 +9,7 @@ import { ErrorHandler } from '../../utils/error-handler'; import { SharedModule } from '../../utils/shared/shared.module'; import { FilterComponent } from '../filter/filter.component'; -import { click } from '../../utils/utils'; +import { click, CURRENT_BASE_HREF } from '../../utils/utils'; import { of } from 'rxjs'; import { delay } from 'rxjs/operators'; @@ -33,7 +33,7 @@ describe('RecentLogComponent (inline template)', () => { data: [] }; let testConfig: IServiceConfig = { - logBaseEndpoint: "/api/logs/testing" + logBaseEndpoint: CURRENT_BASE_HREF + "/logs/testing" }; beforeEach(async(() => { @@ -96,7 +96,7 @@ describe('RecentLogComponent (inline template)', () => { it('should inject the SERVICE_CONFIG', () => { expect(serviceConfig).toBeTruthy(); - expect(serviceConfig.logBaseEndpoint).toEqual("/api/logs/testing"); + expect(serviceConfig.logBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/logs/testing"); }); it('should get data from AccessLogService', async(() => { diff --git a/src/portal/src/lib/components/operation/operation.component.spec.ts b/src/portal/src/lib/components/operation/operation.component.spec.ts index 98419e10b..1618a681b 100644 --- a/src/portal/src/lib/components/operation/operation.component.spec.ts +++ b/src/portal/src/lib/components/operation/operation.component.spec.ts @@ -6,13 +6,14 @@ import { OperationService } from './operation.service'; import { HarborLibraryModule } from '../../harbor-library.module'; import { IServiceConfig, SERVICE_CONFIG } from '../../entities/service.config'; import { OperateInfo } from './operate'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('OperationComponent', () => { let component: OperationComponent; let fixture: ComponentFixture; let config: IServiceConfig = { - configurationEndpoint: '/api/configurations/testing' + configurationEndpoint: CURRENT_BASE_HREF + '/configurations/testing' }; beforeEach(() => { diff --git a/src/portal/src/lib/components/project-policy-config/project-policy-config.component.spec.ts b/src/portal/src/lib/components/project-policy-config/project-policy-config.component.spec.ts index c8898e158..252cb8542 100644 --- a/src/portal/src/lib/components/project-policy-config/project-policy-config.component.spec.ts +++ b/src/portal/src/lib/components/project-policy-config/project-policy-config.component.spec.ts @@ -10,6 +10,7 @@ import {SystemCVEWhitelist, SystemInfo} from '../../services/interface'; import { Project } from './project'; import { UserPermissionService } from '../../services/permission.service'; import { of } from 'rxjs'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; const mockSystemInfo: SystemInfo[] = [ { @@ -80,8 +81,8 @@ const mockSystemWhitelist: SystemCVEWhitelist = { "project_id": 0 }; const config: IServiceConfig = { - projectPolicyEndpoint: '/api/projects/testing', - systemInfoEndpoint: '/api/systeminfo/testing', + projectPolicyEndpoint: CURRENT_BASE_HREF + '/projects/testing', + systemInfoEndpoint: CURRENT_BASE_HREF + '/systeminfo/testing', }; const projectService = { getProject() { diff --git a/src/portal/src/lib/components/replication/replication.component.spec.ts b/src/portal/src/lib/components/replication/replication.component.spec.ts index bf3934587..48f3b44a3 100644 --- a/src/portal/src/lib/components/replication/replication.component.spec.ts +++ b/src/portal/src/lib/components/replication/replication.component.spec.ts @@ -26,6 +26,7 @@ import {FilterLabelComponent} from "../create-edit-rule/filter-label.component"; import {LabelPieceComponent} from "../label-piece/label-piece.component"; import { RouterTestingModule } from '@angular/router/testing'; import { of } from 'rxjs'; +import { CURRENT_BASE_HREF } from "../../utils/utils"; describe('Replication Component (inline template)', () => { @@ -149,7 +150,7 @@ describe('Replication Component (inline template)', () => { let elJob: HTMLElement; let config: IServiceConfig = { - replicationRuleEndpoint: '/api/policies/replication/testing' + replicationRuleEndpoint: CURRENT_BASE_HREF + '/policies/replication/testing' }; beforeEach(async(() => { diff --git a/src/portal/src/lib/entities/service.config.ts b/src/portal/src/lib/entities/service.config.ts index 545e60e0a..7a1a35591 100644 --- a/src/portal/src/lib/entities/service.config.ts +++ b/src/portal/src/lib/entities/service.config.ts @@ -19,9 +19,9 @@ export interface IServiceConfig { * The base endpoint of the service used to handle the repositories of registry and/or tags of repository. * The endpoints of repository or tag(s) will be built based on this endpoint. * E.g: - * If the base endpoint is '/api/repositories', - * the repository endpoint will be '/api/repositories/:repo_id', - * the tag(s) endpoint will be '/api/repositories/:repo_id/tags[/:tag_id]'. + * If the base endpoint is CURRENT_BASE_HREF + '/repositories', + * the repository endpoint will be CURRENT_BASE_HREF + '/repositories/:repo_id', + * the tag(s) endpoint will be CURRENT_BASE_HREF + '/repositories/:repo_id/tags[/:tag_id]'. * * * * {string} @@ -41,9 +41,9 @@ export interface IServiceConfig { * The base endpoint of the service used to handle the registry targets. * Registry target related endpoints will be built based on this endpoint. * E.g: - * If the base endpoint is '/api/endpoints', - * the endpoint for registry target will be '/api/endpoints/:endpoint_id', - * the endpoint for pinging registry target will be '/api/endpoints/:endpoint_id/ping'. + * If the base endpoint is CURRENT_BASE_HREF + '/endpoints', + * the endpoint for registry target will be CURRENT_BASE_HREF + '/endpoints/:endpoint_id', + * the endpoint for pinging registry target will be CURRENT_BASE_HREF + '/endpoints/:endpoint_id/ping'. * * * {string} * @memberOf IServiceConfig @@ -59,8 +59,8 @@ export interface IServiceConfig { * The base endpoint of the service used to handle the replication rules. * Replication rule related endpoints will be built based on this endpoint. * E.g: - * If the base endpoint is '/api/replication/rules', - * the endpoint for rule will be '/api/replication/rules/:rule_id'. + * If the base endpoint is CURRENT_BASE_HREF + '/replication/rules', + * the endpoint for rule will be CURRENT_BASE_HREF + '/replication/rules/:rule_id'. * * * {string} * @memberOf IServiceConfig @@ -203,8 +203,8 @@ export interface IServiceConfig { * The base endpoint of the service used to handle the labels. * labels related endpoints will be built based on this endpoint. * E.g: - * If the base endpoint is '/api/labels', - * the label endpoint will be '/api/labels/:id'. + * If the base endpoint is CURRENT_BASE_HREF + '/labels', + * the label endpoint will be CURRENT_BASE_HREF + '/labels/:id'. * * * {string} * @memberOf IServiceConfig @@ -215,8 +215,8 @@ export interface IServiceConfig { * The base endpoint of the service used to handle the helm chart. * helm charts related endpoints will be built based on this endpoint. * E.g: - * If the base endpoint is '/api/helmcharts', - * the helm chart endpoint will be '/api/helmcharts/:id'. + * If the base endpoint is CURRENT_BASE_HREF + '/helmcharts', + * the helm chart endpoint will be CURRENT_BASE_HREF + '/helmcharts/:id'. * * * {string} * @memberOf IServiceConfig diff --git a/src/portal/src/lib/harbor-library.module.ts b/src/portal/src/lib/harbor-library.module.ts index 1050ee1fa..de9f12e1f 100644 --- a/src/portal/src/lib/harbor-library.module.ts +++ b/src/portal/src/lib/harbor-library.module.ts @@ -38,7 +38,7 @@ import { ErrorHandler, DefaultErrorHandler } from './utils/error-handler'; -import { DEFAULT_LANG_COOKIE_KEY, DEFAULT_SUPPORTING_LANGS, DEFAULT_LANG } from './utils/utils'; +import { DEFAULT_LANG_COOKIE_KEY, DEFAULT_SUPPORTING_LANGS, DEFAULT_LANG, CURRENT_BASE_HREF } from './utils/utils'; import { OperationService } from './components/operation/operation.service'; import { GcHistoryComponent } from "./components/config/gc/gc-history/gc-history.component"; import { GcComponent } from "./components/config/gc/gc.component"; @@ -80,16 +80,16 @@ import { TranslateServiceInitializer } from "./i18n"; * this default configuration. */ export const DefaultServiceConfig: IServiceConfig = { - baseEndpoint: "/api", - systemInfoEndpoint: "/api/systeminfo", - repositoryBaseEndpoint: "/api/repositories", - logBaseEndpoint: "/api/logs", - targetBaseEndpoint: "/api/registries", - replicationBaseEndpoint: "/api/replication", - replicationRuleEndpoint: "/api/replication/policies", - vulnerabilityScanningBaseEndpoint: "/api/repositories", - projectPolicyEndpoint: "/api/projects/configs", - projectBaseEndpoint: "/api/projects", + baseEndpoint: CURRENT_BASE_HREF, + systemInfoEndpoint: CURRENT_BASE_HREF + "/systeminfo", + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories", + logBaseEndpoint: CURRENT_BASE_HREF + "/logs", + targetBaseEndpoint: CURRENT_BASE_HREF + "/registries", + replicationBaseEndpoint: CURRENT_BASE_HREF + "/replication", + replicationRuleEndpoint: CURRENT_BASE_HREF + "/replication/policies", + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/repositories", + projectPolicyEndpoint: CURRENT_BASE_HREF + "/projects/configs", + projectBaseEndpoint: CURRENT_BASE_HREF + "/projects", enablei18Support: false, langCookieKey: DEFAULT_LANG_COOKIE_KEY, supportedLangs: DEFAULT_SUPPORTING_LANGS, @@ -98,13 +98,13 @@ export const DefaultServiceConfig: IServiceConfig = { langMessagePathForHttpLoader: "i18n/langs/", langMessageFileSuffixForHttpLoader: "-lang.json", localI18nMessageVariableMap: {}, - configurationEndpoint: "/api/configurations", - scanJobEndpoint: "/api/jobs/scan", - labelEndpoint: "/api/labels", - helmChartEndpoint: "/api/chartrepo", + configurationEndpoint: CURRENT_BASE_HREF + "/configurations", + scanJobEndpoint: CURRENT_BASE_HREF + "/jobs/scan", + labelEndpoint: CURRENT_BASE_HREF + "/labels", + helmChartEndpoint: CURRENT_BASE_HREF + "/chartrepo", downloadChartEndpoint: "/chartrepo", - gcEndpoint: "/api/system/gc", - ScanAllEndpoint: "/api/system/scanAll" + gcEndpoint: CURRENT_BASE_HREF + "/system/gc", + ScanAllEndpoint: CURRENT_BASE_HREF + "/system/scanAll" }; /** diff --git a/src/portal/src/lib/services/access-log.service.spec.ts b/src/portal/src/lib/services/access-log.service.spec.ts index 889c0de7f..d575528f0 100644 --- a/src/portal/src/lib/services/access-log.service.spec.ts +++ b/src/portal/src/lib/services/access-log.service.spec.ts @@ -3,10 +3,11 @@ import { TestBed, inject } from '@angular/core/testing'; import { AccessLogService, AccessLogDefaultService } from './access-log.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('AccessLogService', () => { const mockConfig: IServiceConfig = { - logBaseEndpoint: "/api/logs/testing" + logBaseEndpoint: CURRENT_BASE_HREF + "/logs/testing" }; let config: IServiceConfig; @@ -36,7 +37,7 @@ describe('AccessLogService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.logBaseEndpoint).toEqual("/api/logs/testing"); + expect(config.logBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/logs/testing"); }); }); diff --git a/src/portal/src/lib/services/access-log.service.ts b/src/portal/src/lib/services/access-log.service.ts index 46cbbb4ef..960252970 100644 --- a/src/portal/src/lib/services/access-log.service.ts +++ b/src/portal/src/lib/services/access-log.service.ts @@ -4,7 +4,11 @@ import { AccessLog, AccessLogItem } from "./interface"; import { Injectable, Inject } from "@angular/core"; import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config"; import { HttpClient, HttpResponse } from "@angular/common/http"; -import { buildHttpRequestOptionsWithObserveResponse, HTTP_GET_OPTIONS_OBSERVE_RESPONSE } from "../utils/utils"; +import { + buildHttpRequestOptionsWithObserveResponse, + CURRENT_BASE_HREF, + HTTP_GET_OPTIONS_OBSERVE_RESPONSE +} from "../utils/utils"; import { map, catchError } from "rxjs/operators"; /** @@ -77,7 +81,7 @@ export class AccessLogDefaultService extends AccessLogService { ? this.config.logBaseEndpoint : ""; if (url === "") { - url = "/api/logs"; + url = CURRENT_BASE_HREF + "/logs"; } return this.http diff --git a/src/portal/src/lib/services/configuration.service.spec.ts b/src/portal/src/lib/services/configuration.service.spec.ts index 44d571b70..0a2aae54f 100644 --- a/src/portal/src/lib/services/configuration.service.spec.ts +++ b/src/portal/src/lib/services/configuration.service.spec.ts @@ -3,10 +3,11 @@ import { TestBed, inject } from '@angular/core/testing'; import { ConfigurationService, ConfigurationDefaultService } from './configuration.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('ConfigurationService', () => { const mockConfig: IServiceConfig = { - configurationEndpoint: "/api/configurations/testing" + configurationEndpoint: CURRENT_BASE_HREF + "/configurations/testing" }; let config: IServiceConfig; @@ -36,7 +37,7 @@ describe('ConfigurationService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.configurationEndpoint).toEqual("/api/configurations/testing"); + expect(config.configurationEndpoint).toEqual(CURRENT_BASE_HREF + "/configurations/testing"); }); }); diff --git a/src/portal/src/lib/services/configuration.service.ts b/src/portal/src/lib/services/configuration.service.ts index 457f65995..194e9a4a4 100644 --- a/src/portal/src/lib/services/configuration.service.ts +++ b/src/portal/src/lib/services/configuration.service.ts @@ -4,7 +4,7 @@ import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config"; -import { HTTP_JSON_OPTIONS, HTTP_GET_OPTIONS } from "../utils/utils"; +import { HTTP_JSON_OPTIONS, HTTP_GET_OPTIONS, CURRENT_BASE_HREF } from "../utils/utils"; import { Configuration } from "../components/config/config"; /** @@ -52,7 +52,7 @@ export class ConfigurationDefaultService extends ConfigurationService { this._baseUrl = this.config && this.config.configurationEndpoint ? this.config.configurationEndpoint - : "/api/configurations"; + : CURRENT_BASE_HREF + "/configurations"; } getConfigurations(): diff --git a/src/portal/src/lib/services/endpoint.service.spec.ts b/src/portal/src/lib/services/endpoint.service.spec.ts index 653415d41..f06c4ef3a 100644 --- a/src/portal/src/lib/services/endpoint.service.spec.ts +++ b/src/portal/src/lib/services/endpoint.service.spec.ts @@ -2,13 +2,14 @@ import { TestBed, inject } from '@angular/core/testing'; import { SharedModule } from '../utils/shared/shared.module'; import { IServiceConfig, SERVICE_CONFIG } from '../entities/service.config'; import { EndpointService, EndpointDefaultService } from './endpoint.service'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('EndpointService', () => { let mockEndpoint: IServiceConfig = { - targetBaseEndpoint: '/api/endpoint/testing' + targetBaseEndpoint: CURRENT_BASE_HREF + '/endpoint/testing' }; beforeEach(() => { diff --git a/src/portal/src/lib/services/endpoint.service.ts b/src/portal/src/lib/services/endpoint.service.ts index e2e1a080b..a03b24636 100644 --- a/src/portal/src/lib/services/endpoint.service.ts +++ b/src/portal/src/lib/services/endpoint.service.ts @@ -6,7 +6,7 @@ import { IServiceConfig, SERVICE_CONFIG } from "../entities/service.config"; import { buildHttpRequestOptions, HTTP_JSON_OPTIONS, - HTTP_GET_OPTIONS + HTTP_GET_OPTIONS, CURRENT_BASE_HREF } from "../utils/utils"; import { RequestQueryParams } from "./RequestQueryParams"; import { Endpoint, ReplicationRule, PingEndpoint } from "./interface"; @@ -145,7 +145,7 @@ export class EndpointDefaultService extends EndpointService { super(); this._endpointUrl = config.targetBaseEndpoint ? config.targetBaseEndpoint - : "/api/registries"; + : CURRENT_BASE_HREF + "/registries"; } public getEndpoints( @@ -180,7 +180,7 @@ export class EndpointDefaultService extends EndpointService { public getAdapters(): Observable { return this.http - .get(`/api/replication/adapters`) + .get(`${ CURRENT_BASE_HREF }/replication/adapters`) .pipe(catchError(error => observableThrowError(error))); } diff --git a/src/portal/src/lib/services/job-log.service.spec.ts b/src/portal/src/lib/services/job-log.service.spec.ts index 310ff2139..bd5da77b6 100644 --- a/src/portal/src/lib/services/job-log.service.spec.ts +++ b/src/portal/src/lib/services/job-log.service.spec.ts @@ -3,11 +3,12 @@ import { TestBed, inject } from '@angular/core/testing'; import { JobLogService, JobLogDefaultService } from './job-log.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('JobLogService', () => { const mockConfig: IServiceConfig = { - replicationBaseEndpoint: "/api/replication/testing", - scanJobEndpoint: "/api/jobs/scan/testing" + replicationBaseEndpoint: CURRENT_BASE_HREF + "/replication/testing", + scanJobEndpoint: CURRENT_BASE_HREF + "/jobs/scan/testing" }; let config: IServiceConfig; @@ -33,7 +34,7 @@ describe('JobLogService', () => { it('should be initialized', inject([JobLogDefaultService], (service: JobLogService) => { expect(service).toBeTruthy(); - expect(config.replicationBaseEndpoint).toEqual("/api/replication/testing"); - expect(config.scanJobEndpoint).toEqual("/api/jobs/scan/testing"); + expect(config.replicationBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/replication/testing"); + expect(config.scanJobEndpoint).toEqual(CURRENT_BASE_HREF + "/jobs/scan/testing"); })); }); diff --git a/src/portal/src/lib/services/job-log.service.ts b/src/portal/src/lib/services/job-log.service.ts index 3696232b3..aa372e0a5 100644 --- a/src/portal/src/lib/services/job-log.service.ts +++ b/src/portal/src/lib/services/job-log.service.ts @@ -1,7 +1,7 @@ import { Injectable, Inject } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config"; -import { HTTP_GET_OPTIONS, HTTP_GET_OPTIONS_TEXT } from "../utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_GET_OPTIONS_TEXT } from "../utils/utils"; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; /** @@ -49,10 +49,10 @@ export class JobLogDefaultService extends JobLogService { super(); this._replicationJobBaseUrl = config.replicationBaseEndpoint ? config.replicationBaseEndpoint - : "/api/replication"; + : CURRENT_BASE_HREF + "/replication"; this._scanningJobBaseUrl = config.scanJobEndpoint ? config.scanJobEndpoint - : "/api/jobs/scan"; + : CURRENT_BASE_HREF + "/jobs/scan"; this._supportedJobTypes = ["replication", "scan"]; } diff --git a/src/portal/src/lib/services/label.service.ts b/src/portal/src/lib/services/label.service.ts index e52352244..4e0a8a114 100644 --- a/src/portal/src/lib/services/label.service.ts +++ b/src/portal/src/lib/services/label.service.ts @@ -6,7 +6,7 @@ import { RequestQueryParams } from "./RequestQueryParams"; import { Label } from "./interface"; import { IServiceConfig, SERVICE_CONFIG } from "../entities/service.config"; -import { buildHttpRequestOptions, HTTP_JSON_OPTIONS } from "../utils/utils"; +import { buildHttpRequestOptions, CURRENT_BASE_HREF, HTTP_JSON_OPTIONS } from "../utils/utils"; import { Observable, throwError as observableThrowError } from "rxjs"; export abstract class LabelService { @@ -78,8 +78,8 @@ export class LabelDefaultService extends LabelService { private http: HttpClient ) { super(); - this.labelUrl = config.labelEndpoint ? config.labelEndpoint : "/api/labels"; - this.chartUrl = config.helmChartEndpoint ? config.helmChartEndpoint : "/api/chartrepo"; + this.labelUrl = config.labelEndpoint ? config.labelEndpoint : CURRENT_BASE_HREF + "/labels"; + this.chartUrl = config.helmChartEndpoint ? config.helmChartEndpoint : CURRENT_BASE_HREF + "/chartrepo"; } diff --git a/src/portal/src/lib/services/permission.service.ts b/src/portal/src/lib/services/permission.service.ts index 740904ad3..3f1f1e832 100644 --- a/src/portal/src/lib/services/permission.service.ts +++ b/src/portal/src/lib/services/permission.service.ts @@ -17,6 +17,7 @@ import { Observable, forkJoin, of, throwError as observableThrowError } from "rx import { map, tap, publishReplay, refCount } from "rxjs/operators"; import { HttpClient } from '@angular/common/http'; import { CacheObservable } from "../utils/cache-util"; +import { CURRENT_BASE_HREF } from "../utils/utils"; interface Permission { @@ -53,7 +54,7 @@ export class UserPermissionDefaultService extends UserPermissionService { @CacheObservable({ maxAge: 1000 * 60 }) private getPermissions(scope: string, relative?: boolean): Observable> { - const url = `/api/users/current/permissions?scope=${scope}&relative=${relative ? 'true' : 'false'}`; + const url = `${ CURRENT_BASE_HREF }/users/current/permissions?scope=${scope}&relative=${relative ? 'true' : 'false'}`; return this.http.get>(url); } diff --git a/src/portal/src/lib/services/project.service.ts b/src/portal/src/lib/services/project.service.ts index 0636ed5b5..505b4b1d1 100644 --- a/src/portal/src/lib/services/project.service.ts +++ b/src/portal/src/lib/services/project.service.ts @@ -10,7 +10,7 @@ import { ProjectPolicy } from "../components/project-policy-config/project-polic import { HTTP_JSON_OPTIONS, HTTP_GET_OPTIONS, - buildHttpRequestOptionsWithObserveResponse + buildHttpRequestOptionsWithObserveResponse, CURRENT_BASE_HREF } from "../utils/utils"; /** @@ -100,7 +100,7 @@ export class ProjectDefaultService extends ProjectService { } let baseUrl: string = this.config.projectBaseEndpoint ? this.config.projectBaseEndpoint - : "/api/projects"; + : CURRENT_BASE_HREF + "/projects"; return this.http .get(`${baseUrl}/${projectId}`, HTTP_GET_OPTIONS) .pipe(catchError(error => observableThrowError(error))); @@ -114,7 +114,7 @@ export class ProjectDefaultService extends ProjectService { ): any { let baseUrl: string = this.config.projectBaseEndpoint ? this.config.projectBaseEndpoint - : "/api/projects"; + : CURRENT_BASE_HREF + "/projects"; return this.http .put( `${baseUrl}/${projectId}`, @@ -145,13 +145,13 @@ export class ProjectDefaultService extends ProjectService { params = params.set('public', '' + isPublic); } return this.http - .get>(`/api/projects`, buildHttpRequestOptionsWithObserveResponse(params)).pipe( + .get>(`${ CURRENT_BASE_HREF }/projects`, buildHttpRequestOptionsWithObserveResponse(params)).pipe( catchError(error => observableThrowError(error)), ); } public createProject(name: string, metadata: any, countLimit: number, storageLimit: number): Observable { return this.http - .post(`/api/projects`, + .post(`${ CURRENT_BASE_HREF }/projects`, JSON.stringify({'project_name': name, 'metadata': { public: metadata.public ? 'true' : 'false', }, @@ -163,13 +163,13 @@ export class ProjectDefaultService extends ProjectService { public deleteProject(projectId: number): Observable { return this.http - .delete(`/api/projects/${projectId}`) + .delete(`${ CURRENT_BASE_HREF }/projects/${projectId}`) .pipe(catchError(error => observableThrowError(error))); } public checkProjectExists(projectName: string): Observable { return this.http - .head(`/api/projects/?project_name=${projectName}`).pipe( + .head(`${ CURRENT_BASE_HREF }/projects/?project_name=${projectName}`).pipe( catchError(error => { if (error && error.status === 404) { return of(error); @@ -180,12 +180,12 @@ export class ProjectDefaultService extends ProjectService { public checkProjectMember(projectId: number): Observable { return this.http - .get(`/api/projects/${projectId}/members`, HTTP_GET_OPTIONS).pipe( + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/members`, HTTP_GET_OPTIONS).pipe( catchError(error => observableThrowError(error)), ); } public getProjectSummary(projectId: number): Observable { return this.http - .get(`/api/projects/${projectId}/summary`, HTTP_GET_OPTIONS).pipe( + .get(`${ CURRENT_BASE_HREF }/projects/${projectId}/summary`, HTTP_GET_OPTIONS).pipe( catchError(error => observableThrowError(error)), ); } } diff --git a/src/portal/src/lib/services/replication.service.spec.ts b/src/portal/src/lib/services/replication.service.spec.ts index 9acc42066..d36273a13 100644 --- a/src/portal/src/lib/services/replication.service.spec.ts +++ b/src/portal/src/lib/services/replication.service.spec.ts @@ -3,11 +3,12 @@ import { TestBed, inject } from '@angular/core/testing'; import { ReplicationService, ReplicationDefaultService } from './replication.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('ReplicationService', () => { const mockConfig: IServiceConfig = { - replicationRuleEndpoint: "/api/policies/replication/testing", - replicationBaseEndpoint: "/api/replication/testing" + replicationRuleEndpoint: CURRENT_BASE_HREF + "/policies/replication/testing", + replicationBaseEndpoint: CURRENT_BASE_HREF + "/replication/testing" }; let config: IServiceConfig; @@ -37,7 +38,7 @@ describe('ReplicationService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.replicationRuleEndpoint).toEqual("/api/policies/replication/testing"); - expect(config.replicationBaseEndpoint).toEqual("/api/replication/testing"); + expect(config.replicationRuleEndpoint).toEqual(CURRENT_BASE_HREF + "/policies/replication/testing"); + expect(config.replicationBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/replication/testing"); }); }); diff --git a/src/portal/src/lib/services/replication.service.ts b/src/portal/src/lib/services/replication.service.ts index a5296e81b..a7528bd7a 100644 --- a/src/portal/src/lib/services/replication.service.ts +++ b/src/portal/src/lib/services/replication.service.ts @@ -6,7 +6,7 @@ import { HTTP_JSON_OPTIONS, HTTP_GET_OPTIONS, buildHttpRequestOptionsWithObserveResponse, - HTTP_GET_OPTIONS_OBSERVE_RESPONSE + HTTP_GET_OPTIONS_OBSERVE_RESPONSE, CURRENT_BASE_HREF } from "../utils/utils"; import { ReplicationJob, @@ -219,11 +219,11 @@ export class ReplicationDefaultService extends ReplicationService { super(); this._ruleBaseUrl = config.replicationRuleEndpoint ? config.replicationRuleEndpoint - : "/api/replication/policies"; + : CURRENT_BASE_HREF + "/replication/policies"; this._replicateUrl = config.replicationBaseEndpoint ? config.replicationBaseEndpoint - : "/api/replication"; - this._baseUrl = config.baseEndpoint ? config.baseEndpoint : "/api"; + : CURRENT_BASE_HREF + "/replication"; + this._baseUrl = config.baseEndpoint ? config.baseEndpoint : CURRENT_BASE_HREF + ""; } // Private methods diff --git a/src/portal/src/lib/services/resource-label.service.ts b/src/portal/src/lib/services/resource-label.service.ts index 5e999a39f..da4962bb2 100644 --- a/src/portal/src/lib/services/resource-label.service.ts +++ b/src/portal/src/lib/services/resource-label.service.ts @@ -2,7 +2,7 @@ import { Label } from "./interface"; import { Inject, Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { IServiceConfig, SERVICE_CONFIG } from "../entities/service.config"; -import { buildHttpRequestOptions, HTTP_JSON_OPTIONS } from "../utils/utils"; +import { buildHttpRequestOptions, CURRENT_BASE_HREF, HTTP_JSON_OPTIONS } from "../utils/utils"; import { RequestQueryParams } from "./RequestQueryParams"; import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; @@ -40,7 +40,7 @@ export class LabelDefaultService extends LabelService { super(); this._labelUrl = config.labelEndpoint ? config.labelEndpoint - : "/api/labels"; + : CURRENT_BASE_HREF + "/labels"; } getLabels( diff --git a/src/portal/src/lib/services/retag.service.ts b/src/portal/src/lib/services/retag.service.ts index 11ca3eb74..12923b62d 100644 --- a/src/portal/src/lib/services/retag.service.ts +++ b/src/portal/src/lib/services/retag.service.ts @@ -2,7 +2,7 @@ import { Observable } from "rxjs"; import { HttpClient } from "@angular/common/http"; import { Injectable, Inject } from "@angular/core"; import { RetagRequest } from "./interface"; -import { HTTP_JSON_OPTIONS } from "../utils/utils"; +import { CURRENT_BASE_HREF, HTTP_JSON_OPTIONS } from "../utils/utils"; import { catchError } from "rxjs/operators"; import { throwError as observableThrowError } from "rxjs/index"; import { IServiceConfig, SERVICE_CONFIG } from "../entities/service.config"; @@ -44,7 +44,7 @@ export class RetagDefaultService extends RetagService { } retag(request: RetagRequest): Observable { - let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; + let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories'; return this.http .post(`${baseUrl}/${request.targetProject}/${request.targetRepo}/tags`, { diff --git a/src/portal/src/lib/services/scanning.service.spec.ts b/src/portal/src/lib/services/scanning.service.spec.ts index 4778a66dd..6587e4721 100644 --- a/src/portal/src/lib/services/scanning.service.spec.ts +++ b/src/portal/src/lib/services/scanning.service.spec.ts @@ -3,10 +3,11 @@ import { TestBed, inject } from '@angular/core/testing'; import { ScanningResultService, ScanningResultDefaultService } from './scanning.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('ScanningResultService', () => { const mockConfig: IServiceConfig = { - vulnerabilityScanningBaseEndpoint: "/api/vulnerability/testing" + vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing" }; let config: IServiceConfig; @@ -36,6 +37,6 @@ describe('ScanningResultService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.vulnerabilityScanningBaseEndpoint).toEqual("/api/vulnerability/testing"); + expect(config.vulnerabilityScanningBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/vulnerability/testing"); }); }); diff --git a/src/portal/src/lib/services/scanning.service.ts b/src/portal/src/lib/services/scanning.service.ts index 3f50a0254..c3a5a80e9 100644 --- a/src/portal/src/lib/services/scanning.service.ts +++ b/src/portal/src/lib/services/scanning.service.ts @@ -2,7 +2,12 @@ import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Injectable, Inject } from "@angular/core"; import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config"; -import { buildHttpRequestOptions, DEFAULT_SUPPORTED_MIME_TYPE, HTTP_JSON_OPTIONS } from "../utils/utils"; +import { + buildHttpRequestOptions, + CURRENT_BASE_HREF, + DEFAULT_SUPPORTED_MIME_TYPE, + HTTP_JSON_OPTIONS +} from "../utils/utils"; import { RequestQueryParams } from "./RequestQueryParams"; import { VulnerabilityDetail, VulnerabilitySummary } from "./interface"; import { map, catchError } from "rxjs/operators"; @@ -91,7 +96,7 @@ export abstract class ScanningResultService { @Injectable() export class ScanningResultDefaultService extends ScanningResultService { - _baseUrl: string = "/api/v2.0/projects"; + _baseUrl: string = CURRENT_BASE_HREF + "/projects"; constructor( private http: HttpClient, @@ -151,7 +156,7 @@ export class ScanningResultDefaultService extends ScanningResultService { return this.http .post( - `/api/v2.0/projects//${projectName}/repositories/${repoName}/artifacts/${artifactId}/scan`, + `${ CURRENT_BASE_HREF }/projects//${projectName}/repositories/${repoName}/artifacts/${artifactId}/scan`, HTTP_JSON_OPTIONS ) .pipe(map(() => { @@ -169,12 +174,12 @@ export class ScanningResultDefaultService extends ScanningResultService { , catchError(error => observableThrowError(error))); } getScannerMetadata(uuid: string): Observable { - return this.http.get(`/api/scanners/${uuid}/metadata`) + return this.http.get(`${ CURRENT_BASE_HREF }/scanners/${uuid}/metadata`) .pipe(map(response => response as any)) .pipe(catchError(error => observableThrowError(error))); } getProjectScanner(projectId: number): Observable { - return this.http.get(`/api/projects/${projectId}/scanner`) + return this.http.get(`${ CURRENT_BASE_HREF }/projects/${projectId}/scanner`) .pipe(map(response => response as any)) .pipe(catchError(error => observableThrowError(error))); } diff --git a/src/portal/src/lib/services/system-info.service.spec.ts b/src/portal/src/lib/services/system-info.service.spec.ts index 4b1e6b700..4aa0189c0 100644 --- a/src/portal/src/lib/services/system-info.service.spec.ts +++ b/src/portal/src/lib/services/system-info.service.spec.ts @@ -3,10 +3,11 @@ import { TestBed, inject } from '@angular/core/testing'; import { SystemInfoService, SystemInfoDefaultService } from './system-info.service'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('SystemInfoService', () => { const mockConfig: IServiceConfig = { - systemInfoEndpoint: "/api/systeminfo/testing" + systemInfoEndpoint: CURRENT_BASE_HREF + "/systeminfo/testing" }; let config: IServiceConfig; @@ -36,6 +37,6 @@ describe('SystemInfoService', () => { it('should inject the right config', () => { expect(config).toBeTruthy(); - expect(config.systemInfoEndpoint).toEqual("/api/systeminfo/testing"); + expect(config.systemInfoEndpoint).toEqual(CURRENT_BASE_HREF + "/systeminfo/testing"); }); }); diff --git a/src/portal/src/lib/services/system-info.service.ts b/src/portal/src/lib/services/system-info.service.ts index 1dedfbc1e..1be47c5bc 100644 --- a/src/portal/src/lib/services/system-info.service.ts +++ b/src/portal/src/lib/services/system-info.service.ts @@ -4,7 +4,7 @@ import { map, catchError } from "rxjs/operators"; import { Observable, throwError as observableThrowError } from "rxjs"; import {SystemCVEWhitelist, SystemInfo} from './interface'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; -import {HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS} from "../utils/utils"; +import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../utils/utils"; /** * Get System information about current backend server. @@ -42,18 +42,18 @@ export class SystemInfoDefaultService extends SystemInfoService { super(); } getSystemInfo(): Observable { - let url = this.config.systemInfoEndpoint ? this.config.systemInfoEndpoint : '/api/systeminfo'; + let url = this.config.systemInfoEndpoint ? this.config.systemInfoEndpoint : CURRENT_BASE_HREF + '/systeminfo'; return this.http.get(url, HTTP_GET_OPTIONS) .pipe(map(systemInfo => systemInfo as SystemInfo) , catchError(error => observableThrowError(error))); } public getSystemWhitelist(): Observable { - return this.http.get("/api/system/CVEWhitelist", HTTP_GET_OPTIONS) + return this.http.get(CURRENT_BASE_HREF + "/system/CVEWhitelist", HTTP_GET_OPTIONS) .pipe(map(systemCVEWhitelist => systemCVEWhitelist as SystemCVEWhitelist) , catchError(error => observableThrowError(error))); } public updateSystemWhitelist(systemCVEWhitelist: SystemCVEWhitelist): Observable { - return this.http.put("/api/system/CVEWhitelist", JSON.stringify(systemCVEWhitelist), HTTP_JSON_OPTIONS) + return this.http.put(CURRENT_BASE_HREF + "/system/CVEWhitelist", JSON.stringify(systemCVEWhitelist), HTTP_JSON_OPTIONS) .pipe(map(response => response) , catchError(error => observableThrowError(error))); } diff --git a/src/portal/src/lib/services/tag.service.spec.ts b/src/portal/src/lib/services/tag.service.spec.ts index 8c2cd25f2..66ec23403 100644 --- a/src/portal/src/lib/services/tag.service.spec.ts +++ b/src/portal/src/lib/services/tag.service.spec.ts @@ -3,6 +3,7 @@ import { TestBed, inject } from '@angular/core/testing'; import { SharedModule } from '../utils/shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config'; import { TagService, TagDefaultService } from './tag.service'; +import { CURRENT_BASE_HREF } from "../utils/utils"; describe('TagService', () => { @@ -22,7 +23,7 @@ describe('TagService', () => { // ]; const mockConfig: IServiceConfig = { - repositoryBaseEndpoint: "/api/repositories/testing" + repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; beforeEach(() => { diff --git a/src/portal/src/lib/services/tag.service.ts b/src/portal/src/lib/services/tag.service.ts index e33539e21..30e4948af 100644 --- a/src/portal/src/lib/services/tag.service.ts +++ b/src/portal/src/lib/services/tag.service.ts @@ -5,7 +5,7 @@ import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config"; import { buildHttpRequestOptions, HTTP_JSON_OPTIONS, - HTTP_GET_OPTIONS + HTTP_GET_OPTIONS, CURRENT_BASE_HREF } from "../utils/utils"; import { RequestQueryParams } from "./RequestQueryParams"; import { Tag, Manifest } from "./interface"; @@ -89,10 +89,10 @@ export class TagDefaultService extends TagService { super(); this._baseUrl = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint - : "/api/repositories"; + : CURRENT_BASE_HREF + "/repositories"; this._labelUrl = this.config.labelEndpoint ? this.config.labelEndpoint - : "/api/labels"; + : CURRENT_BASE_HREF + "/labels"; } public newTag( @@ -104,7 +104,7 @@ export class TagDefaultService extends TagService { if (!projectName || !repositoryName || !digest || !tagName) { return observableThrowError("Bad argument"); } - let url: string = `/api/v2.0/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags`; + let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags`; return this.http .post(url, tagName, HTTP_JSON_OPTIONS) .pipe(map(response => response) @@ -121,7 +121,7 @@ export class TagDefaultService extends TagService { return observableThrowError("Bad argument"); } - let url: string = `/api/v2.0/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags/${tagName}`; + let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags/${tagName}`; return this.http .delete(url, HTTP_JSON_OPTIONS) .pipe(map(response => response) diff --git a/src/portal/src/lib/utils/utils.ts b/src/portal/src/lib/utils/utils.ts index 78caa4d17..a684cbc25 100644 --- a/src/portal/src/lib/utils/utils.ts +++ b/src/portal/src/lib/utils/utils.ts @@ -6,6 +6,17 @@ import { DebugElement } from '@angular/core'; import { Comparator, State, HttpOptionInterface, HttpOptionTextInterface, QuotaUnitInterface } from '../services/interface'; import { QuotaUnits, StorageMultipleConstant, LimitCount } from '../entities/shared.const'; import { AbstractControl } from "@angular/forms"; +/** + * Api levels + */ +enum APILevels { + V1 = '', + V2 = '/v2.0' +} +/** + * Current base href + */ +export const CURRENT_BASE_HREF = '/api' + APILevels.V2; /** * Convert the different async channels to the Promise type.