Commit 41dd5656 authored by AllForNothing's avatar AllForNothing
Browse files

Upgrade api level to v2


Signed-off-by: default avatarAllForNothing <sshijun@vmware.com>
parent 8bc41574
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!');
......
......@@ -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<any> {
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)));
}
}
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);
});
......
......@@ -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";
......
......@@ -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);
......
......@@ -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
*
......
......@@ -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 }
],
......
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();
});
});
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<any>, next: HttpHandler): Observable<any> {
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);
}
}
......@@ -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());
});
......
......@@ -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
*
......
......@@ -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 {
......
......@@ -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<Scanner[]> {
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<Scanner[]> {
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<any> {
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<any> {
return this.http.post('/api/scanners', scanner )
return this.http.post(CURRENT_BASE_HREF + '/scanners', scanner )
.pipe(catchError(error => observableThrowError(error)));
}
getScanners(): Observable<Scanner[]> {
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<any> {
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<any> {
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<any> {
......@@ -54,25 +55,25 @@ export class ConfigScannerService {
}
}
getProjectScanner(projectId: number): Observable<Scanner> {
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<any> {
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<ScannerMetadata> {
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<any> {
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)));
}
......
......@@ -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 {
......
......@@ -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', <string>queryParam.page_size);
}
return this.http
.get<HttpResponse<AuditLog[]>>(`/api/projects/${queryParam.project_id}/logs`
.get<HttpResponse<AuditLog[]>>(`${ CURRENT_BASE_HREF }/projects/${queryParam.project_id}/logs`
, buildHttpRequestOptionsWithObserveResponse(params)).pipe(
catchError(error => observableThrowError(error)), );
}
......
......@@ -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<Member[]> {
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<any> {
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<any> {
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<any> {
return this.http
.delete(`/api/projects/${projectId}/members/${memberId}`)
.delete(`${ CURRENT_BASE_HREF }/projects/${projectId}/members/${memberId}`)
.pipe(catchError(error => observableThrowError(error)));
}
}
......@@ -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({
......
......@@ -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<ArtifactAdditionsComponent>;
......
......@@ -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({
......
......@@ -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({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment