Fix bugs that some place hardcode url addr

In the repositories and projects service some url is hardcoded.
This commit is contained in:
Deng, Qian 2018-04-27 14:08:22 +08:00
parent 18c8686d57
commit 6ba6dcd1d5
7 changed files with 43 additions and 21 deletions

View File

@ -1,6 +1,6 @@
{
"name": "harbor-ui",
"version": "0.7.5",
"version": "0.7.10",
"description": "Harbor shared UI components based on Clarity and Angular4",
"scripts": {
"start": "ng serve --host 0.0.0.0 --port 4500 --proxy-config proxy.config.json",

View File

@ -1,6 +1,6 @@
{
"name": "harbor-ui",
"version": "0.7.5",
"version": "0.7.10",
"description": "Harbor shared UI components based on Clarity and Angular4",
"author": "VMware",
"module": "index.js",

View File

@ -94,7 +94,7 @@ export const DefaultServiceConfig: IServiceConfig = {
/**
* Define the configuration for harbor shareable module
*
*
* @export
* @interface HarborModuleConfig
*/
@ -140,8 +140,6 @@ export interface HarborModuleConfig {
}
/**
*
*
* @export
* @param {AppConfigService} configService
* @returns

View File

@ -88,6 +88,13 @@ export interface IServiceConfig {
*/
projectPolicyEndpoint?: string;
/**
* The base endpoint of service used to handle projects
* @type {string}
* @memberOf IServiceConfig
*/
projectBaseEndpoint?: string;
/**
* To determine whether or not to enable the i18 multiple languages supporting.
*

View File

@ -1,9 +1,9 @@
import { Observable } from 'rxjs/Observable';
import { Injectable, Inject } from '@angular/core';
import 'rxjs/add/observable/of';
import { Http, Headers, RequestOptions } from '@angular/http';
import { SERVICE_CONFIG, IServiceConfig } from '../service.config';
import 'rxjs/add/observable/of';
import { SERVICE_CONFIG, IServiceConfig } from '../service.config';
import { Project } from '../project-policy-config/project';
import { ProjectPolicy } from '../project-policy-config/project-policy-config.component';
import {HTTP_JSON_OPTIONS, HTTP_GET_OPTIONS, buildHttpRequestOptions} from "../utils";
@ -40,6 +40,18 @@ export abstract class ProjectService {
*/
abstract updateProjectPolicy(projectId: number | string, projectPolicy: ProjectPolicy): Observable<any> | Promise<any> | any;
/**
* Get all projects
*
* @abstract
* @param {string} name
* @param {number} isPublic
* @param {number} page
* @param {number} pageSize
* @returns {(Observable<any> | Promise<any> | any)}
*
* @memberOf EndpointService
*/
abstract listProjects(name: string, isPublic: number, page?: number, pageSize?: number): Observable<Project[]> | Promise<Project[]> | Project[];
}
@ -64,14 +76,15 @@ export class ProjectDefaultService extends ProjectService {
if (!projectId) {
return Promise.reject('Bad argument');
}
let baseUrl: string = this.config.projectBaseEndpoint ? this.config.projectBaseEndpoint : '/api/projects';
return this.http
.get(`/api/projects/${projectId}`, HTTP_GET_OPTIONS)
.get(`${baseUrl}/${projectId}`, HTTP_GET_OPTIONS)
.map(response => response.json())
.catch(error => Observable.throw(error));
}
listProjects(name: string, isPublic: number, page?: number, pageSize?: number): Observable<Project[]> | Promise<Project[]> | Project[] {
public listProjects(name: string, isPublic: number, page?: number, pageSize?: number): Observable<Project[]> | Promise<Project[]> | Project[] {
let baseUrl: string = this.config.projectBaseEndpoint ? this.config.projectBaseEndpoint : '/api/projects';
let params = new RequestQueryParams();
if (page && pageSize) {
params.set('page', page + '');
@ -87,20 +100,24 @@ export class ProjectDefaultService extends ProjectService {
// let options = new RequestOptions({ headers: this.getHeaders, search: params });
return this.http
.get(`/api/projects`, buildHttpRequestOptions(params))
.get(baseUrl, buildHttpRequestOptions(params))
.map(response => response.json())
.catch(error => Observable.throw(error));
}
public updateProjectPolicy(projectId: number | string, projectPolicy: ProjectPolicy): any {
let baseUrl: string = this.config.projectBaseEndpoint ? this.config.projectBaseEndpoint : '/api/projects';
return this.http
.put(`/api/projects/${projectId}`, { 'metadata': {
'public': projectPolicy.Public ? 'true' : 'false',
'enable_content_trust': projectPolicy.ContentTrust ? 'true' : 'false',
'prevent_vul': projectPolicy.PreventVulImg ? 'true' : 'false',
'severity': projectPolicy.PreventVulImgSeverity,
'auto_scan': projectPolicy.ScanImgOnPush ? 'true' : 'false'
} }, HTTP_JSON_OPTIONS)
.put(`${baseUrl}/${projectId}`, {
'metadata': {
'public': projectPolicy.Public ? 'true' : 'false',
'enable_content_trust': projectPolicy.ContentTrust ? 'true' : 'false',
'prevent_vul': projectPolicy.PreventVulImg ? 'true' : 'false',
'severity': projectPolicy.PreventVulImgSeverity,
'auto_scan': projectPolicy.ScanImgOnPush ? 'true' : 'false'
}
},
HTTP_JSON_OPTIONS)
.map(response => response.status)
.catch(error => Observable.throw(error));
}

View File

@ -147,7 +147,7 @@ export class TagDefaultService extends TagService {
return Promise.reject('Invalid parameters.');
}
let _addLabelToImageUrl = `/api/repositories/${repoName}/tags/${tagName}/labels`;
let _addLabelToImageUrl = `${this._baseUrl}/${repoName}/tags/${tagName}/labels`;
return this.http.post(_addLabelToImageUrl, {id: labelId}, HTTP_JSON_OPTIONS).toPromise()
.then(response => response.status)
.catch(error => Promise.reject(error));
@ -159,7 +159,7 @@ export class TagDefaultService extends TagService {
return Promise.reject('Invalid parameters.');
}
let _addLabelToImageUrl = `/api/repositories/${repoName}/tags/${tagName}/labels/${labelId}`;
let _addLabelToImageUrl = `${this._baseUrl}/${repoName}/tags/${tagName}/labels/${labelId}`;
return this.http.delete(_addLabelToImageUrl).toPromise()
.then(response => response.status)
.catch(error => Promise.reject(error));

View File

@ -30,7 +30,7 @@
"clarity-icons": "^0.10.27",
"clarity-ui": "^0.10.27",
"core-js": "^2.4.1",
"harbor-ui": "0.7.7",
"harbor-ui": "0.7.10",
"intl": "^1.2.5",
"mutationobserver-shim": "^0.3.2",
"ngx-cookie": "^1.0.0",