Merge pull request #10863 from AllForNothing/api-center

Fix Api cennter
This commit is contained in:
Will Sun 2020-03-05 10:00:15 +08:00 committed by GitHub
commit a5d9a3b65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 14 deletions

View File

@ -15,6 +15,7 @@ COPY ./api/v2.0/legacy_swagger.yaml /build_dir/swagger.yaml
COPY ./api/v2.0/swagger.yaml /build_dir/swagger2.yaml COPY ./api/v2.0/swagger.yaml /build_dir/swagger2.yaml
RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger.yaml > swagger.json RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger.yaml > swagger.json
RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger2.yaml > swagger2.json
COPY ./LICENSE /build_dir COPY ./LICENSE /build_dir
COPY src/portal /build_dir COPY src/portal /build_dir
@ -28,6 +29,7 @@ FROM goharbor/harbor-portal-base:${harbor_base_image_version}
COPY --from=nodeportal /build_dir/dist /usr/share/nginx/html COPY --from=nodeportal /build_dir/dist /usr/share/nginx/html
COPY --from=nodeportal /build_dir/swagger.yaml /usr/share/nginx/html COPY --from=nodeportal /build_dir/swagger.yaml /usr/share/nginx/html
COPY --from=nodeportal /build_dir/swagger.json /usr/share/nginx/html COPY --from=nodeportal /build_dir/swagger.json /usr/share/nginx/html
COPY --from=nodeportal /build_dir/swagger2.json /usr/share/nginx/html
COPY --from=nodeportal /build_dir/LICENSE /usr/share/nginx/html COPY --from=nodeportal /build_dir/LICENSE /usr/share/nginx/html
COPY make/photon/portal/nginx.conf /etc/nginx/nginx.conf COPY make/photon/portal/nginx.conf /etc/nginx/nginx.conf

View File

