mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 14:47:38 +01:00
change adapterInfo from by hardcode to by getting
from backend API Signed-off-by: sshijun <sshijun@vmware.com>
This commit is contained in:
parent
6bc50090d2
commit
4a97cf40c6
@ -1,7 +1,7 @@
|
||||
<clr-modal [(clrModalOpen)]="createEditDestinationOpened" [clrModalStaticBackdrop]="staticBackdrop" [clrModalClosable]="closable">
|
||||
<h3 class="modal-title">{{modalTitle}}</h3>
|
||||
<hbr-inline-alert class="modal-title" (confirmEvt)="confirmCancel($event)"></hbr-inline-alert>
|
||||
<div class="modal-body">
|
||||
<div class="modal-body overflow-visible">
|
||||
<div class="alert alert-warning" *ngIf="!editable">
|
||||
<div class="alert-item static">
|
||||
<span class="alert-text">
|
||||
@ -35,19 +35,24 @@
|
||||
<div class="clr-form-control">
|
||||
<label for="destination_url" class="required clr-control-label">{{ 'DESTINATION.URL' | translate }}</label>
|
||||
<div class="clr-control-container" [class.clr-error]="targetEndpoint?.errors && targetEndpoint.errors.required && (targetEndpoint.dirty || targetEndpoint.touched)">
|
||||
<div class="clr-input-wrapper" *ngIf="!endpointList.length">
|
||||
<input class="clr-input" type="text" id="destination_url" [disabled]="testOngoing || urlDisabled" [readonly]="!editable"
|
||||
<div class="clr-input-wrapper position-relative">
|
||||
<clr-icon *ngIf="!(!showEndpointList
|
||||
&& targetEndpoint?.errors
|
||||
&& targetEndpoint.errors.required
|
||||
&& (targetEndpoint.dirty || targetEndpoint.touched))
|
||||
&& endpointList?.length" class="down" shape="caret" dir="down"
|
||||
(click)="showEndpointList=true"></clr-icon>
|
||||
<input autocomplete="off" (blur)="blur()" (focus)="showEndpointList=true" class="clr-input endpoint-input" type="text" id="destination_url" [disabled]="testOngoing || urlDisabled" [readonly]="!editable"
|
||||
[(ngModel)]="target.url" size="30" name="endpointUrl" #targetEndpoint="ngModel" required placeholder="http(s)://192.168.1.1">
|
||||
<clr-icon class="clr-validate-icon" shape="exclamation-circle"></clr-icon>
|
||||
<div class="selectBox" (mouseleave)="endpointOnHover=false" (mouseover)="endpointOnHover=true" *ngIf="endpointList?.length && showEndpointList">
|
||||
<ul>
|
||||
<li *ngFor="let endpoint of endpointList" (click)="selectedEndpoint(endpoint.value)">{{endpoint.key}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<clr-icon *ngIf="!showEndpointList && targetEndpoint?.errors && targetEndpoint.errors.required && (targetEndpoint.dirty || targetEndpoint.touched)"
|
||||
class="clr-validate-icon" shape="exclamation-circle"></clr-icon>
|
||||
</div>
|
||||
<div class="clr-select-wrapper" *ngIf="endpointList.length">
|
||||
<select id="destination_url" class="clr-select" *ngIf="endpointList.length" [(ngModel)]="target.url"
|
||||
name="endpointUrl" #targetEndpoint="ngModel">
|
||||
<option class="display-none" value=""></option>
|
||||
<option *ngFor="let endpoint of endpointList" value="{{endpoint.value}}">{{endpoint.key}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<clr-control-error *ngIf="targetEndpoint?.errors && targetEndpoint.errors.required && (targetEndpoint.dirty || targetEndpoint.touched)">
|
||||
<clr-control-error *ngIf="!showEndpointList && targetEndpoint?.errors && targetEndpoint.errors.required && (targetEndpoint.dirty || targetEndpoint.touched)">
|
||||
{{ 'DESTINATION.URL_IS_REQUIRED' | translate }}
|
||||
</clr-control-error>
|
||||
</div>
|
||||
@ -55,7 +60,7 @@
|
||||
<!-- access_key -->
|
||||
<clr-input-container>
|
||||
<label>{{ 'DESTINATION.ACCESS_ID' | translate }}</label>
|
||||
<input clrInput type="text" placeholder="Access ID" id="destination_access_key" [disabled]="testOngoing" [readonly]="target.type ==='google-gcr' || !editable"
|
||||
<input autocomplete="off" clrInput type="text" placeholder="Access ID" id="destination_access_key" [disabled]="testOngoing" [readonly]="target.type ==='google-gcr' || !editable"
|
||||
[(ngModel)]="target.credential.access_key" size="30" name="access_key" #access_key="ngModel">
|
||||
</clr-input-container>
|
||||
<!-- access_secret -->
|
||||
@ -63,11 +68,11 @@
|
||||
<label for="destination_password" class="clr-control-label">{{ 'DESTINATION.ACCESS_SECRET' | translate }}</label>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-textarea-wrapper">
|
||||
<input class="clr-input" *ngIf="target.type !=='google-gcr';else gcr_secret" type="password" placeholder="Access Secret"
|
||||
<input autocomplete="off" class="clr-input" *ngIf="isNormalCredential();else gcr_secret" type="password" placeholder="Access Secret"
|
||||
id="destination_password" [disabled]="testOngoing" [readonly]="!editable" [(ngModel)]="target.credential.access_secret"
|
||||
size="30" name="access_secret" #access_secret="ngModel">
|
||||
<ng-template #gcr_secret>
|
||||
<textarea type="text" row="3" placeholder="Json Secret" class="clr-textarea" id="destination_password" [disabled]="testOngoing"
|
||||
<textarea autocomplete="off" type="text" row="3" placeholder="Json Secret" class="clr-textarea" id="destination_password" [disabled]="testOngoing"
|
||||
[readonly]="!editable" [(ngModel)]="target.credential.access_secret" name="access_secret" #access_secret="ngModel"></textarea>
|
||||
</ng-template>
|
||||
</div>
|
||||
@ -101,4 +106,4 @@
|
||||
<button type="submit" class="btn btn-primary" (click)="onSubmit()" [disabled]="!isValid">{{ 'BUTTON.OK' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</clr-modal>
|
||||
</clr-modal>
|
||||
|
@ -18,3 +18,51 @@
|
||||
.display-none {
|
||||
display: none
|
||||
}
|
||||
.selectBox{
|
||||
position: absolute;
|
||||
width: 173px;
|
||||
height: auto;
|
||||
border: 1px solid #ccc;
|
||||
background-color: white;
|
||||
border-right-width: 2px;
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 5px 10px rgba(0,0,0,.2);
|
||||
z-index: 100;
|
||||
ul {
|
||||
overflow-y: auto;
|
||||
max-height: 260px;
|
||||
li {
|
||||
list-style: none;
|
||||
padding: 0 18px;
|
||||
height:20px;
|
||||
line-height: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
li:hover {
|
||||
color: #262626;
|
||||
background-image: linear-gradient(180deg,#f5f5f5 0,#e8e8e8);
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
}
|
||||
}
|
||||
.position-relative {
|
||||
position: relative;
|
||||
}
|
||||
.overflow-visible {
|
||||
overflow: visible;
|
||||
}
|
||||
.down {
|
||||
position: absolute;
|
||||
top: .2916665rem;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
color: rgb(164,164,164);
|
||||
cursor: pointer;
|
||||
}
|
||||
.endpoint-input {
|
||||
padding-right: 17px;
|
||||
width: 256px;
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ import {
|
||||
} from "../service/endpoint.service";
|
||||
import { IServiceConfig, SERVICE_CONFIG } from "../service.config";
|
||||
import { of } from "rxjs";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
||||
|
||||
describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
let mockData: Endpoint = {
|
||||
id: 1,
|
||||
@ -33,7 +36,218 @@ describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
type: "Harbor",
|
||||
url: "https://10.117.4.151"
|
||||
};
|
||||
|
||||
let adapterInfoMockData = {
|
||||
"ali-acr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "cn-hangzhou",
|
||||
"value": "https://registry.cn-hangzhou.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-shanghai",
|
||||
"value": "https://registry.cn-shanghai.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-qingdao",
|
||||
"value": "https://registry.cn-qingdao.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-beijing",
|
||||
"value": "https://registry.cn-beijing.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-zhangjiakou",
|
||||
"value": "https://registry.cn-zhangjiakou.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-huhehaote",
|
||||
"value": "https://registry.cn-huhehaote.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-shenzhen",
|
||||
"value": "https://registry.cn-shenzhen.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-chengdu",
|
||||
"value": "https://registry.cn-chengdu.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-hongkong",
|
||||
"value": "https://registry.cn-hongkong.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-1",
|
||||
"value": "https://registry.ap-southeast-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-2",
|
||||
"value": "https://registry.ap-southeast-2.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-3",
|
||||
"value": "https://registry.ap-southeast-3.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-5",
|
||||
"value": "https://registry.ap-southeast-5.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-northeast-1",
|
||||
"value": "https://registry.ap-northeast-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-south-1",
|
||||
"value": "https://registry.ap-south-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-central-1",
|
||||
"value": "https://registry.eu-central-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-1",
|
||||
"value": "https://registry.eu-west-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-1",
|
||||
"value": "https://registry.us-west-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-1",
|
||||
"value": "https://registry.us-east-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "me-east-1",
|
||||
"value": "https://registry.me-east-1.aliyuncs.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"aws-ecr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "ap-northeast-1",
|
||||
"value": "https://api.ecr.ap-northeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-1",
|
||||
"value": "https://api.ecr.us-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-2",
|
||||
"value": "https://api.ecr.us-east-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-1",
|
||||
"value": "https://api.ecr.us-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-2",
|
||||
"value": "https://api.ecr.us-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-east-1",
|
||||
"value": "https://api.ecr.ap-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-south-1",
|
||||
"value": "https://api.ecr.ap-south-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-northeast-2",
|
||||
"value": "https://api.ecr.ap-northeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-1",
|
||||
"value": "https://api.ecr.ap-southeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-2",
|
||||
"value": "https://api.ecr.ap-southeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ca-central-1",
|
||||
"value": "https://api.ecr.ca-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-central-1",
|
||||
"value": "https://api.ecr.eu-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-1",
|
||||
"value": "https://api.ecr.eu-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-2",
|
||||
"value": "https://api.ecr.eu-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-3",
|
||||
"value": "https://api.ecr.eu-west-3.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-north-1",
|
||||
"value": "https://api.ecr.eu-north-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "sa-east-1",
|
||||
"value": "https://api.ecr.sa-east-1.amazonaws.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"docker-hub": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeFix",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "hub.docker.com",
|
||||
"value": "https://hub.docker.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"google-gcr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "gcr.io",
|
||||
"value": "https://gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "us.gcr.io",
|
||||
"value": "https://us.gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "eu.gcr.io",
|
||||
"value": "https://eu.gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "asia.gcr.io",
|
||||
"value": "https://asia.gcr.io"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": {
|
||||
"access_key_type": "AccessKeyTypeFix",
|
||||
"access_key_data": "_json_key",
|
||||
"access_secret_type": "AccessSecretTypeFile",
|
||||
"access_secret_data": "No Change"
|
||||
}
|
||||
}
|
||||
};
|
||||
let fakedHttp = {
|
||||
get() {
|
||||
return of(adapterInfoMockData);
|
||||
}
|
||||
};
|
||||
let mockAdapters = ['harbor', 'docker hub'];
|
||||
|
||||
let comp: CreateEditEndpointComponent;
|
||||
@ -44,10 +258,10 @@ describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
};
|
||||
|
||||
let endpointService: EndpointService;
|
||||
let http: HttpClient;
|
||||
|
||||
let spy: jasmine.Spy;
|
||||
let spyAdapter: jasmine.Spy;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [SharedModule, NoopAnimationsModule],
|
||||
@ -59,7 +273,8 @@ describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
providers: [
|
||||
ErrorHandler,
|
||||
{ provide: SERVICE_CONFIG, useValue: config },
|
||||
{ provide: EndpointService, useClass: EndpointDefaultService }
|
||||
{ provide: EndpointService, useClass: EndpointDefaultService },
|
||||
{ provide: HttpClient, useValue: fakedHttp },
|
||||
]
|
||||
});
|
||||
}));
|
||||
@ -67,12 +282,11 @@ describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateEditEndpointComponent);
|
||||
comp = fixture.componentInstance;
|
||||
|
||||
endpointService = fixture.debugElement.injector.get(EndpointService);
|
||||
http = fixture.debugElement.injector.get(HttpClient);
|
||||
spyAdapter = spyOn(endpointService, "getAdapters").and.returnValue(
|
||||
of(mockAdapters)
|
||||
);
|
||||
|
||||
spy = spyOn(endpointService, "getEndpoint").and.returnValue(
|
||||
of(mockData)
|
||||
);
|
||||
@ -94,6 +308,13 @@ describe("CreateEditEndpointComponent (inline template)", () => {
|
||||
expect(spy.calls.any()).toBeTruthy();
|
||||
});
|
||||
}));
|
||||
it("should get adapterInfo", async(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(comp.adapterInfo).toBeTruthy();
|
||||
});
|
||||
}));
|
||||
|
||||
it("should get endpoint and open modal", async(() => {
|
||||
fixture.detectChanges();
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
OnInit
|
||||
} from "@angular/core";
|
||||
import { NgForm } from "@angular/forms";
|
||||
import { Subscription } from "rxjs";
|
||||
import { Subscription, throwError as observableThrowError } from "rxjs";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
|
||||
import { EndpointService } from "../service/endpoint.service";
|
||||
@ -30,18 +30,12 @@ import { ErrorHandler } from "../error-handler/index";
|
||||
import { InlineAlertComponent } from "../inline-alert/inline-alert.component";
|
||||
import { Endpoint, PingEndpoint } from "../service/interface";
|
||||
import { clone, compareValue, isEmptyObject } from "../utils";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { catchError } from "rxjs/operators";
|
||||
|
||||
const FAKE_PASSWORD = "rjGcfuRu";
|
||||
const FAKE_JSON_KEY = "No Change";
|
||||
const DOCKERHUB_URL = "https://hub.docker.com";
|
||||
const HELM_HUB_URL = "https://hub.helm.sh";
|
||||
const HELM_HUB_ACCESS_KEY = "_json_key";
|
||||
const REGISTRY_NAME_LIST = {
|
||||
DOCKER_HUB: "docker-hub",
|
||||
HELM_HUB: "helm-hub",
|
||||
GOOGLE_GCR: "google-gcr",
|
||||
AWS_ECR: "aws-ecr"
|
||||
};
|
||||
const METADATA_URL = "/api/replication/adapterinfos";
|
||||
@Component({
|
||||
selector: "hbr-create-edit-endpoint",
|
||||
templateUrl: "./create-edit-endpoint.component.html",
|
||||
@ -58,7 +52,7 @@ export class CreateEditEndpointComponent
|
||||
closable: boolean = false;
|
||||
editable: boolean;
|
||||
adapterList: string[];
|
||||
endpointList: object[] = [];
|
||||
endpointList: any[] = [];
|
||||
target: Endpoint = this.initEndpoint();
|
||||
selectedType: string;
|
||||
initVal: Endpoint;
|
||||
@ -76,12 +70,15 @@ export class CreateEditEndpointComponent
|
||||
timerHandler: any;
|
||||
valueChangesSub: Subscription;
|
||||
formValues: { [key: string]: string } | any;
|
||||
|
||||
adapterInfo: object;
|
||||
showEndpointList: boolean = false;
|
||||
endpointOnHover: boolean = false;
|
||||
constructor(
|
||||
private endpointService: EndpointService,
|
||||
private errorHandler: ErrorHandler,
|
||||
private translateService: TranslateService,
|
||||
private ref: ChangeDetectorRef
|
||||
private ref: ChangeDetectorRef,
|
||||
private http: HttpClient
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
@ -93,8 +90,34 @@ export class CreateEditEndpointComponent
|
||||
this.errorHandler.error(error);
|
||||
}
|
||||
);
|
||||
this.getAdapterInfo();
|
||||
}
|
||||
|
||||
getAdapterInfo() {
|
||||
this.http.get(METADATA_URL)
|
||||
.pipe(catchError(error => observableThrowError(error)))
|
||||
.subscribe(
|
||||
response => {
|
||||
this.adapterInfo = response;
|
||||
}, error => {
|
||||
this.errorHandler.error(error);
|
||||
});
|
||||
}
|
||||
isNormalCredential(): boolean {
|
||||
return !(this.adapterInfo && this.target && this.target.type
|
||||
&& this.adapterInfo[this.target.type]
|
||||
&& this.adapterInfo[this.target.type].credential_pattern);
|
||||
}
|
||||
selectedEndpoint(endpoint: string) {
|
||||
this.targetForm.controls.endpointUrl.reset(endpoint);
|
||||
this.showEndpointList = false;
|
||||
this.endpointOnHover = false;
|
||||
}
|
||||
blur() {
|
||||
if (!this.endpointOnHover) {
|
||||
this.showEndpointList = false;
|
||||
}
|
||||
}
|
||||
public get isValid(): boolean {
|
||||
return (
|
||||
!this.testOngoing &&
|
||||
@ -195,7 +218,7 @@ export class CreateEditEndpointComponent
|
||||
this.endpointService.getEndpoint(targetId).subscribe(
|
||||
target => {
|
||||
this.target = target;
|
||||
this.urlDisabled = this.target.type === 'docker-hub' ? true : false;
|
||||
this.urlDisabled = this.target.type === 'docker-hub';
|
||||
// Keep data cache
|
||||
this.initVal = clone(target);
|
||||
this.initVal.credential.access_secret = this.target.type === 'google-gcr' ? FAKE_JSON_KEY : FAKE_PASSWORD;
|
||||
@ -221,112 +244,21 @@ export class CreateEditEndpointComponent
|
||||
}
|
||||
|
||||
adapterChange($event): void {
|
||||
this.targetForm.controls.endpointUrl.reset("");
|
||||
let selectValue = this.targetForm.controls.adapter.value;
|
||||
if (selectValue === REGISTRY_NAME_LIST.DOCKER_HUB) {
|
||||
this.urlDisabled = true;
|
||||
this.targetForm.controls.endpointUrl.setValue(DOCKERHUB_URL);
|
||||
} else if (selectValue === REGISTRY_NAME_LIST.HELM_HUB) {
|
||||
this.urlDisabled = true;
|
||||
this.targetForm.controls.endpointUrl.setValue(HELM_HUB_URL);
|
||||
} else {
|
||||
this.urlDisabled = false;
|
||||
this.targetForm.controls.endpointUrl.setValue("");
|
||||
}
|
||||
if (selectValue === REGISTRY_NAME_LIST.GOOGLE_GCR) {
|
||||
this.targetForm.controls.access_key.setValue(HELM_HUB_ACCESS_KEY);
|
||||
} else {
|
||||
this.urlDisabled = false;
|
||||
if (this.isNormalCredential()) {
|
||||
this.targetForm.controls.access_key.setValue("");
|
||||
} else {
|
||||
this.targetForm.controls.access_key.setValue(this.adapterInfo[this.target.type].credential_pattern.access_key_data);
|
||||
}
|
||||
if (selectValue === REGISTRY_NAME_LIST.GOOGLE_GCR) {
|
||||
this.endpointList = [
|
||||
{
|
||||
key: "gcr.io",
|
||||
value: "https://gcr.io"
|
||||
},
|
||||
{
|
||||
key: "us.gcr.io",
|
||||
value: "https://us.gcr.io"
|
||||
},
|
||||
{
|
||||
key: "eu.gcr.io",
|
||||
value: "https://eu.gcr.io"
|
||||
},
|
||||
{
|
||||
key: "asia.gcr.io",
|
||||
value: "https://asia.gcr.io"
|
||||
}
|
||||
];
|
||||
} else if (selectValue === REGISTRY_NAME_LIST.AWS_ECR) {
|
||||
this.endpointList = [
|
||||
{
|
||||
key: "ap-northeast-1",
|
||||
value: "https://api.ecr.ap-northeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "us-east-1",
|
||||
value: "https://api.ecr.us-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "us-east-2",
|
||||
value: "https://api.ecr.us-east-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "us-west-1",
|
||||
value: "https://api.ecr.us-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "us-west-2",
|
||||
value: "https://api.ecr.us-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ap-east-1",
|
||||
value: "https://api.ecr.ap-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ap-south-1",
|
||||
value: "https://api.ecr.ap-south-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ap-northeast-2",
|
||||
value: "https://api.ecr.ap-northeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ap-southeast-1",
|
||||
value: "https://api.ecr.ap-southeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ap-southeast-2",
|
||||
value: "https://api.ecr.ap-southeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "ca-central-1",
|
||||
value: "https://api.ecr.ca-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "eu-central-1",
|
||||
value: "https://api.ecr.eu-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "eu-west-1",
|
||||
value: "https://api.ecr.eu-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "eu-west-2",
|
||||
value: "https://api.ecr.eu-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "eu-west-3",
|
||||
value: "https://api.ecr.eu-west-3.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "eu-north-1",
|
||||
value: "https://api.ecr.eu-north-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
key: "sa-east-1",
|
||||
value: "https://api.ecr.sa-east-1.amazonaws.com"
|
||||
}
|
||||
];
|
||||
if (this.adapterInfo && this.adapterInfo[selectValue]
|
||||
&& this.adapterInfo[selectValue].endpoint_pattern
|
||||
&& this.adapterInfo[selectValue].endpoint_pattern.endpoints) {
|
||||
this.endpointList = this.adapterInfo[selectValue].endpoint_pattern.endpoints;
|
||||
if (this.endpointList.length === 1) {
|
||||
this.target.url = this.endpointList[0].value;
|
||||
}
|
||||
} else {
|
||||
this.endpointList = [];
|
||||
}
|
||||
|
@ -20,8 +20,222 @@ import { OperationService } from "../operation/operation.service";
|
||||
|
||||
import { click } from "../utils";
|
||||
import { of } from "rxjs";
|
||||
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
|
||||
describe("EndpointComponent (inline template)", () => {
|
||||
let adapterInfoMockData = {
|
||||
"ali-acr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "cn-hangzhou",
|
||||
"value": "https://registry.cn-hangzhou.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-shanghai",
|
||||
"value": "https://registry.cn-shanghai.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-qingdao",
|
||||
"value": "https://registry.cn-qingdao.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-beijing",
|
||||
"value": "https://registry.cn-beijing.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-zhangjiakou",
|
||||
"value": "https://registry.cn-zhangjiakou.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-huhehaote",
|
||||
"value": "https://registry.cn-huhehaote.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-shenzhen",
|
||||
"value": "https://registry.cn-shenzhen.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-chengdu",
|
||||
"value": "https://registry.cn-chengdu.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "cn-hongkong",
|
||||
"value": "https://registry.cn-hongkong.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-1",
|
||||
"value": "https://registry.ap-southeast-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-2",
|
||||
"value": "https://registry.ap-southeast-2.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-3",
|
||||
"value": "https://registry.ap-southeast-3.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-5",
|
||||
"value": "https://registry.ap-southeast-5.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-northeast-1",
|
||||
"value": "https://registry.ap-northeast-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-south-1",
|
||||
"value": "https://registry.ap-south-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-central-1",
|
||||
"value": "https://registry.eu-central-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-1",
|
||||
"value": "https://registry.eu-west-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-1",
|
||||
"value": "https://registry.us-west-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-1",
|
||||
"value": "https://registry.us-east-1.aliyuncs.com"
|
||||
},
|
||||
{
|
||||
"key": "me-east-1",
|
||||
"value": "https://registry.me-east-1.aliyuncs.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"aws-ecr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "ap-northeast-1",
|
||||
"value": "https://api.ecr.ap-northeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-1",
|
||||
"value": "https://api.ecr.us-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-east-2",
|
||||
"value": "https://api.ecr.us-east-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-1",
|
||||
"value": "https://api.ecr.us-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "us-west-2",
|
||||
"value": "https://api.ecr.us-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-east-1",
|
||||
"value": "https://api.ecr.ap-east-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-south-1",
|
||||
"value": "https://api.ecr.ap-south-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-northeast-2",
|
||||
"value": "https://api.ecr.ap-northeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-1",
|
||||
"value": "https://api.ecr.ap-southeast-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ap-southeast-2",
|
||||
"value": "https://api.ecr.ap-southeast-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "ca-central-1",
|
||||
"value": "https://api.ecr.ca-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-central-1",
|
||||
"value": "https://api.ecr.eu-central-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-1",
|
||||
"value": "https://api.ecr.eu-west-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-2",
|
||||
"value": "https://api.ecr.eu-west-2.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-west-3",
|
||||
"value": "https://api.ecr.eu-west-3.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "eu-north-1",
|
||||
"value": "https://api.ecr.eu-north-1.amazonaws.com"
|
||||
},
|
||||
{
|
||||
"key": "sa-east-1",
|
||||
"value": "https://api.ecr.sa-east-1.amazonaws.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"docker-hub": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeFix",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "hub.docker.com",
|
||||
"value": "https://hub.docker.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": null
|
||||
},
|
||||
"google-gcr": {
|
||||
"endpoint_pattern": {
|
||||
"endpoint_type": "EndpointPatternTypeList",
|
||||
"endpoints": [
|
||||
{
|
||||
"key": "gcr.io",
|
||||
"value": "https://gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "us.gcr.io",
|
||||
"value": "https://us.gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "eu.gcr.io",
|
||||
"value": "https://eu.gcr.io"
|
||||
},
|
||||
{
|
||||
"key": "asia.gcr.io",
|
||||
"value": "https://asia.gcr.io"
|
||||
}
|
||||
]
|
||||
},
|
||||
"credential_pattern": {
|
||||
"access_key_type": "AccessKeyTypeFix",
|
||||
"access_key_data": "_json_key",
|
||||
"access_secret_type": "AccessSecretTypeFile",
|
||||
"access_secret_data": "No Change"
|
||||
}
|
||||
}
|
||||
};
|
||||
let fakedHttp = {
|
||||
get() {
|
||||
return of(adapterInfoMockData);
|
||||
}
|
||||
};
|
||||
let mockData: Endpoint[] = [
|
||||
{
|
||||
id: 1,
|
||||
@ -76,7 +290,6 @@ describe("EndpointComponent (inline template)", () => {
|
||||
url: "https://4.4.4.4"
|
||||
}
|
||||
];
|
||||
|
||||
let mockOne: Endpoint[] = [
|
||||
{
|
||||
id: 1,
|
||||
@ -108,7 +321,7 @@ describe("EndpointComponent (inline template)", () => {
|
||||
let spyOne: jasmine.Spy;
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [SharedModule, NoopAnimationsModule],
|
||||
imports: [SharedModule, NoopAnimationsModule, HttpClientTestingModule],
|
||||
declarations: [
|
||||
FilterComponent,
|
||||
ConfirmationDialogComponent,
|
||||
@ -120,7 +333,8 @@ describe("EndpointComponent (inline template)", () => {
|
||||
ErrorHandler,
|
||||
{ provide: SERVICE_CONFIG, useValue: config },
|
||||
{ provide: EndpointService, useClass: EndpointDefaultService },
|
||||
{ provide: OperationService }
|
||||
{ provide: OperationService },
|
||||
{ provide: HttpClient, useValue: fakedHttp },
|
||||
]
|
||||
});
|
||||
}));
|
||||
@ -128,9 +342,7 @@ describe("EndpointComponent (inline template)", () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EndpointComponent);
|
||||
comp = fixture.componentInstance;
|
||||
|
||||
endpointService = fixture.debugElement.injector.get(EndpointService);
|
||||
|
||||
spy = spyOn(endpointService, "getEndpoints").and.returnValues(
|
||||
of(mockData)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user