Updates for verfied tags deletion.

This commit is contained in:
kunw 2017-03-13 19:34:30 +08:00
parent e80840c2d3
commit 959af275d8
6 changed files with 54 additions and 47 deletions

View File

@ -1,10 +0,0 @@
import { VerifiedSignature } from './verified-signature';
export const verifiedSignatures: VerifiedSignature[] = [
{
"tag": "latest",
"hashes": {
"sha256": "E1lggRW5RZnlZBY4usWu8d36p5u5YFfr9B68jTOs+Kc="
}
}
];

View File

@ -5,8 +5,6 @@ import { Repository } from './repository';
import { Tag } from './tag'; import { Tag } from './tag';
import { VerifiedSignature } from './verified-signature'; import { VerifiedSignature } from './verified-signature';
import { verifiedSignatures } from './mock-verfied-signature';
import { Observable } from 'rxjs/Observable' import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/of'; import 'rxjs/add/observable/of';
import 'rxjs/add/operator/mergeMap'; import 'rxjs/add/operator/mergeMap';
@ -43,25 +41,23 @@ export class RepositoryService {
listTagsWithVerifiedSignatures(repoName: string): Observable<Tag[]> { listTagsWithVerifiedSignatures(repoName: string): Observable<Tag[]> {
return this.http return this.http
.get(`/api/repositories/tags?repo_name=${repoName}&detail=1`) .get(`/api/repositories/signatures?repo_name=${repoName}`)
.map(response=>response.json()) .map(response=>response)
.catch(error=>Observable.throw(error)) .flatMap(res=>
.flatMap((tags: Tag[])=> this.listTags(repoName)
this.http .map((tags: Tag[])=>{
.get(`/api/repositories/signatures?repo_name=${repoName}`) let signatures = res.json();
.map(res=>{ tags.forEach(t=>{
let signatures = res.json(); for(let i = 0; i < signatures.length; i++) {
tags.forEach(t=>{ if(signatures[i].tag === t.tag) {
for(let i = 0; i < signatures.length; i++) { t.verified = true;
if(signatures[i].tag === t.tag) { break;
t.verified = true;
break;
}
} }
}); }
return tags; });
}) return tags;
.catch(error=>Observable.throw(error)) })
.catch(error=>Observable.throw(error))
) )
.catch(error=>Observable.throw(error)); .catch(error=>Observable.throw(error));
} }

View File

@ -22,7 +22,7 @@
<clr-dg-cell>{{t.architecture}}</clr-dg-cell> <clr-dg-cell>{{t.architecture}}</clr-dg-cell>
<clr-dg-cell>{{t.os}} <clr-dg-cell>{{t.os}}
<harbor-action-overflow> <harbor-action-overflow>
<a href="javascript:void(0)" class="dropdown-item" (click)="deleteTag(t.tag)">{{'REPOSITORY.DELETE' | translate}}</a> <a href="javascript:void(0)" class="dropdown-item" (click)="deleteTag(t)">{{'REPOSITORY.DELETE' | translate}}</a>
</harbor-action-overflow> </harbor-action-overflow>
</clr-dg-cell> </clr-dg-cell>
</clr-dg-row> </clr-dg-row>

View File

@ -32,16 +32,24 @@ export class TagRepositoryComponent implements OnInit, OnDestroy {
private repositoryService: RepositoryService) { private repositoryService: RepositoryService) {
this.subscription = this.deletionDialogService.deletionConfirm$.subscribe( this.subscription = this.deletionDialogService.deletionConfirm$.subscribe(
message=>{ message=>{
let tagName = message.data; let tag = message.data;
this.repositoryService if(tag) {
.deleteRepoByTag(this.repoName, tagName) if(tag.verified) {
.subscribe( return;
response=>{ } else {
this.retrieve(); let tagName = tag.tag;
console.log('Deleted repo:' + this.repoName + ' with tag:' + tagName); this.repositoryService
}, .deleteRepoByTag(this.repoName, tagName)
error=>this.messageService.announceMessage(error.status, 'Failed to delete tag:' + tagName + ' under repo:' + this.repoName, AlertType.DANGER) .subscribe(
); response=>{
this.retrieve();
console.log('Deleted repo:' + this.repoName + ' with tag:' + tagName);
},
error=>this.messageService.announceMessage(error.status, 'Failed to delete tag:' + tagName + ' under repo:' + this.repoName, AlertType.DANGER)
);
}
}
} }
) )
} }
@ -58,8 +66,9 @@ export class TagRepositoryComponent implements OnInit, OnDestroy {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
} }
retrieve() { retrieve() {
this.tags = [];
this.repositoryService this.repositoryService
.listTagsWithVerifiedSignatures(this.repoName) .listTagsWithVerifiedSignatures(this.repoName)
.subscribe( .subscribe(
@ -81,11 +90,19 @@ export class TagRepositoryComponent implements OnInit, OnDestroy {
error=>this.messageService.announceMessage(error.status, 'Failed to list tags with repo:' + this.repoName, AlertType.DANGER)); error=>this.messageService.announceMessage(error.status, 'Failed to list tags with repo:' + this.repoName, AlertType.DANGER));
} }
deleteTag(tagName: string) { deleteTag(tag: TagView) {
let message = new DeletionMessage( if(tag) {
'REPOSITORY.DELETION_TITLE_TAG', 'REPOSITORY.DELETION_SUMMARY_TAG', let titleKey: string, summaryKey: string;
tagName, tagName, DeletionTargets.TAG); if (tag.verified) {
this.deletionDialogService.openComfirmDialog(message); titleKey = 'REPOSITORY.DELETION_TITLE_TAG_DENIED';
summaryKey = 'REPOSITORY.DELETION_SUMMARY_TAG_DENIED';
} else {
titleKey = 'REPOSITORY.DELETION_TITLE_TAG';
summaryKey = 'REPOSITORY.DELETION_SUMMARY_TAG';
}
let message = new DeletionMessage(titleKey, summaryKey, tag.tag, tag, DeletionTargets.TAG);
this.deletionDialogService.openComfirmDialog(message);
}
} }
} }

