mirror of
https://github.com/goharbor/harbor
synced 2024-09-20 18:39:52 +00:00
Merge pull request #11089 from jwangyangls/clear-dead-code
[OCI] Remove dead code
This commit is contained in:
commit
89cdd7a9f9
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
import { Project } from "../../project/project";
|
||||
import { HelmChartSearchResultItem } from "../../project/helm-chart/helm-chart.interface.service";
|
||||
import { Repository } from "../../../lib/services";
|
||||
import { Repository } from "../../../../ng-swagger-gen/models/repository";
|
||||
|
||||
export class SearchResults {
|
||||
constructor() {
|
||||
|
|
|
@ -14,7 +14,7 @@ import { HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../../lib/utils/utils";
|
|||
*
|
||||
**
|
||||
* @abstract
|
||||
* class RepositoryService
|
||||
* class HelmChartService
|
||||
*/
|
||||
export abstract class HelmChartService {
|
||||
/**
|
||||
|
|
|
@ -17,12 +17,11 @@ import { ListProjectComponent } from './list-project/list-project.component';
|
|||
import { ProjectTypes } from '../shared/shared.const';
|
||||
import { ConfigurationService } from '../config/config.service';
|
||||
import { SessionService } from "../shared/session.service";
|
||||
import { ProjectService, QuotaHardInterface, Repository, RequestQueryParams } from "../../lib/services";
|
||||
import { ProjectService, QuotaHardInterface } from "../../lib/services";
|
||||
import { Configuration } from "../../lib/components/config/config";
|
||||
import { FilterComponent } from '../../lib/components/filter/filter.component';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, finalize, switchMap } from 'rxjs/operators';
|
||||
import { calculatePage, doFiltering, doSorting } from '../../lib/utils/utils';
|
||||
import { Project } from './project';
|
||||
import { MessageHandlerService } from '../shared/message-handler/message-handler.service';
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ import { ValuesComponent } from "./repository/artifact/artifact-additions/values
|
|||
import {
|
||||
ArtifactVulnerabilitiesComponent
|
||||
} from "./repository/artifact/artifact-additions/artifact-vulnerabilities/artifact-vulnerabilities.component";
|
||||
import { RepositoryDefaultService, RepositoryService } from "./repository/repository.service";
|
||||
import { ArtifactDefaultService, ArtifactService } from "./repository/artifact/artifact.service";
|
||||
import { GridViewComponent } from "./repository/gridview/grid-view.component";
|
||||
import { LastTriggerComponent } from "./webhook/last-trigger/last-trigger.component";
|
||||
|
@ -120,9 +119,7 @@ import { LastTriggerComponent } from "./webhook/last-trigger/last-trigger.compon
|
|||
RobotService,
|
||||
WebhookService,
|
||||
ConfigScannerService,
|
||||
RepositoryDefaultService,
|
||||
ArtifactDefaultService,
|
||||
{ provide: RepositoryService, useClass: RepositoryDefaultService },
|
||||
{ provide: ArtifactService, useClass: ArtifactDefaultService },
|
||||
]
|
||||
})
|
||||
|
|
|
@ -14,8 +14,6 @@ import {
|
|||
LabelService,
|
||||
ProjectDefaultService,
|
||||
ProjectService,
|
||||
RetagDefaultService,
|
||||
RetagService,
|
||||
ScanningResultDefaultService,
|
||||
ScanningResultService,
|
||||
UserPermissionDefaultService,
|
||||
|
@ -311,7 +309,6 @@ describe("ArtifactListTabComponent (inline template)", () => {
|
|||
{ provide: SERVICE_CONFIG, useValue: config },
|
||||
{ provide: ArtifactService, useValue: mockArtifactService },
|
||||
{ provide: ProjectService, useClass: ProjectDefaultService },
|
||||
{ provide: RetagService, useClass: RetagDefaultService },
|
||||
{ provide: ScanningResultService, useClass: ScanningResultDefaultService },
|
||||
{ provide: LabelService, useClass: LabelDefaultService },
|
||||
{ provide: UserPermissionService, useClass: UserPermissionDefaultService },
|
||||
|
|
|
@ -30,10 +30,8 @@ import { ClrLoadingState, ClrDatagridStateInterface, ClrDatagridComparatorInterf
|
|||
import { HttpParams } from "@angular/common/http";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import {
|
||||
ArtifactClickEvent,
|
||||
Comparator, Label, LabelService, ProjectService,
|
||||
RetagService, ScanningResultService,
|
||||
State, Tag,
|
||||
Comparator, Label, LabelService, ScanningResultService,
|
||||
State,
|
||||
UserPermissionService, USERSTATICPERMISSION, VulnerabilitySummary
|
||||
} from "../../../../../../lib/services";
|
||||
import {
|
||||
|
@ -89,7 +87,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
|
|||
@Input() registryUrl: string;
|
||||
@Input() withNotary: boolean;
|
||||
@Input() withAdmiral: boolean;
|
||||
tags: Tag[];
|
||||
artifactList: Artifact[] = [];
|
||||
availableTime = AVAILABLE_TIME;
|
||||
showTagManifestOpened: boolean;
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
import { ComponentFixture, TestBed, async, } from '@angular/core/testing';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ArtifactListComponent } from './artifact-list.component';
|
||||
import { of } from "rxjs";
|
||||
import { delay } from 'rxjs/operators';
|
||||
import { ClarityModule } from '@clr/angular';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { RepositoryDefaultService, RepositoryService } from "../../repository.service";
|
||||
import {
|
||||
Repository,
|
||||
RepositoryItem,
|
||||
SystemInfo, SystemInfoDefaultService,
|
||||
SystemInfoService,
|
||||
} from "../../../../../lib/services";
|
||||
import { ArtifactDefaultService, ArtifactService } from "../../artifact/artifact.service";
|
||||
import { ChannelService } from "../../../../../lib/services/channel.service";
|
||||
import { FormsModule } from "@angular/forms";
|
||||
import { MarkdownModule } from "ngx-markdown";
|
||||
|
||||
import { TranslateFakeLoader, TranslateLoader, TranslateModule, TranslateService } from "@ngx-translate/core";
|
||||
import { ErrorHandler } from "../../../../../lib/utils/error-handler";
|
||||
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../../../lib/entities/service.config";
|
||||
import { SharedModule } from "../../../../../lib/utils/shared/shared.module";
|
||||
import {
|
||||
|
@ -29,7 +24,6 @@ describe('ArtifactListComponent (inline template)', () => {
|
|||
|
||||
let compRepo: ArtifactListComponent;
|
||||
let fixture: ComponentFixture<ArtifactListComponent>;
|
||||
let repositoryService: RepositoryService;
|
||||
let systemInfoService: SystemInfoService;
|
||||
let artifactService: ArtifactService;
|
||||
let spyRepos: jasmine.Spy;
|
||||
|
@ -64,34 +58,11 @@ describe('ArtifactListComponent (inline template)', () => {
|
|||
'harbor_version': 'v1.1.1-rc1-160-g565110d'
|
||||
};
|
||||
|
||||
let mockRepoData: RepositoryItem[] = [
|
||||
{
|
||||
'id': 1,
|
||||
'name': 'library/busybox',
|
||||
'project_id': 1,
|
||||
'description': 'asdfsadf',
|
||||
'pull_count': 0,
|
||||
'star_count': 0,
|
||||
'tags_count': 1
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'name': 'library/nginx',
|
||||
'project_id': 1,
|
||||
'description': 'asdf',
|
||||
'pull_count': 0,
|
||||
'star_count': 0,
|
||||
'tags_count': 1
|
||||
}
|
||||
];
|
||||
let newRepositoryService = {
|
||||
updateRepository: () => of(null),
|
||||
getRepository: () => of({description: ''})
|
||||
};
|
||||
let mockRepo: Repository = {
|
||||
metadata: { xTotalCount: 2 },
|
||||
data: mockRepoData
|
||||
};
|
||||
|
||||
const fakedErrorHandler = {
|
||||
error: () => {}
|
||||
};
|
||||
|
@ -119,7 +90,6 @@ describe('ArtifactListComponent (inline template)', () => {
|
|||
providers: [
|
||||
TranslateService,
|
||||
{ provide: ErrorHandler, useValue: fakedErrorHandler },
|
||||
{ provide: RepositoryService, useClass: RepositoryDefaultService },
|
||||
{ provide: ChannelService, useValue: mockChannelService },
|
||||
{ provide: SystemInfoService, useClass: SystemInfoDefaultService },
|
||||
{ provide: ArtifactService, useClass: ArtifactDefaultService },
|
||||
|
@ -136,10 +106,8 @@ describe('ArtifactListComponent (inline template)', () => {
|
|||
compRepo.projectId = 1;
|
||||
compRepo.hasProjectAdminRole = true;
|
||||
compRepo.repoName = 'library/nginx';
|
||||
repositoryService = fixture.debugElement.injector.get(RepositoryService);
|
||||
systemInfoService = fixture.debugElement.injector.get(SystemInfoService);
|
||||
artifactService = fixture.debugElement.injector.get(ArtifactService);
|
||||
spyRepos = spyOn(repositoryService, 'getRepositories').and.returnValues(of(mockRepo).pipe(delay(0)));
|
||||
spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValues(of(mockSystemInfo).pipe(delay(0)));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
|
|
@ -13,14 +13,13 @@
|
|||
// limitations under the License.
|
||||
import { Component, OnInit, ViewChild, Input, Output, EventEmitter, OnDestroy } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ArtifactClickEvent, RepositoryItem, State, SystemInfo, SystemInfoService } from "../../../../../lib/services";
|
||||
import { ArtifactClickEvent, State, SystemInfo, SystemInfoService } from "../../../../../lib/services";
|
||||
import {
|
||||
ConfirmationAcknowledgement,
|
||||
ConfirmationDialogComponent,
|
||||
ConfirmationMessage
|
||||
} from "../../../../../lib/components/confirmation-dialog";
|
||||
import { ErrorHandler } from "../../../../../lib/utils/error-handler";
|
||||
import { RepositoryService } from "../../repository.service";
|
||||
import { ArtifactService } from "../../artifact/artifact.service";
|
||||
import { ConfirmationState, ConfirmationTargets } from "../../../../../lib/entities/shared.const";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
|
@ -54,7 +53,6 @@ export class ArtifactListComponent implements OnInit {
|
|||
editing = false;
|
||||
inProgress = true;
|
||||
currentTabID = 'repo-image';
|
||||
changedRepositories: RepositoryItem[];
|
||||
systemInfo: SystemInfo;
|
||||
|
||||
imageInfo: string;
|
||||
|
@ -68,7 +66,6 @@ export class ArtifactListComponent implements OnInit {
|
|||
artifactDigest: string;
|
||||
constructor(
|
||||
private errorHandler: ErrorHandler,
|
||||
private repositoryService: RepositoryService,
|
||||
private systemInfoService: SystemInfoService,
|
||||
private artifactService: ArtifactService,
|
||||
private newRepositoryService: NewRepositoryService,
|
||||
|
|
|
@ -7,7 +7,7 @@ import { of } from 'rxjs';
|
|||
import { IServiceConfig, SERVICE_CONFIG } from "../../../../../lib/entities/service.config";
|
||||
import { SharedModule } from "../../../../../lib/utils/shared/shared.module";
|
||||
import { ErrorHandler } from "../../../../../lib/utils/error-handler";
|
||||
import { TagService } from "../../../../../lib/services";
|
||||
import { ArtifactService } from '../../../../../../ng-swagger-gen/services/artifact.service';
|
||||
import { OperationService } from "../../../../../lib/components/operation/operation.service";
|
||||
import { CURRENT_BASE_HREF } from "../../../../../lib/utils/utils";
|
||||
|
||||
|
@ -18,8 +18,8 @@ describe('ArtifactTagComponent', () => {
|
|||
const mockErrorHandler = {
|
||||
error: () => {}
|
||||
};
|
||||
const mockTagService = {
|
||||
newTag: () => of([]),
|
||||
const mockArtifactService = {
|
||||
createTag: () => of([]),
|
||||
deleteTag: () => of(null),
|
||||
};
|
||||
const config: IServiceConfig = {
|
||||
|
@ -40,7 +40,7 @@ describe('ArtifactTagComponent', () => {
|
|||
ErrorHandler,
|
||||
{ provide: SERVICE_CONFIG, useValue: config },
|
||||
{ provide: mockErrorHandler, useValue: ErrorHandler },
|
||||
{ provide: TagService, useValue: mockTagService },
|
||||
{ provide: ArtifactService, useValue: mockArtifactService },
|
||||
{ provide: OperationService },
|
||||
]
|
||||
})
|
||||
|
|
|
@ -10,12 +10,13 @@ import {
|
|||
ConfirmationMessage
|
||||
} from "../../../../../lib/components/confirmation-dialog";
|
||||
import { OperationService } from "../../../../../lib/components/operation/operation.service";
|
||||
import { Tag, TagService } from "../../../../../lib/services";
|
||||
import { ErrorHandler } from "../../../../../lib/utils/error-handler";
|
||||
import { ConfirmationButtons, ConfirmationState, ConfirmationTargets } from "../../../../../lib/entities/shared.const";
|
||||
import { operateChanges, OperateInfo, OperationState } from "../../../../../lib/components/operation/operate";
|
||||
import { errorHandler } from "../../../../../lib/utils/shared/shared.utils";
|
||||
import { ArtifactFront as Artifact } from "../artifact";
|
||||
import { ArtifactService } from '../../../../../../ng-swagger-gen/services/artifact.service';
|
||||
import { Tag } from '../../../../../../ng-swagger-gen/models/tag';
|
||||
|
||||
class InitTag {
|
||||
name = "";
|
||||
|
@ -44,7 +45,7 @@ export class ArtifactTagComponent implements OnInit {
|
|||
confirmationDialog: ConfirmationDialogComponent;
|
||||
constructor(
|
||||
private operationService: OperationService,
|
||||
private tagService: TagService,
|
||||
private artifactService: ArtifactService,
|
||||
private translateService: TranslateService,
|
||||
private errorHandlerService: ErrorHandler
|
||||
|
||||
|
@ -62,7 +63,14 @@ export class ArtifactTagComponent implements OnInit {
|
|||
this.newTagName = new InitTag();
|
||||
}
|
||||
saveAddTag() {
|
||||
this.tagService.newTag(this.projectName, this.repositoryName, this.artifactDetails.digest, this.newTagName).subscribe(res => {
|
||||
// const tag: NewTag = {name: this.newTagName};
|
||||
const createTagParams: ArtifactService.CreateTagParams = {
|
||||
projectName: this.projectName,
|
||||
repositoryName: this.repositoryName,
|
||||
reference: this.artifactDetails.digest,
|
||||
tag: this.newTagName
|
||||
};
|
||||
this.artifactService.createTag(createTagParams).subscribe(res => {
|
||||
this.newTagformShow = false;
|
||||
this.newTagName = new InitTag();
|
||||
this.refreshArtifact.emit();
|
||||
|
@ -121,8 +129,13 @@ export class ArtifactTagComponent implements OnInit {
|
|||
operMessage.state = OperationState.progressing;
|
||||
operMessage.data.name = tag.name;
|
||||
this.operationService.publishInfo(operMessage);
|
||||
return this.tagService
|
||||
.deleteTag(this.projectName, this.repositoryName, this.artifactDetails.digest, tag.name)
|
||||
const deleteTagParams: ArtifactService.DeleteTagParams = {
|
||||
projectName: this.projectName,
|
||||
repositoryName: this.repositoryName,
|
||||
reference: this.artifactDetails.digest,
|
||||
tagName: tag.name
|
||||
};
|
||||
return this.artifactService.deleteTag(deleteTagParams)
|
||||
.pipe(map(
|
||||
response => {
|
||||
this.translateService.get("BATCH.DELETED_SUCCESS")
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config";
|
||||
import { SharedModule } from "../../../../lib/utils/shared/shared.module";
|
||||
import { TagDefaultService, TagService } from "../../../../lib/services";
|
||||
import { ArtifactDefaultService, ArtifactService } from "../artifact/artifact.service";
|
||||
import { CURRENT_BASE_HREF } from "../../../../lib/utils/utils";
|
||||
|
||||
describe('TagService', () => {
|
||||
|
||||
const mockConfig: IServiceConfig = {
|
||||
repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing"
|
||||
};
|
||||
describe('ArtifactService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
|
@ -16,18 +12,15 @@ describe('TagService', () => {
|
|||
SharedModule
|
||||
],
|
||||
providers: [
|
||||
TagDefaultService,
|
||||
ArtifactDefaultService,
|
||||
{
|
||||
provide: TagService,
|
||||
useClass: TagDefaultService
|
||||
}, {
|
||||
provide: SERVICE_CONFIG,
|
||||
useValue: mockConfig
|
||||
provide: ArtifactService,
|
||||
useClass: ArtifactDefaultService
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be initialized', inject([TagDefaultService], (service: TagService) => {
|
||||
it('should be initialized', inject([ArtifactDefaultService], (service: ArtifactService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
|
|
|
@ -1,234 +1,27 @@
|
|||
import { Injectable, Inject } from "@angular/core";
|
||||
import { HttpClient, HttpResponse } from "@angular/common/http";
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import { Observable, throwError as observableThrowError, Subject } from "rxjs";
|
||||
import { Manifest, RequestQueryParams } from "../../../../lib/services";
|
||||
import { Subject } from "rxjs";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config";
|
||||
import {
|
||||
buildHttpRequestOptionsWithObserveResponse, CURRENT_BASE_HREF,
|
||||
HTTP_GET_OPTIONS,
|
||||
HTTP_JSON_OPTIONS
|
||||
} from "../../../../lib/utils/utils";
|
||||
import { ArtifactFront as Artifact } from "./artifact";
|
||||
|
||||
|
||||
/**
|
||||
* Define the service methods to handle the repository tag related things.
|
||||
*
|
||||
**
|
||||
* @abstract
|
||||
* class TagService
|
||||
* class ArtifactService
|
||||
*/
|
||||
export abstract class ArtifactService {
|
||||
reference: string[];
|
||||
triggerUploadArtifact = new Subject<string>();
|
||||
TriggerArtifactChan$ = this.triggerUploadArtifact.asObservable();
|
||||
/**
|
||||
* Get all the tags under the specified repository.
|
||||
* NOTES: If the Notary is enabled, the signatures should be included in the returned data.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {RequestQueryParams} [queryParams]
|
||||
* returns {(Observable<Tag[]>)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
abstract getArtifactList(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
queryParams?: RequestQueryParams
|
||||
): Observable<HttpResponse<Artifact[]>>;
|
||||
|
||||
/**
|
||||
* Delete the specified tag.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {string} tag
|
||||
* returns {(Observable<any> | any)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
abstract getArtifactFromDigest(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
artifactDigest: string
|
||||
): Observable<Artifact>;
|
||||
|
||||
abstract deleteArtifact(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string
|
||||
): Observable<any>;
|
||||
|
||||
/**
|
||||
* Get the specified tag.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {string} tag
|
||||
* returns {(Observable<Tag>)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
|
||||
abstract addLabelToImages(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
digest: string,
|
||||
labelId: number
|
||||
): Observable<any>;
|
||||
abstract deleteLabelToImages(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
digest: string,
|
||||
labelId: number
|
||||
): Observable<any>;
|
||||
|
||||
/**
|
||||
* Get manifest of tag under the specified repository.
|
||||
*
|
||||
* @abstract
|
||||
* returns {(Observable<Manifest>)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
abstract getManifest(
|
||||
repositoryName: string,
|
||||
tag: string
|
||||
): Observable<Manifest>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement default service for tag.
|
||||
*
|
||||
**
|
||||
* class TagDefaultService
|
||||
* extends {TagService}
|
||||
*/
|
||||
@Injectable()
|
||||
export class ArtifactDefaultService extends ArtifactService {
|
||||
_baseUrl: string;
|
||||
_labelUrl: string;
|
||||
reference: string[] = [];
|
||||
|
||||
triggerUploadArtifact = new Subject<string>();
|
||||
TriggerArtifactChan$ = this.triggerUploadArtifact.asObservable();
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
@Inject(SERVICE_CONFIG) private config: IServiceConfig
|
||||
) {
|
||||
constructor() {
|
||||
super();
|
||||
this._baseUrl = this.config.repositoryBaseEndpoint
|
||||
? this.config.repositoryBaseEndpoint
|
||||
: CURRENT_BASE_HREF + "/repositories";
|
||||
this._labelUrl = this.config.labelEndpoint
|
||||
? this.config.labelEndpoint
|
||||
: CURRENT_BASE_HREF + "/labels";
|
||||
}
|
||||
|
||||
|
||||
_getArtifacts(
|
||||
project_id: string, repositoryName: string,
|
||||
queryParams?: RequestQueryParams
|
||||
): Observable<HttpResponse<Artifact[]>> {
|
||||
if (!queryParams) {
|
||||
queryParams = queryParams = new RequestQueryParams();
|
||||
}
|
||||
|
||||
// queryParams = queryParams.set("detail", "true");
|
||||
let url: string = `${ CURRENT_BASE_HREF }/projects/${project_id}/repositories/${repositoryName}/artifacts`;
|
||||
// /api/v2/projects/{project_id}/repositories/{repositoryName}/artifacts
|
||||
return this.http
|
||||
.get<HttpResponse<Artifact[]>>(url, buildHttpRequestOptionsWithObserveResponse(queryParams))
|
||||
.pipe(map(response => response as HttpResponse<Artifact[]>)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
public getArtifactList(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
queryParams?: RequestQueryParams
|
||||
): Observable<HttpResponse<Artifact[]>> {
|
||||
if (!repositoryName) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
return this._getArtifacts(projectName, repositoryName, queryParams);
|
||||
}
|
||||
public getArtifactFromDigest(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
artifactDigest: string
|
||||
): Observable<Artifact> {
|
||||
if (!artifactDigest) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
let url = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${artifactDigest}`;
|
||||
return this.http.get(url).pipe(catchError(error => observableThrowError(error))) as Observable<Artifact>;
|
||||
}
|
||||
public deleteArtifact(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string
|
||||
): Observable<any> {
|
||||
if (!repositoryName || !projectName || !digest) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
|
||||
let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}`;
|
||||
return this.http
|
||||
.delete(url, HTTP_JSON_OPTIONS)
|
||||
.pipe(map(response => response)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
|
||||
public addLabelToImages(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
digest: string,
|
||||
labelId: number
|
||||
): Observable<any> {
|
||||
if (!labelId || !digest || !repoName) {
|
||||
return observableThrowError("Invalid parameters.");
|
||||
}
|
||||
|
||||
let _addLabelToImageUrl = `
|
||||
${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels`;
|
||||
return this.http
|
||||
.post(_addLabelToImageUrl, { id: labelId }, HTTP_JSON_OPTIONS)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
public deleteLabelToImages(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
digest: string,
|
||||
labelId: number
|
||||
): Observable<any> {
|
||||
if (!labelId || !digest || !repoName) {
|
||||
return observableThrowError("Invalid parameters.");
|
||||
}
|
||||
|
||||
let _addLabelToImageUrl = `
|
||||
${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repoName}/artifacts/${digest}/labels/${labelId}`;
|
||||
return this.http
|
||||
.delete(_addLabelToImageUrl)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
public getManifest(
|
||||
repositoryName: string,
|
||||
tag: string
|
||||
): Observable<Manifest> {
|
||||
if (!repositoryName || !tag) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
let url: string = `${this._baseUrl}/${repositoryName}/tags/${tag}/manifest`;
|
||||
return this.http
|
||||
.get(url, HTTP_GET_OPTIONS)
|
||||
.pipe(map(response => response as Manifest)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,13 @@ import { RepositoryGridviewComponent } from "./repository-gridview.component";
|
|||
import {
|
||||
ProjectDefaultService,
|
||||
ProjectService,
|
||||
Repository,
|
||||
RepositoryItem,
|
||||
RequestQueryParams, RetagDefaultService, RetagService,
|
||||
SystemInfo, SystemInfoService,
|
||||
TagDefaultService,
|
||||
TagService, UserPermissionService
|
||||
UserPermissionService
|
||||
} from "../../../lib/services";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config";
|
||||
import { delay } from 'rxjs/operators';
|
||||
import { SharedModule } from "../../../lib/utils/shared/shared.module";
|
||||
import { ErrorHandler } from "../../../lib/utils/error-handler";
|
||||
import { RepositoryService } from "./repository.service";
|
||||
import { OperationService } from "../../../lib/components/operation/operation.service";
|
||||
import { ProjectModule } from "../project.module";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
|
@ -121,11 +116,8 @@ describe('RepositoryComponentGridview (inline template)', () => {
|
|||
{ provide: ActivatedRoute, useValue: fakedActivatedRoute },
|
||||
{ provide: ErrorHandler, useValue: fakedErrorHandler },
|
||||
{ provide: SERVICE_CONFIG, useValue: config },
|
||||
{ provide: RepositoryService, useValue: fakedRepositoryService },
|
||||
{ provide: NewRepositoryService, useValue: fakedRepositoryService },
|
||||
{ provide: TagService, useClass: TagDefaultService },
|
||||
{ provide: ProjectService, useClass: ProjectDefaultService },
|
||||
{ provide: RetagService, useClass: RetagDefaultService },
|
||||
{ provide: SystemInfoService, useValue: fakedSystemInfoService },
|
||||
{ provide: UserPermissionService, useValue: fakedUserPermissionService },
|
||||
{ provide: OperationService },
|
||||
|
|
|
@ -19,11 +19,9 @@ import {
|
|||
RepositoryService as NewRepositoryService
|
||||
} from "../../../../ng-swagger-gen/services/repository.service";
|
||||
import {
|
||||
Repository,
|
||||
RepositoryItem, RequestQueryParams,
|
||||
SystemInfo,
|
||||
SystemInfoService,
|
||||
TagService, UserPermissionService, USERSTATICPERMISSION
|
||||
UserPermissionService, USERSTATICPERMISSION
|
||||
} from "../../../lib/services";
|
||||
import { FilterComponent } from "../../../lib/components/filter/filter.component";
|
||||
import { calculatePage, clone, DEFAULT_PAGE_SIZE } from "../../../lib/utils/utils";
|
||||
|
@ -41,7 +39,6 @@ import { errorHandler } from "../../../lib/utils/shared/shared.utils";
|
|||
import { Project } from "../project";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { SessionService } from "../../shared/session.service";
|
||||
import { RepositoryDefaultService } from "./repository.service";
|
||||
import { GridViewComponent } from "./gridview/grid-view.component";
|
||||
import { Repository as NewRepository } from "../../../../ng-swagger-gen/models/repository";
|
||||
import { StrictHttpResponse as __StrictHttpResponse } from '../../../../ng-swagger-gen/strict-http-response';
|
||||
|
@ -93,10 +90,8 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit, OnDestroy
|
|||
constructor(@Inject(SERVICE_CONFIG) private configInfo: IServiceConfig,
|
||||
private errorHandlerService: ErrorHandler,
|
||||
private translateService: TranslateService,
|
||||
private repositoryService: RepositoryDefaultService,
|
||||
private newRepoService: NewRepositoryService,
|
||||
private systemInfoService: SystemInfoService,
|
||||
private tagService: TagService,
|
||||
private operationService: OperationService,
|
||||
private userPermissionService: UserPermissionService,
|
||||
private route: ActivatedRoute,
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { RepositoryService, RepositoryDefaultService } from './repository.service';
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config";
|
||||
import { SharedModule } from "../../../lib/utils/shared/shared.module";
|
||||
import { CURRENT_BASE_HREF } from "../../../lib/utils/utils";
|
||||
|
||||
|
||||
describe('RepositoryService', () => {
|
||||
const mockConfig: IServiceConfig = {
|
||||
repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing"
|
||||
};
|
||||
|
||||
let config: IServiceConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SharedModule
|
||||
],
|
||||
providers: [
|
||||
RepositoryDefaultService,
|
||||
{
|
||||
provide: RepositoryService,
|
||||
useClass: RepositoryDefaultService
|
||||
}, {
|
||||
provide: SERVICE_CONFIG,
|
||||
useValue: mockConfig
|
||||
}]
|
||||
});
|
||||
|
||||
config = TestBed.get(SERVICE_CONFIG);
|
||||
});
|
||||
|
||||
it('should be initialized', inject([RepositoryDefaultService], (service: RepositoryService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should inject the right config', () => {
|
||||
expect(config).toBeTruthy();
|
||||
expect(config.repositoryBaseEndpoint).toEqual(CURRENT_BASE_HREF + "/repositories/testing");
|
||||
});
|
||||
|
||||
});
|
|
@ -1,148 +0,0 @@
|
|||
import { Injectable, Inject } from '@angular/core';
|
||||
import { HttpClient, HttpResponse } from '@angular/common/http';
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import { Observable, throwError as observableThrowError } from "rxjs";
|
||||
import { Repository, RepositoryItem, RequestQueryParams } from "../../../lib/services";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../../../lib/entities/service.config";
|
||||
import {
|
||||
buildHttpRequestOptionsWithObserveResponse,
|
||||
CURRENT_BASE_HREF,
|
||||
HTTP_JSON_OPTIONS
|
||||
} from "../../../lib/utils/utils";
|
||||
|
||||
/**
|
||||
* Define service methods for handling the repository related things.
|
||||
* Loose couple with project module.
|
||||
*
|
||||
**
|
||||
* @abstract
|
||||
* class RepositoryService
|
||||
*/
|
||||
export abstract class RepositoryService {
|
||||
/**
|
||||
* List all the repositories in the specified project.
|
||||
* Specify the 'repositoryName' to only return the repositories which match the name pattern.
|
||||
* If pagination needed, set the following parameters in queryParams:
|
||||
* 'page': current page,
|
||||
* 'page_size': page size.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {(number | string)} projectId
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {RequestQueryParams} [queryParams]
|
||||
* returns {(Observable<Repository>)}
|
||||
*
|
||||
* @memberOf RepositoryService
|
||||
*/
|
||||
abstract getRepositories(projectId: number | string, repositoryName?: string, queryParams?: RequestQueryParams):
|
||||
Observable<Repository>;
|
||||
|
||||
/**
|
||||
* Update description of specified repository.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {number | string} projectId
|
||||
* ** deprecated param {string} repoName
|
||||
* returns {(Observable<Repository>)}
|
||||
*
|
||||
* @memberOf RepositoryService
|
||||
*/
|
||||
abstract updateRepositoryDescription(repoName: string, description: string): Observable<any>;
|
||||
|
||||
/**
|
||||
* DELETE the specified repository.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* returns {(Observable<any>)}
|
||||
*
|
||||
* @memberOf RepositoryService
|
||||
*/
|
||||
abstract deleteRepository(repositoryName: string): Observable<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement default service for repository.
|
||||
*
|
||||
**
|
||||
* class RepositoryDefaultService
|
||||
* extends {RepositoryService}
|
||||
*/
|
||||
@Injectable()
|
||||
export class RepositoryDefaultService extends RepositoryService {
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
@Inject(SERVICE_CONFIG) private config: IServiceConfig
|
||||
) {
|
||||
super();
|
||||
}
|
||||
public getRepositories(projectId: number | string, repositoryName?: string, queryParams?: RequestQueryParams):
|
||||
Observable<Repository> {
|
||||
if (!projectId) {
|
||||
return observableThrowError('Bad argument');
|
||||
}
|
||||
|
||||
if (!queryParams) {
|
||||
queryParams = new RequestQueryParams();
|
||||
}
|
||||
|
||||
queryParams = queryParams.set('project_id', '' + projectId);
|
||||
if (repositoryName && repositoryName.trim() !== '') {
|
||||
queryParams = queryParams.set('q', repositoryName);
|
||||
}
|
||||
let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories';
|
||||
return this.http.get<HttpResponse<RepositoryItem[]>>(url, buildHttpRequestOptionsWithObserveResponse(queryParams))
|
||||
.pipe(map(response => {
|
||||
let result: Repository = {
|
||||
metadata: { xTotalCount: 0 },
|
||||
data: []
|
||||
};
|
||||
|
||||
if (response && response.headers) {
|
||||
let xHeader: string = response.headers.get('X-Total-Count');
|
||||
if (xHeader) {
|
||||
result.metadata.xTotalCount = parseInt(xHeader, 0);
|
||||
}
|
||||
}
|
||||
|
||||
result.data = response.body as RepositoryItem[];
|
||||
|
||||
if (result.metadata.xTotalCount === 0) {
|
||||
if (result.data && result.data.length > 0) {
|
||||
result.metadata.xTotalCount = result.data.length;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
})
|
||||
, catchError(error => {
|
||||
return observableThrowError(error);
|
||||
}));
|
||||
}
|
||||
|
||||
public updateRepositoryDescription(repositoryName: string, description: string,
|
||||
queryParams?: RequestQueryParams): Observable<any> {
|
||||
|
||||
if (!queryParams) {
|
||||
queryParams = new RequestQueryParams();
|
||||
}
|
||||
|
||||
let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories';
|
||||
let url = `${baseUrl}/${repositoryName}`;
|
||||
return this.http.put(url, { 'description': description }, HTTP_JSON_OPTIONS)
|
||||
.pipe(map(response => response)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
public deleteRepository(repositoryName: string): Observable<any> {
|
||||
if (!repositoryName) {
|
||||
return observableThrowError('Bad argument');
|
||||
}
|
||||
let url: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories';
|
||||
url = `${url}/${repositoryName}`;
|
||||
|
||||
return this.http.delete(url, HTTP_JSON_OPTIONS)
|
||||
.pipe(map(response => response)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
}
|
|
@ -15,7 +15,9 @@ import {filter} from 'rxjs/operators';
|
|||
// limitations under the License.
|
||||
import { Component, Input, Output, OnDestroy, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef, OnInit } from '@angular/core';
|
||||
import { Router, NavigationEnd } from '@angular/router';
|
||||
import { Repository, State } from '../../../lib/services/interface';
|
||||
import { State } from '../../../lib/services/interface';
|
||||
import { Repository } from '../../../../ng-swagger-gen/models/repository';
|
||||
|
||||
import { SearchTriggerService } from '../../base/global-search/search-trigger.service';
|
||||
import {Subscription} from "rxjs";
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
|
||||
import { TopRepoService } from './top-repository.service';
|
||||
import { Repository } from "../../../lib/services";
|
||||
import { Repository } from "../../../../ng-swagger-gen/models/repository";
|
||||
import { ListMode } from "../../../lib/entities/shared.const";
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import { Injectable } from '@angular/core';
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import { Observable, throwError as observableThrowError } from "rxjs";
|
||||
import { Repository } from "../../../lib/services";
|
||||
import { Repository } from "../../../../ng-swagger-gen/models/repository";
|
||||
import { CURRENT_BASE_HREF, HTTP_GET_OPTIONS } from "../../../lib/utils/utils";
|
||||
|
||||
export const topRepoEndpoint = CURRENT_BASE_HREF + "/repositories/top";
|
||||
|
|
|
@ -12,8 +12,6 @@ import {
|
|||
ReplicationDefaultService,
|
||||
QuotaService,
|
||||
QuotaDefaultService,
|
||||
TagService,
|
||||
TagDefaultService,
|
||||
ScanningResultService,
|
||||
ScanningResultDefaultService,
|
||||
ConfigurationService,
|
||||
|
@ -24,8 +22,6 @@ import {
|
|||
ProjectDefaultService,
|
||||
LabelService,
|
||||
LabelDefaultService,
|
||||
RetagService,
|
||||
RetagDefaultService,
|
||||
UserPermissionService,
|
||||
UserPermissionDefaultService,
|
||||
} from './services';
|
||||
|
@ -155,12 +151,6 @@ export interface HarborModuleConfig {
|
|||
// Service implementation for repository
|
||||
repositoryService?: Provider;
|
||||
|
||||
// Service implementation for tag
|
||||
tagService?: Provider;
|
||||
|
||||
// Service implementation for retag
|
||||
retagService?: Provider;
|
||||
|
||||
// Service implementation for vulnerability scanning
|
||||
scanningService?: Provider;
|
||||
|
||||
|
@ -279,8 +269,6 @@ export class HarborLibraryModule {
|
|||
config.endpointService || { provide: EndpointService, useClass: EndpointDefaultService },
|
||||
config.replicationService || { provide: ReplicationService, useClass: ReplicationDefaultService },
|
||||
config.QuotaService || { provide: QuotaService, useClass: QuotaDefaultService },
|
||||
config.tagService || { provide: TagService, useClass: TagDefaultService },
|
||||
config.retagService || { provide: RetagService, useClass: RetagDefaultService },
|
||||
config.scanningService || { provide: ScanningResultService, useClass: ScanningResultDefaultService },
|
||||
config.configService || { provide: ConfigurationService, useClass: ConfigurationDefaultService },
|
||||
config.jobLogService || { provide: JobLogService, useClass: JobLogDefaultService },
|
||||
|
@ -317,8 +305,6 @@ export class HarborLibraryModule {
|
|||
config.endpointService || { provide: EndpointService, useClass: EndpointDefaultService },
|
||||
config.replicationService || { provide: ReplicationService, useClass: ReplicationDefaultService },
|
||||
config.QuotaService || { provide: QuotaService, useClass: QuotaDefaultService },
|
||||
config.tagService || { provide: TagService, useClass: TagDefaultService },
|
||||
config.retagService || { provide: RetagService, useClass: RetagDefaultService },
|
||||
config.scanningService || { provide: ScanningResultService, useClass: ScanningResultDefaultService },
|
||||
config.configService || { provide: ConfigurationService, useClass: ConfigurationDefaultService },
|
||||
config.jobLogService || { provide: JobLogService, useClass: JobLogDefaultService },
|
||||
|
|
|
@ -3,14 +3,12 @@ export * from "./system-info.service";
|
|||
export * from "./access-log.service";
|
||||
export * from "./endpoint.service";
|
||||
export * from "./replication.service";
|
||||
export * from "./tag.service";
|
||||
export * from "./RequestQueryParams";
|
||||
export * from "./scanning.service";
|
||||
export * from "./configuration.service";
|
||||
export * from "./job-log.service";
|
||||
export * from "./project.service";
|
||||
export * from "./label.service";
|
||||
export * from "./retag.service";
|
||||
export * from "./permission.service";
|
||||
export * from "./permission-static";
|
||||
export * from "./quota.service";
|
||||
|
|
|
@ -16,53 +16,6 @@ export interface Base {
|
|||
update_time?: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for Repository Info
|
||||
*
|
||||
**
|
||||
* interface Repository
|
||||
* extends {Base}
|
||||
*/
|
||||
export interface RepositoryItem extends Base {
|
||||
[key: string]: any | any[];
|
||||
name: string;
|
||||
tags_count: number;
|
||||
owner_id?: number;
|
||||
project_id?: number;
|
||||
description?: string;
|
||||
star_count?: number;
|
||||
pull_count?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for repository
|
||||
*
|
||||
**
|
||||
* interface Repository
|
||||
*/
|
||||
export interface Repository {
|
||||
metadata?: Metadata;
|
||||
data: RepositoryItem[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for the tag of repository
|
||||
*
|
||||
**
|
||||
* interface Tag
|
||||
* extends {Base}
|
||||
*/
|
||||
|
||||
export interface Tag extends Base {
|
||||
artifact_id: number;
|
||||
name: string;
|
||||
push_time?: string;
|
||||
pull_time?: string;
|
||||
immutable?: boolean;
|
||||
repository_id?: number;
|
||||
upload_time?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for registry endpoints.
|
||||
*
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
import { Observable } from "rxjs";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable, Inject } from "@angular/core";
|
||||
import { RetagRequest } from "./interface";
|
||||
import { CURRENT_BASE_HREF, HTTP_JSON_OPTIONS } from "../utils/utils";
|
||||
import { catchError } from "rxjs/operators";
|
||||
import { throwError as observableThrowError } from "rxjs/index";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../entities/service.config";
|
||||
|
||||
/**
|
||||
* Define the service methods to perform images retag.
|
||||
*
|
||||
**
|
||||
* @abstract
|
||||
* class RetagService
|
||||
*/
|
||||
export abstract class RetagService {
|
||||
/**
|
||||
* Retag an image.
|
||||
*
|
||||
* @abstract
|
||||
* param {RetagRequest} request
|
||||
* returns {Observable<any>}
|
||||
*
|
||||
* @memberOf RetagService
|
||||
*/
|
||||
abstract retag(request: RetagRequest): Observable<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement default service for retag.
|
||||
*
|
||||
**
|
||||
* class RetagDefaultService
|
||||
* extends {RetagService}
|
||||
*/
|
||||
@Injectable()
|
||||
export class RetagDefaultService extends RetagService {
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
@Inject(SERVICE_CONFIG) private config: IServiceConfig
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
retag(request: RetagRequest): Observable<any> {
|
||||
let baseUrl: string = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : CURRENT_BASE_HREF + '/repositories';
|
||||
return this.http
|
||||
.post(`${baseUrl}/${request.targetProject}/${request.targetRepo}/tags`,
|
||||
{
|
||||
"tag": request.targetTag,
|
||||
"src_image": request.srcImage,
|
||||
"override": request.override
|
||||
},
|
||||
HTTP_JSON_OPTIONS)
|
||||
.pipe(catchError(error => observableThrowError(error)));
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { SharedModule } from '../utils/shared/shared.module';
|
||||
import { SERVICE_CONFIG, IServiceConfig } from '../entities/service.config';
|
||||
import { TagService, TagDefaultService } from './tag.service';
|
||||
import { CURRENT_BASE_HREF } from "../utils/utils";
|
||||
|
||||
|
||||
describe('TagService', () => {
|
||||
// let mockTags: Tag[] = [
|
||||
// {
|
||||
// "digest": "sha256:e5c82328a509aeb7c18c1d7fb36633dc638fcf433f651bdcda59c1cc04d3ee55",
|
||||
// "name": "1.11.5",
|
||||
// "size": "2049",
|
||||
// "architecture": "amd64",
|
||||
// "os": "linux",
|
||||
// "docker_version": "1.12.3",
|
||||
// "author": "NGINX Docker Maintainers \"docker-maint@nginx.com\"",
|
||||
// "created": new Date("2016-11-08T22:41:15.912313785Z"),
|
||||
// "signature": null,
|
||||
// 'labels': []
|
||||
// }
|
||||
// ];
|
||||
|
||||
const mockConfig: IServiceConfig = {
|
||||
repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing"
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SharedModule
|
||||
],
|
||||
providers: [
|
||||
TagDefaultService,
|
||||
{
|
||||
provide: TagService,
|
||||
useClass: TagDefaultService
|
||||
}, {
|
||||
provide: SERVICE_CONFIG,
|
||||
useValue: mockConfig
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be initialized', inject([TagDefaultService], (service: TagService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
});
|
|
@ -1,130 +0,0 @@
|
|||
import { Injectable, Inject } from "@angular/core";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
|
||||
import { SERVICE_CONFIG, IServiceConfig } from "../entities/service.config";
|
||||
import {
|
||||
buildHttpRequestOptions,
|
||||
HTTP_JSON_OPTIONS,
|
||||
HTTP_GET_OPTIONS, CURRENT_BASE_HREF
|
||||
} from "../utils/utils";
|
||||
import { RequestQueryParams } from "./RequestQueryParams";
|
||||
import { Tag, Manifest } from "./interface";
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import { Observable, throwError as observableThrowError } from "rxjs";
|
||||
|
||||
/**
|
||||
* For getting tag signatures.
|
||||
* This is temporary, will be removed in future.
|
||||
*
|
||||
**
|
||||
* class VerifiedSignature
|
||||
*/
|
||||
export class VerifiedSignature {
|
||||
tag: string;
|
||||
hashes: {
|
||||
sha256: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the service methods to handle the repository tag related things.
|
||||
*
|
||||
**
|
||||
* @abstract
|
||||
* class TagService
|
||||
*/
|
||||
export abstract class TagService {
|
||||
|
||||
/**
|
||||
* Get all the tags under the specified repository.
|
||||
* NOTES: If the Notary is enabled, the signatures should be included in the returned data.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {RequestQueryParams} [queryParams]
|
||||
* returns {(Observable<Tag[]>)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
// to delete
|
||||
abstract newTag(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string,
|
||||
tagName: {name: string}
|
||||
): Observable<any>;
|
||||
|
||||
/**
|
||||
* Delete the specified tag.
|
||||
*
|
||||
* @abstract
|
||||
* ** deprecated param {string} repositoryName
|
||||
* ** deprecated param {string} tag
|
||||
* returns {(Observable<any> | any)}
|
||||
*
|
||||
* @memberOf TagService
|
||||
*/
|
||||
abstract deleteTag(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string,
|
||||
tagName: string
|
||||
): Observable<any>;
|
||||
}
|
||||
/**
|
||||
* Implement default service for tag.
|
||||
*
|
||||
**
|
||||
* class TagDefaultService
|
||||
* extends {TagService}
|
||||
*/
|
||||
@Injectable()
|
||||
export class TagDefaultService extends TagService {
|
||||
_baseUrl: string;
|
||||
_labelUrl: string;
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
@Inject(SERVICE_CONFIG) private config: IServiceConfig
|
||||
) {
|
||||
super();
|
||||
this._baseUrl = this.config.repositoryBaseEndpoint
|
||||
? this.config.repositoryBaseEndpoint
|
||||
: CURRENT_BASE_HREF + "/repositories";
|
||||
this._labelUrl = this.config.labelEndpoint
|
||||
? this.config.labelEndpoint
|
||||
: CURRENT_BASE_HREF + "/labels";
|
||||
}
|
||||
|
||||
public newTag(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string,
|
||||
tagName: {name: string}
|
||||
): Observable<any> {
|
||||
if (!projectName || !repositoryName || !digest || !tagName) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags`;
|
||||
return this.http
|
||||
.post(url, tagName, HTTP_JSON_OPTIONS)
|
||||
.pipe(map(response => response)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
|
||||
public deleteTag(
|
||||
projectName: string,
|
||||
repositoryName: string,
|
||||
digest: string,
|
||||
tagName: string
|
||||
): Observable<any> {
|
||||
if (!projectName || !repositoryName || !digest || !tagName) {
|
||||
return observableThrowError("Bad argument");
|
||||
}
|
||||
|
||||
let url: string = `${ CURRENT_BASE_HREF }/projects/${projectName}/repositories/${repositoryName}/artifacts/${digest}/tags/${tagName}`;
|
||||
return this.http
|
||||
.delete(url, HTTP_JSON_OPTIONS)
|
||||
.pipe(map(response => response)
|
||||
, catchError(error => observableThrowError(error)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user