@ -1,12 +1,18 @@
import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core'; import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { throwError as observableThrowError, Observable } from 'rxjs'; import { throwError as observableThrowError, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { catchError } from 'rxjs/operators';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CookieService } from "ngx-cookie"; import { CookieService } from "ngx-cookie";
import * as SwaggerUI from 'swagger-ui';
import { mergeDeep } from "../../lib/utils/utils";
enum SwaggerJsonUrls {
SWAGGER1 = '/swagger.json',
SWAGGER2 = '/swagger2.json'
}
const SwaggerUI = require('swagger-ui');
@Component({ @Component({
selector: 'dev-center', selector: 'dev-center',
templateUrl: 'dev-center.component.html', templateUrl: 'dev-center.component.html',
@ -15,8 +21,6 @@ const SwaggerUI = require('swagger-ui');
}) })
export class DevCenterComponent implements AfterViewInit, OnInit { export class DevCenterComponent implements AfterViewInit, OnInit {
private ui: any; private ui: any;
private host: any;
private json: any;
constructor( constructor(
private el: ElementRef, private el: ElementRef,
private http: HttpClient, private http: HttpClient,
@ -48,13 +52,15 @@ export class DevCenterComponent implements AfterViewInit, OnInit {
} }
} }
}; };
this.http.get("/swagger.json") forkJoin([this.http.get(SwaggerJsonUrls.SWAGGER1), this.http.get(SwaggerJsonUrls.SWAGGER2)])
.pipe(catchError(error => observableThrowError(error))) .pipe(catchError(error => observableThrowError(error)))
.subscribe(json => { .subscribe(jsonArr => {
const json: object = {};
mergeDeep(json, jsonArr[0], jsonArr[1]);
json['host'] = window.location.host; json['host'] = window.location.host;
const protocal = window.location.protocol; const protocal = window.location.protocol;
json['schemes'] = [protocal.replace(":", "")]; json['schemes'] = [protocal.replace(":", "")];
let ui = SwaggerUI({ this.ui = SwaggerUI({
spec: json, spec: json,
domNode: this.el.nativeElement.querySelector('.swagger-container'), domNode: this.el.nativeElement.querySelector('.swagger-container'),
deepLinking: true, deepLinking: true,

View File

@ -8,6 +8,7 @@ import { AdditionLink } from "../../../../../../../ng-swagger-gen/models/additio
import { ErrorHandler } from "../../../../../../lib/utils/error-handler"; import { ErrorHandler } from "../../../../../../lib/utils/error-handler";
import * as yaml from "js-yaml"; import * as yaml from "js-yaml";
import { finalize } from "rxjs/operators"; import { finalize } from "rxjs/operators";
import { isObject } from "../../../../../../lib/utils/utils";
@Component({ @Component({
selector: "hbr-artifact-values", selector: "hbr-artifact-values",
@ -84,7 +85,7 @@ export class ValuesComponent implements OnInit {
format(obj: object) { format(obj: object) {
for (let name in obj) { for (let name in obj) {
if (obj.hasOwnProperty(name)) { if (obj.hasOwnProperty(name)) {
if (obj[name] instanceof Object) { if (isObject(obj[name])) {
for (let key in obj[name]) { for (let key in obj[name]) {
if (obj[name].hasOwnProperty(key)) { if (obj[name].hasOwnProperty(key)) {
obj[`${name}.${key}`] = obj[name][key]; obj[`${name}.${key}`] = obj[name][key];

View File

@ -2,7 +2,7 @@ import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/cor
import { DatePipe } from "@angular/common"; import { DatePipe } from "@angular/common";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { Artifact } from "../../../../../../ng-swagger-gen/models/artifact"; import { Artifact } from "../../../../../../ng-swagger-gen/models/artifact";
import { formatSize } from "../../../../../lib/utils/utils"; import { isObject } from "../../../../../lib/utils/utils";
enum Types { enum Types {
CREATED = 'created', CREATED = 'created',
@ -36,7 +36,7 @@ export class ArtifactCommonPropertiesComponent implements OnInit, OnChanges {
Object.assign(this.commonProperties, this.artifactDetails.extra_attrs); Object.assign(this.commonProperties, this.artifactDetails.extra_attrs);
for (let name in this.commonProperties) { for (let name in this.commonProperties) {
if (this.commonProperties.hasOwnProperty(name)) { if (this.commonProperties.hasOwnProperty(name)) {
if (this.commonProperties[name] && this.commonProperties[name] instanceof Object) { if (isObject(this.commonProperties[name])) {
this.commonProperties[name] = JSON.stringify(this.commonProperties[name]); this.commonProperties[name] = JSON.stringify(this.commonProperties[name]);
} }
if (name === Types.CREATED) { if (name === Types.CREATED) {

View File

@ -51,7 +51,6 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
if ((this.status === VULNERABILITY_SCAN_STATUS.RUNNING || if ((this.status === VULNERABILITY_SCAN_STATUS.RUNNING ||
this.status === VULNERABILITY_SCAN_STATUS.PENDING) && this.status === VULNERABILITY_SCAN_STATUS.PENDING) &&
!this.stateCheckTimer) { !this.stateCheckTimer) {
@ -188,7 +187,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
this.summary = clone(newVal); this.summary = clone(newVal);
} }
viewLog(): string { viewLog(): string {
return `${ CURRENT_BASE_HREF }/projects/${this.projectName}/repositories/${this.repoName} return `${ CURRENT_BASE_HREF }/projects/${this.projectName
/artifacts/${this.artifactDigest}/scan/${this.summary.report_id}/log`; }/repositories/${this.repoName}/artifacts/${this.artifactDigest}/scan/${this.summary.report_id}/log`;
} }
} }

View File

@ -597,3 +597,34 @@ export function formatSize(tagSize: string): string {
return size + "B"; return size + "B";
} }
} }
/**
* Simple object check.
* @param item
* @returns {boolean}
*/
export function isObject(item): boolean {
return (item && typeof item === 'object' && !Array.isArray(item));
}
/**
* Deep merge two objects.
* @param target
* @param ...sources
*/
export function mergeDeep(target, ...sources) {
if (!sources.length) { return target; }
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) { Object.assign(target, { [key]: {} }); }
mergeDeep(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return mergeDeep(target, ...sources);
}