View File

@ -256,6 +256,8 @@
"DELETION_SUMMARY_REPO": "Do you want to delete repository {{param}}?", "DELETION_SUMMARY_REPO": "Do you want to delete repository {{param}}?",
"DELETION_TITLE_TAG": "Confirm Tag Deletion", "DELETION_TITLE_TAG": "Confirm Tag Deletion",
"DELETION_SUMMARY_TAG": "Do you want to delete tag {{param}}?", "DELETION_SUMMARY_TAG": "Do you want to delete tag {{param}}?",
"DELETION_TITLE_TAG_DENIED": "Signed Tag can't be deleted",
"DELETION_SUMMARY_TAG_DENIED": "The tag must be removed from Notary before they can be deleted.",
"FILTER_FOR_REPOSITORIES": "Filter for repositories", "FILTER_FOR_REPOSITORIES": "Filter for repositories",
"TAG": "Tag", "TAG": "Tag",
"VERIFIED": "Verified", "VERIFIED": "Verified",

View File

@ -256,6 +256,8 @@
"DELETION_SUMMARY_REPO": "确认删除镜像仓库 {{param}}?", "DELETION_SUMMARY_REPO": "确认删除镜像仓库 {{param}}?",
"DELETION_TITLE_TAG": "删除镜像标签确认", "DELETION_TITLE_TAG": "删除镜像标签确认",
"DELETION_SUMMARY_TAG": "确认删除镜像标签 {{param}}?", "DELETION_SUMMARY_TAG": "确认删除镜像标签 {{param}}?",
"DELETION_TITLE_TAG_DENIED": "已签名的镜像不能被删除",
"DELETION_SUMMARY_TAG_DENIED": "要删除此镜像标签必须首先从Notary中删除。",
"FILTER_FOR_REPOSITORIES": "过滤镜像仓库", "FILTER_FOR_REPOSITORIES": "过滤镜像仓库",
"TAG": "标签", "TAG": "标签",
"VERIFIED": "已验证", "VERIFIED": "已验证",