Update APIs to only accept encoded repository name

Signed-off-by: Yogi_Wang <yawang@vmware.com>
This commit is contained in:
Yogi_Wang 2020-04-07 17:06:26 +08:00 committed by Wenkai Yin
parent 7188e01569
commit 3775509ce5
9 changed files with 34 additions and 22 deletions

View File

@ -34,7 +34,7 @@ import {
clone, clone,
CustomComparator, CustomComparator,
DEFAULT_PAGE_SIZE, DEFAULT_SUPPORTED_MIME_TYPE, DEFAULT_PAGE_SIZE, DEFAULT_SUPPORTED_MIME_TYPE,
formatSize, VULNERABILITY_SCAN_STATUS formatSize, VULNERABILITY_SCAN_STATUS, dbEncodeURIComponent
} from "../../../../../../lib/utils/utils"; } from "../../../../../../lib/utils/utils";
import { import {
ConfirmationAcknowledgement, ConfirmationAcknowledgement,
@ -335,7 +335,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
} }
if (this.artifactDigest) { if (this.artifactDigest) {
const artifactParam: NewArtifactService.GetArtifactParams = { const artifactParam: NewArtifactService.GetArtifactParams = {
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
projectName: this.projectName, projectName: this.projectName,
reference: this.artifactDigest, reference: this.artifactDigest,
withImmutableStatus: true, withImmutableStatus: true,
@ -351,7 +351,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
res.references.forEach((child, index) => { res.references.forEach((child, index) => {
if (index >= (pageNumber - 1) * this.pageSize && index < pageNumber * this.pageSize) { if (index >= (pageNumber - 1) * this.pageSize && index < pageNumber * this.pageSize) {
let childParams: NewArtifactService.GetArtifactParams = { let childParams: NewArtifactService.GetArtifactParams = {
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
projectName: this.projectName, projectName: this.projectName,
reference: child.child_digest, reference: child.child_digest,
withImmutableStatus: true, withImmutableStatus: true,
@ -378,7 +378,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
} else { } else {
let listArtifactParams: NewArtifactService.ListArtifactsParams = { let listArtifactParams: NewArtifactService.ListArtifactsParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
withLabel: true, withLabel: true,
withScanOverview: true, withScanOverview: true,
withTag: true withTag: true
@ -480,7 +480,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
this.selectedRow = this.selectedTag; this.selectedRow = this.selectedTag;
let params: NewArtifactService.AddLabelParams = { let params: NewArtifactService.AddLabelParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
reference: this.selectedRow[0].digest, reference: this.selectedRow[0].digest,
label: labelInfo.label label: labelInfo.label
}; };
@ -517,7 +517,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
this.selectedRow = this.selectedTag; this.selectedRow = this.selectedTag;
let params: NewArtifactService.RemoveLabelParams = { let params: NewArtifactService.RemoveLabelParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
reference: this.selectedRow[0].digest, reference: this.selectedRow[0].digest,
labelId: labelId labelId: labelId
}; };
@ -675,18 +675,18 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
onRetag() { onRetag() {
let params: NewArtifactService.CopyArtifactParams = { let params: NewArtifactService.CopyArtifactParams = {
projectName: this.imageNameInput.projectName.value, projectName: this.imageNameInput.projectName.value,
repositoryName: this.imageNameInput.repoName.value, repositoryName: dbEncodeURIComponent(this.imageNameInput.repoName.value),
from: `${this.projectName}/${this.repoName}@${this.selectedRow[0].digest}`, from: `${this.projectName}/${this.repoName}@${this.selectedRow[0].digest}`,
}; };
this.newArtifactService.CopyArtifact(params) this.newArtifactService.CopyArtifact(params)
.pipe(finalize(() => { .pipe(finalize(() => {
this.retagDialogOpened = false;
this.imageNameInput.form.reset(); this.imageNameInput.form.reset();
})) }))
.subscribe(response => { .subscribe(response => {
this.translateService.get('RETAG.MSG_SUCCESS').subscribe((res: string) => { this.translateService.get('RETAG.MSG_SUCCESS').subscribe((res: string) => {
this.errorHandlerService.info(res); this.errorHandlerService.info(res);
}); });
this.retagDialogOpened = false;
}, error => { }, error => {
this.errorHandlerService.error(error); this.errorHandlerService.error(error);
}); });
@ -779,7 +779,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
// } else { // } else {
let params: NewArtifactService.DeleteArtifactParams = { let params: NewArtifactService.DeleteArtifactParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
reference: artifact.digest reference: artifact.digest
}; };
return this.newArtifactService return this.newArtifactService

View File

@ -27,6 +27,7 @@ import { Project } from '../../../project';
import { import {
RepositoryService as NewRepositoryService RepositoryService as NewRepositoryService
} from "../../../../../../ng-swagger-gen/services/repository.service"; } from "../../../../../../ng-swagger-gen/services/repository.service";
import { dbEncodeURIComponent } from '../../../../../lib/utils/utils';
const TabLinkContentMap: { [index: string]: string } = { const TabLinkContentMap: { [index: string]: string } = {
'repo-info': 'info', 'repo-info': 'info',
'repo-image': 'image' 'repo-image': 'image'
@ -117,7 +118,7 @@ export class ArtifactListComponent implements OnInit {
retrieve(state?: State) { retrieve(state?: State) {
let params: NewRepositoryService.GetRepositoryParams = { let params: NewRepositoryService.GetRepositoryParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName repositoryName: dbEncodeURIComponent(this.repoName),
}; };
this.newRepositoryService.getRepository(params) this.newRepositoryService.getRepository(params)
.subscribe(response => { .subscribe(response => {
@ -168,7 +169,7 @@ export class ArtifactListComponent implements OnInit {
} }
this.onGoing = true; this.onGoing = true;
let params: NewRepositoryService.UpdateRepositoryParams = { let params: NewRepositoryService.UpdateRepositoryParams = {
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
repository: {description: this.imageInfo}, repository: {description: this.imageInfo},
projectName: this.projectName, projectName: this.projectName,
}; };

View File

@ -8,6 +8,7 @@ import { ActivatedRoute, Router } from "@angular/router";
import { AppConfigService } from "../../../services/app-config.service"; import { AppConfigService } from "../../../services/app-config.service";
import { Project } from "../../project"; import { Project } from "../../project";
import { finalize } from "rxjs/operators"; import { finalize } from "rxjs/operators";
import { dbEncodeURIComponent } from "../../../../lib/utils/utils";
@Component({ @Component({
selector: "artifact-summary", selector: "artifact-summary",
@ -87,7 +88,7 @@ export class ArtifactSummaryComponent implements OnInit {
getArtifactDetails(): void { getArtifactDetails(): void {
this.loading = true; this.loading = true;
this.artifactService.getArtifact({ this.artifactService.getArtifact({
repositoryName: this.repositoryName, repositoryName: dbEncodeURIComponent(this.repositoryName),
reference: this.artifactDigest, reference: this.artifactDigest,
projectName: this.projectName, projectName: this.projectName,
withLabel: true, withLabel: true,

View File

@ -21,7 +21,7 @@ import {
UserPermissionService, USERSTATICPERMISSION UserPermissionService, USERSTATICPERMISSION
} from "../../../../../lib/services"; } from "../../../../../lib/services";
import { ClrDatagridStateInterface } from '@clr/angular'; import { ClrDatagridStateInterface } from '@clr/angular';
import { DEFAULT_PAGE_SIZE, calculatePage } from '../../../../../lib/utils/utils'; import { DEFAULT_PAGE_SIZE, calculatePage, dbEncodeURIComponent } from '../../../../../lib/utils/utils';
class InitTag { class InitTag {
name = ""; name = "";
@ -74,7 +74,7 @@ export class ArtifactTagComponent implements OnInit, OnDestroy {
checkTagName(name) { checkTagName(name) {
let listArtifactParams: ArtifactService.ListArtifactsParams = { let listArtifactParams: ArtifactService.ListArtifactsParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repositoryName, repositoryName: dbEncodeURIComponent(this.repositoryName),
withLabel: true, withLabel: true,
withScanOverview: true, withScanOverview: true,
withTag: true, withTag: true,
@ -111,7 +111,7 @@ export class ArtifactTagComponent implements OnInit, OnDestroy {
if (pageNumber <= 0) { pageNumber = 1; } if (pageNumber <= 0) { pageNumber = 1; }
let params: ArtifactService.ListTagsParams = { let params: ArtifactService.ListTagsParams = {
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repositoryName, repositoryName: dbEncodeURIComponent(this.repositoryName),
reference: this.artifactDetails.digest, reference: this.artifactDetails.digest,
page: pageNumber, page: pageNumber,
withSignature: true, withSignature: true,
@ -272,6 +272,8 @@ export class ArtifactTagComponent implements OnInit, OnDestroy {
existValid(name) { existValid(name) {
if (name) { if (name) {
this.tagNameChecker.next(name); this.tagNameChecker.next(name);
} else {
this.isTagNameExist = false;
} }
} }
toggleTagListOpenOrClose() { toggleTagListOpenOrClose() {

View File

@ -24,7 +24,7 @@ import {
UserPermissionService, USERSTATICPERMISSION UserPermissionService, USERSTATICPERMISSION
} from "../../../lib/services"; } from "../../../lib/services";
import { FilterComponent } from "../../../lib/components/filter/filter.component"; import { FilterComponent } from "../../../lib/components/filter/filter.component";
import { calculatePage, clone, DEFAULT_PAGE_SIZE } from "../../../lib/utils/utils"; import { calculatePage, clone, DEFAULT_PAGE_SIZE, dbEncodeURIComponent } from "../../../lib/utils/utils";
import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config"; import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config";
import { ErrorHandler } from "../../../lib/utils/error-handler"; import { ErrorHandler } from "../../../lib/utils/error-handler";
import { ConfirmationButtons, ConfirmationState, ConfirmationTargets } from "../../../lib/entities/shared.const"; import { ConfirmationButtons, ConfirmationState, ConfirmationTargets } from "../../../lib/entities/shared.const";
@ -222,7 +222,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit, OnDestroy
this.operationService.publishInfo(operMessage); this.operationService.publishInfo(operMessage);
return this.newRepoService return this.newRepoService
.deleteRepository({ .deleteRepository({
repositoryName: repo.name, repositoryName: dbEncodeURIComponent(repo.name),
projectName: this.projectName projectName: this.projectName
}) })
.pipe(map( .pipe(map(

View File

@ -14,7 +14,8 @@ import {
clone, clone,
CURRENT_BASE_HREF, CURRENT_BASE_HREF,
DEFAULT_SUPPORTED_MIME_TYPE, DEFAULT_SUPPORTED_MIME_TYPE,
VULNERABILITY_SCAN_STATUS VULNERABILITY_SCAN_STATUS,
dbEncodeURIComponent
} from "../../../../lib/utils/utils"; } from "../../../../lib/utils/utils";
import { ArtifactService } from "../../../../../ng-swagger-gen/services/artifact.service"; import { ArtifactService } from "../../../../../ng-swagger-gen/services/artifact.service";
import { Artifact } from "../../../../../ng-swagger-gen/models/artifact"; import { Artifact } from "../../../../../ng-swagger-gen/models/artifact";
@ -118,7 +119,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
this.onSubmitting = true; this.onSubmitting = true;
this.scanningService.startVulnerabilityScanning(this.projectName, this.repoName, this.artifactDigest) this.scanningService.startVulnerabilityScanning(this.projectName, dbEncodeURIComponent(this.repoName), this.artifactDigest)
.pipe(finalize(() => this.submitFinish.emit(false))) .pipe(finalize(() => this.submitFinish.emit(false)))
.subscribe(() => { .subscribe(() => {
this.onSubmitting = false; this.onSubmitting = false;
@ -149,7 +150,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
} }
this.artifactService.getArtifact({ this.artifactService.getArtifact({
projectName: this.projectName, projectName: this.projectName,
repositoryName: this.repoName, repositoryName: dbEncodeURIComponent(this.repoName),
reference: this.artifactDigest, reference: this.artifactDigest,
withScanOverview: true withScanOverview: true
}) })

View File

@ -19,6 +19,7 @@ import { Artifact } from "../../../../ng-swagger-gen/models/artifact";
import { ArtifactService } from "../../../../ng-swagger-gen/services/artifact.service"; import { ArtifactService } from "../../../../ng-swagger-gen/services/artifact.service";
import { Project } from "../../project/project"; import { Project } from "../../project/project";
import { ProjectService } from "../../../lib/services"; import { ProjectService } from "../../../lib/services";
import { dbEncodeURIComponent } from '../../../lib/utils/utils';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -38,7 +39,7 @@ export class ArtifactDetailRoutingResolverService implements Resolve<Artifact> {
.pipe( .pipe(
mergeMap((project: Project) => { mergeMap((project: Project) => {
return forkJoin([this.artifactService.getArtifact({ return forkJoin([this.artifactService.getArtifact({
repositoryName: repositoryName, repositoryName: dbEncodeURIComponent(repositoryName),
reference: artifactDigest, reference: artifactDigest,
projectName: project.name, projectName: project.name,
withLabel: true, withLabel: true,

View File

@ -624,3 +624,9 @@ export function mergeDeep(target, ...sources) {
} }
return mergeDeep(target, ...sources); return mergeDeep(target, ...sources);
} }
export function dbEncodeURIComponent(url: string) {
if (typeof url === "string") {
return encodeURIComponent(encodeURIComponent(url));
}
return "";
}

View File

@ -59,7 +59,7 @@ class TestProjects(unittest.TestCase):
self.assertEqual(quota[0].used["storage"], 2789002) self.assertEqual(quota[0].used["storage"], 2789002)
#8. Delete repository(RA) by user(UA); #8. Delete repository(RA) by user(UA);
self.repo.delete_repoitory(project_name, image, **ADMIN_CLIENT) self.repo.delete_repoitory(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
#9. Quota should be 0 #9. Quota should be 0
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT) quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)