web-apps: Remove all the Rok references (kubeflow/kubeflow#7020)
* web-apps(front): Remove rok references Signed-off-by: Elena Zioga <elena@arrikto.com> * web-apps(back): Remove rok references Signed-off-by: Elena Zioga <elena@arrikto.com> --------- Signed-off-by: Elena Zioga <elena@arrikto.com>
This commit is contained in:
parent
78e067e594
commit
f3cacadbb2
|
|
@ -1 +0,0 @@
|
||||||
from .routes import bp # noqa E402, F401
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
from flask import Blueprint
|
|
||||||
|
|
||||||
from .. import api
|
|
||||||
|
|
||||||
bp = Blueprint("rok_base_routes", __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/api/rok/storageclasses")
|
|
||||||
def get_rok_storageclasses():
|
|
||||||
"""
|
|
||||||
Return a list of k8s storage classes that are provided from Rok
|
|
||||||
"""
|
|
||||||
# TODO(kimwnasptd): Should use annotations on storage classes instead
|
|
||||||
return api.success_response("storageClasses", ["rok"])
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
|
|
||||||
<defs>
|
|
||||||
<path id="browse-in-rok-blue-a" d="M15.9899671,8.40418062 C15.779458,12.6346619 12.2827374,16 8,16 C3.581722,16 0,12.418278 0,8 C0,4.27063317 2.55185507,1.13728403 6.00468786,0.250829921 C6.00157195,0.333500797 6,0.416566824 6,0.5 C6,4.08985087 8.91014913,7 12.5,7 C13.1339017,7 13.7466095,6.90925845 14.3258426,6.7400562 L15.9899671,8.40418062 Z"/>
|
|
||||||
</defs>
|
|
||||||
<g fill="none" fill-rule="evenodd" transform="translate(-3234 -2346)">
|
|
||||||
<g transform="translate(3237 2352)">
|
|
||||||
<mask id="browse-in-rok-blue-b" fill="#fff">
|
|
||||||
<use xlink:href="#browse-in-rok-blue-a"/>
|
|
||||||
</mask>
|
|
||||||
<use fill="#4990E2" xlink:href="#browse-in-rok-blue-a"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M3,3 L3,13 L13,13 L13,3 L3,3 Z M2,2 L14,2 L14,14 L2,14 L2,2 Z" mask="url(#browse-in-rok-blue-b)"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M6,10 L10,10 L10,6 L6,6 L6,10 Z M5,5 L11,5 L11,11 L5,11 L5,5 Z" mask="url(#browse-in-rok-blue-b)"/>
|
|
||||||
</g>
|
|
||||||
<path fill="#4990E2" fill-rule="nonzero" d="M3249.5,2355 C3250.88071,2355 3252,2353.88071 3252,2352.5 C3252,2351.11929 3250.88071,2350 3249.5,2350 C3248.11929,2350 3247,2351.11929 3247,2352.5 C3247,2353.88071 3248.11929,2355 3249.5,2355 Z M3249.5,2357 C3247.01472,2357 3245,2354.98528 3245,2352.5 C3245,2350.01472 3247.01472,2348 3249.5,2348 C3251.98528,2348 3254,2350.01472 3254,2352.5 C3254,2354.98528 3251.98528,2357 3249.5,2357 Z"/>
|
|
||||||
<polygon fill="#4990E2" fill-rule="nonzero" points=".793 2.207 4.328 5.743 5.743 4.328 2.207 .793" transform="translate(3251 2354)"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.6 KiB |
|
|
@ -1,17 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
|
|
||||||
<defs>
|
|
||||||
<path id="browse-in-rok-gray-a" d="M15.9899671,8.40418062 C15.779458,12.6346619 12.2827374,16 8,16 C3.581722,16 0,12.418278 0,8 C0,4.27063317 2.55185507,1.13728403 6.00468786,0.250829921 C6.00157195,0.333500797 6,0.416566824 6,0.5 C6,4.08985087 8.91014913,7 12.5,7 C13.1339017,7 13.7466095,6.90925845 14.3258426,6.7400562 L15.9899671,8.40418062 Z"/>
|
|
||||||
</defs>
|
|
||||||
<g fill="none" fill-rule="evenodd" transform="translate(-3170 -2346)">
|
|
||||||
<g transform="translate(3173 2352)">
|
|
||||||
<mask id="browse-in-rok-gray-b" fill="#fff">
|
|
||||||
<use xlink:href="#browse-in-rok-gray-a"/>
|
|
||||||
</mask>
|
|
||||||
<use fill="#00000061" xlink:href="#browse-in-rok-gray-a"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M3,3 L3,13 L13,13 L13,3 L3,3 Z M2,2 L14,2 L14,14 L2,14 L2,2 Z" mask="url(#browse-in-rok-gray-b)"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M6,10 L10,10 L10,6 L6,6 L6,10 Z M5,5 L11,5 L11,11 L5,11 L5,5 Z" mask="url(#browse-in-rok-gray-b)"/>
|
|
||||||
</g>
|
|
||||||
<path fill="#00000061" fill-rule="nonzero" d="M3185.5,2355 C3186.88071,2355 3188,2353.88071 3188,2352.5 C3188,2351.11929 3186.88071,2350 3185.5,2350 C3184.11929,2350 3183,2351.11929 3183,2352.5 C3183,2353.88071 3184.11929,2355 3185.5,2355 Z M3185.5,2357 C3183.01472,2357 3181,2354.98528 3181,2352.5 C3181,2350.01472 3183.01472,2348 3185.5,2348 C3187.98528,2348 3190,2350.01472 3190,2352.5 C3190,2354.98528 3187.98528,2357 3185.5,2357 Z"/>
|
|
||||||
<polygon fill="#00000061" fill-rule="nonzero" points="1.793 2.207 5.328 5.743 6.743 4.328 3.207 .793" transform="translate(3186 2354)"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.7 KiB |
|
|
@ -1,17 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
|
|
||||||
<defs>
|
|
||||||
<path id="browse-in-rok-gray-a" d="M15.9899671,8.40418062 C15.779458,12.6346619 12.2827374,16 8,16 C3.581722,16 0,12.418278 0,8 C0,4.27063317 2.55185507,1.13728403 6.00468786,0.250829921 C6.00157195,0.333500797 6,0.416566824 6,0.5 C6,4.08985087 8.91014913,7 12.5,7 C13.1339017,7 13.7466095,6.90925845 14.3258426,6.7400562 L15.9899671,8.40418062 Z"/>
|
|
||||||
</defs>
|
|
||||||
<g fill="none" fill-rule="evenodd" transform="translate(-3170 -2346)">
|
|
||||||
<g transform="translate(3173 2352)">
|
|
||||||
<mask id="browse-in-rok-gray-b" fill="#fff">
|
|
||||||
<use xlink:href="#browse-in-rok-gray-a"/>
|
|
||||||
</mask>
|
|
||||||
<use fill="#00000061" xlink:href="#browse-in-rok-gray-a"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M3,3 L3,13 L13,13 L13,3 L3,3 Z M2,2 L14,2 L14,14 L2,14 L2,2 Z" mask="url(#browse-in-rok-gray-b)"/>
|
|
||||||
<path fill="#FFF" fill-rule="nonzero" d="M6,10 L10,10 L10,6 L6,6 L6,10 Z M5,5 L11,5 L11,11 L5,11 L5,5 Z" mask="url(#browse-in-rok-gray-b)"/>
|
|
||||||
</g>
|
|
||||||
<path fill="#00000061" fill-rule="nonzero" d="M3185.5,2355 C3186.88071,2355 3188,2353.88071 3188,2352.5 C3188,2351.11929 3186.88071,2350 3185.5,2350 C3184.11929,2350 3183,2351.11929 3183,2352.5 C3183,2353.88071 3184.11929,2355 3185.5,2355 Z M3185.5,2357 C3183.01472,2357 3181,2354.98528 3181,2352.5 C3181,2350.01472 3183.01472,2348 3185.5,2348 C3187.98528,2348 3190,2350.01472 3190,2352.5 C3190,2354.98528 3187.98528,2357 3185.5,2357 Z"/>
|
|
||||||
<polygon fill="#00000061" fill-rule="nonzero" points="1.793 2.207 5.328 5.743 6.743 4.328 3.207 .793" transform="translate(3186 2354)"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.7 KiB |
|
|
@ -21,7 +21,6 @@ import { NameNamespaceInputsComponent } from './name-namespace-inputs/name-names
|
||||||
import { NameInputComponent } from './name-namespace-inputs/name-input/name-input.component';
|
import { NameInputComponent } from './name-namespace-inputs/name-input/name-input.component';
|
||||||
import { IconModule } from '../icon/icon.module';
|
import { IconModule } from '../icon/icon.module';
|
||||||
import { PositiveNumberInputComponent } from './positive-number-input/positive-number-input.component';
|
import { PositiveNumberInputComponent } from './positive-number-input/positive-number-input.component';
|
||||||
import { RokUrlInputComponent } from './rok-url-input/rok-url-input.component';
|
|
||||||
import { AdvancedOptionsComponent } from './advanced-options/advanced-options.component';
|
import { AdvancedOptionsComponent } from './advanced-options/advanced-options.component';
|
||||||
import { PopoverModule } from '../popover/popover.module';
|
import { PopoverModule } from '../popover/popover.module';
|
||||||
import { SubmitBarComponent } from './submit-bar/submit-bar.component';
|
import { SubmitBarComponent } from './submit-bar/submit-bar.component';
|
||||||
|
|
@ -33,7 +32,6 @@ import { StepInfoComponent } from './step-info/step-info.component';
|
||||||
NameNamespaceInputsComponent,
|
NameNamespaceInputsComponent,
|
||||||
NameInputComponent,
|
NameInputComponent,
|
||||||
PositiveNumberInputComponent,
|
PositiveNumberInputComponent,
|
||||||
RokUrlInputComponent,
|
|
||||||
AdvancedOptionsComponent,
|
AdvancedOptionsComponent,
|
||||||
SubmitBarComponent,
|
SubmitBarComponent,
|
||||||
StepInfoComponent,
|
StepInfoComponent,
|
||||||
|
|
@ -57,7 +55,6 @@ import { StepInfoComponent } from './step-info/step-info.component';
|
||||||
NameNamespaceInputsComponent,
|
NameNamespaceInputsComponent,
|
||||||
NameInputComponent,
|
NameInputComponent,
|
||||||
PositiveNumberInputComponent,
|
PositiveNumberInputComponent,
|
||||||
RokUrlInputComponent,
|
|
||||||
AdvancedOptionsComponent,
|
AdvancedOptionsComponent,
|
||||||
SubmitBarComponent,
|
SubmitBarComponent,
|
||||||
StepInfoComponent,
|
StepInfoComponent,
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
<mat-form-field appearance="outline" class="form-field-with-button wide">
|
|
||||||
<mat-label>Rok URL</mat-label>
|
|
||||||
<input matInput type="url" [formControl]="control" />
|
|
||||||
<button
|
|
||||||
matSuffix
|
|
||||||
matTolltip="Choose RokURL"
|
|
||||||
type="button"
|
|
||||||
(click)="openChooser()"
|
|
||||||
[disabled]="control.disabled"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
*ngIf="control.enabled; else disableTpl"
|
|
||||||
src="static/assets/browse-in-rok-blue.svg"
|
|
||||||
/>
|
|
||||||
<ng-template #disableTpl>
|
|
||||||
<img src="static/assets/browse-in-rok-grey.svg" />
|
|
||||||
</ng-template>
|
|
||||||
</button>
|
|
||||||
<mat-error>{{ parseRokUrlError() }}</mat-error>
|
|
||||||
<mat-hint *ngIf="control.valid && dateTime"
|
|
||||||
>Restoring {{ snapshotType }} from {{ dateTime }}</mat-hint
|
|
||||||
>
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
.form-field-with-button {
|
|
||||||
button {
|
|
||||||
border: none;
|
|
||||||
background: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
border-radius: 50%;
|
|
||||||
padding: 0;
|
|
||||||
border: 5px solid transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
button:hover {
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
button:disabled {
|
|
||||||
background: none;
|
|
||||||
cursor: default;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mat-form-field-flex {
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { RokUrlInputComponent } from './rok-url-input.component';
|
|
||||||
import { FormControl } from '@angular/forms';
|
|
||||||
import { FormModule } from '../form.module';
|
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
||||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
|
||||||
|
|
||||||
describe('RokUrlInputComponent', () => {
|
|
||||||
let component: RokUrlInputComponent;
|
|
||||||
let fixture: ComponentFixture<RokUrlInputComponent>;
|
|
||||||
|
|
||||||
beforeEach(
|
|
||||||
waitForAsync(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [
|
|
||||||
FormModule,
|
|
||||||
BrowserAnimationsModule,
|
|
||||||
MatSnackBarModule,
|
|
||||||
HttpClientModule,
|
|
||||||
],
|
|
||||||
}).compileComponents();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(RokUrlInputComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
component.control = new FormControl();
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a valid date using formatDate()', () => {
|
|
||||||
expect(component.formatDate('2022-08-01T10:02:00.716339+00:00')).toEqual(
|
|
||||||
'01/08/2022 - 10:02:00',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
import {
|
|
||||||
Component,
|
|
||||||
OnInit,
|
|
||||||
Input,
|
|
||||||
HostListener,
|
|
||||||
Output,
|
|
||||||
EventEmitter,
|
|
||||||
} from '@angular/core';
|
|
||||||
import { AbstractControl } from '@angular/forms';
|
|
||||||
import { getRokUrlError } from '../validators';
|
|
||||||
import { filter } from 'rxjs/operators';
|
|
||||||
import { RokService } from '../../services/rok/rok.service';
|
|
||||||
import { HttpHeaders } from '@angular/common/http';
|
|
||||||
@Component({
|
|
||||||
selector: 'lib-rok-url-input',
|
|
||||||
templateUrl: './rok-url-input.component.html',
|
|
||||||
styleUrls: ['./rok-url-input.component.scss'],
|
|
||||||
})
|
|
||||||
export class RokUrlInputComponent implements OnInit {
|
|
||||||
@Input() control: AbstractControl;
|
|
||||||
@Input() snapshotType: string;
|
|
||||||
@Input() mode = 'group';
|
|
||||||
@Input() create = false;
|
|
||||||
@Output() snapshotHeaders = new EventEmitter<HttpHeaders>();
|
|
||||||
|
|
||||||
private popupChooser;
|
|
||||||
private chooserId = -1;
|
|
||||||
dateTime: string;
|
|
||||||
|
|
||||||
constructor(public rok: RokService) {}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
// Emit an event whenever a valid url has been detected
|
|
||||||
this.control.statusChanges
|
|
||||||
.pipe(filter(() => this.control.valid && this.control.value !== ''))
|
|
||||||
.subscribe(() => {
|
|
||||||
this.getHeaders(this.control.value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chooser popup handlers
|
|
||||||
public openChooser() {
|
|
||||||
if (this.popupChooser && !this.popupChooser.closed) {
|
|
||||||
this.popupChooser.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.chooserId = Date.now();
|
|
||||||
this.popupChooser = window.open(
|
|
||||||
`/rok/buckets?mode=${this.mode}-chooser` +
|
|
||||||
`&create=${this.create}` +
|
|
||||||
`&chooser-id=${this.chooserId}`,
|
|
||||||
'Chooser',
|
|
||||||
`height=500,width=600,menubar=0`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public parseRokUrlError() {
|
|
||||||
return getRokUrlError(this.control);
|
|
||||||
}
|
|
||||||
|
|
||||||
@HostListener('window:message', ['$event'])
|
|
||||||
onMessage(event) {
|
|
||||||
if (
|
|
||||||
typeof event.data === 'object' &&
|
|
||||||
event.data.hasOwnProperty('chooser') &&
|
|
||||||
event.data.hasOwnProperty('chooserId') &&
|
|
||||||
event.data.chooserId === this.chooserId.toString()
|
|
||||||
) {
|
|
||||||
this.control.setValue(event.data.chooser);
|
|
||||||
this.popupChooser.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getHeaders(url: string) {
|
|
||||||
this.rok.getObjectMetadata(url).subscribe(headers => {
|
|
||||||
this.snapshotHeaders.emit(headers);
|
|
||||||
this.dateTime = this.formatDate(
|
|
||||||
headers.get('x-origin-created-timestamp'),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
formatDate(inputDate: string): string {
|
|
||||||
// More info about 'en-GB' here:
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
|
||||||
const myDate = new Date(inputDate).toLocaleString('en-GB', {
|
|
||||||
timeZone: 'UTC',
|
|
||||||
});
|
|
||||||
return myDate.replace(', ', ' - ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ import {
|
||||||
|
|
||||||
import { Observable, of, timer, of as observableOf } from 'rxjs';
|
import { Observable, of, timer, of as observableOf } from 'rxjs';
|
||||||
import { switchMap, map, catchError } from 'rxjs/operators';
|
import { switchMap, map, catchError } from 'rxjs/operators';
|
||||||
import { RokService } from '../services/rok/rok.service';
|
|
||||||
|
|
||||||
const dns1123LabelFmt = '[a-z0-9]([-a-z0-9]*[a-z0-9])?';
|
const dns1123LabelFmt = '[a-z0-9]([-a-z0-9]*[a-z0-9])?';
|
||||||
|
|
||||||
|
|
@ -130,36 +129,3 @@ export function getNameAsyncValidators(
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rok
|
|
||||||
export function getRokUrlError(rokUrlCtrl: AbstractControl) {
|
|
||||||
if (rokUrlCtrl.hasError('required')) {
|
|
||||||
return 'Rok URL cannot be empty';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rokUrlCtrl.hasError('invalidRokUrl')) {
|
|
||||||
return 'Not a valid Rok URL';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function rokUrlValidator(rok: RokService): AsyncValidatorFn {
|
|
||||||
return (control: AbstractControl): Observable<ValidationErrors | null> => {
|
|
||||||
const url = control.value;
|
|
||||||
|
|
||||||
// Don't return error if the url is empty
|
|
||||||
if (url.length === 0) {
|
|
||||||
return of(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure a protocol is given
|
|
||||||
// Don't fire while the user is writting
|
|
||||||
return timer(DEBOUNCE_TIME).pipe(
|
|
||||||
switchMap(() =>
|
|
||||||
rok.getObjectMetadata(url, false).pipe(
|
|
||||||
map(resp => null),
|
|
||||||
catchError((msg: string) => observableOf({ invalidRokUrl: true })),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import {
|
||||||
HTTP_INTERCEPTORS,
|
HTTP_INTERCEPTORS,
|
||||||
HttpClientXsrfModule,
|
HttpClientXsrfModule,
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { HeadersInterceptor } from './services/rok/injector';
|
|
||||||
import { PopoverModule } from './popover/popover.module';
|
import { PopoverModule } from './popover/popover.module';
|
||||||
import { TitleActionsToolbarModule } from './title-actions-toolbar/title-actions-toolbar.module';
|
import { TitleActionsToolbarModule } from './title-actions-toolbar/title-actions-toolbar.module';
|
||||||
import { ConditionsTableModule } from './conditions-table/conditions-table.module';
|
import { ConditionsTableModule } from './conditions-table/conditions-table.module';
|
||||||
|
|
@ -46,8 +45,5 @@ import { StatusIconModule } from './status-icon/status-icon.module';
|
||||||
StatusIconModule,
|
StatusIconModule,
|
||||||
],
|
],
|
||||||
imports: [CommonModule, HttpClientModule, HttpClientXsrfModule],
|
imports: [CommonModule, HttpClientModule, HttpClientXsrfModule],
|
||||||
providers: [
|
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: HeadersInterceptor, multi: true },
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class KubeflowModule {}
|
export class KubeflowModule {}
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import {
|
|
||||||
HttpInterceptor,
|
|
||||||
HttpRequest,
|
|
||||||
HttpHandler,
|
|
||||||
HttpEvent,
|
|
||||||
HttpResponse,
|
|
||||||
HttpHeaders,
|
|
||||||
} from '@angular/common/http';
|
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
|
|
||||||
export function forEachHttpHeader(
|
|
||||||
headers: HttpHeaders,
|
|
||||||
cb: (name: string, value: string) => void,
|
|
||||||
) {
|
|
||||||
headers.keys().forEach(name => {
|
|
||||||
// FIXME: A header name can have more than one values. We must use the
|
|
||||||
// getAll() method if we want to support more values.
|
|
||||||
const value = headers.get(name) as string;
|
|
||||||
cb(name, value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class HeadersInterceptor implements HttpInterceptor {
|
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
intercept(
|
|
||||||
req: HttpRequest<any>,
|
|
||||||
next: HttpHandler,
|
|
||||||
): Observable<HttpEvent<any>> {
|
|
||||||
return next.handle(req).pipe(
|
|
||||||
map((event: HttpEvent<any>) => {
|
|
||||||
if (!(event instanceof HttpResponse)) {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
const evHeaders = event.headers;
|
|
||||||
const h: { [key: string]: string } = {};
|
|
||||||
forEachHttpHeader(evHeaders, (name, value) => {
|
|
||||||
if (
|
|
||||||
name.startsWith('x-object-meta-') ||
|
|
||||||
value === 'x-container-throw-ref'
|
|
||||||
) {
|
|
||||||
value = decodeURIComponent(value);
|
|
||||||
}
|
|
||||||
h[name] = value;
|
|
||||||
});
|
|
||||||
return event.clone({
|
|
||||||
headers: new HttpHeaders(h),
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { BackendService } from '../backend/backend.service';
|
|
||||||
import { SnackBarService } from '../../snack-bar/snack-bar.service';
|
|
||||||
import {
|
|
||||||
HttpClient,
|
|
||||||
HttpHeaders,
|
|
||||||
HttpResponse,
|
|
||||||
HttpErrorResponse,
|
|
||||||
} from '@angular/common/http';
|
|
||||||
import { map, catchError, tap } from 'rxjs/operators';
|
|
||||||
import { Observable, throwError } from 'rxjs';
|
|
||||||
import { RokSettings } from './types';
|
|
||||||
import { BackendResponse } from '../backend/types';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class RokService extends BackendService {
|
|
||||||
private csrfToken = '';
|
|
||||||
|
|
||||||
constructor(public http: HttpClient, public dialog: SnackBarService) {
|
|
||||||
super(http, dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
public initCSRF() {
|
|
||||||
if (this.csrfToken.length !== 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Setting up CSRF protection for Rok');
|
|
||||||
this.http
|
|
||||||
.get<RokSettings>('/rok/services/settings')
|
|
||||||
.pipe(
|
|
||||||
catchError(error => this.handleError(error, true)),
|
|
||||||
map((settings: RokSettings) => {
|
|
||||||
console.log('Got back Rok settings:');
|
|
||||||
console.log(settings);
|
|
||||||
console.log(`Using token: ${settings.static_token}`);
|
|
||||||
|
|
||||||
if (settings.static_token === null) {
|
|
||||||
console.warn(`Using null token for CSRF protection!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.csrfToken = settings.static_token;
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public rokRespIsValid(resp: HttpResponse<any>) {
|
|
||||||
const rokUrl = resp.headers.get('X-Object-Rok-URL');
|
|
||||||
const objectUrl = resp.headers.get('X-Object-URL');
|
|
||||||
|
|
||||||
if (rokUrl === null || rokUrl !== objectUrl) {
|
|
||||||
throw new ErrorEvent('Bad Rok URL', {
|
|
||||||
message: `'${resp.url}' is not a valid Rok URL`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getObjectMetadata(
|
|
||||||
url: string,
|
|
||||||
showSnackBar = true,
|
|
||||||
): Observable<HttpHeaders> {
|
|
||||||
console.log(`Making a HEAD to '${url} to get Object Metadata`);
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.head<any>(url, {
|
|
||||||
headers: new HttpHeaders({
|
|
||||||
'X-Auth-Token': this.csrfToken,
|
|
||||||
}),
|
|
||||||
observe: 'response',
|
|
||||||
})
|
|
||||||
.pipe(
|
|
||||||
tap(resp => this.rokRespIsValid(resp)),
|
|
||||||
catchError(error => this.handleError(error, showSnackBar)),
|
|
||||||
map((resp: HttpResponse<any>) => {
|
|
||||||
console.log(`Metadata for object in url: ${url}`);
|
|
||||||
console.log(resp.headers);
|
|
||||||
|
|
||||||
return resp.headers;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getRokManagedStorageClasses(
|
|
||||||
showSnackBar = true,
|
|
||||||
): Observable<string[]> {
|
|
||||||
// Get existing PVCs in a namespace
|
|
||||||
const url = `api/rok/storageclasses`;
|
|
||||||
|
|
||||||
return this.http.get<BackendResponse>(url).pipe(
|
|
||||||
catchError(error => this.handleError(error, showSnackBar)),
|
|
||||||
map((data: BackendResponse) => data.storageClasses),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import { BackendResponse } from '../backend/types';
|
|
||||||
|
|
||||||
export interface RokSettings {
|
|
||||||
static_token: string;
|
|
||||||
services_url: string;
|
|
||||||
url_prefix: string;
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ export * from './lib/snack-bar/snack-bar.service';
|
||||||
export * from './lib/services/namespace.service';
|
export * from './lib/services/namespace.service';
|
||||||
export * from './lib/services/poller.service';
|
export * from './lib/services/poller.service';
|
||||||
export * from './lib/services/backend/backend.service';
|
export * from './lib/services/backend/backend.service';
|
||||||
export * from './lib/services/rok/rok.service';
|
|
||||||
|
|
||||||
export * from './lib/namespace-select/namespace-select.module';
|
export * from './lib/namespace-select/namespace-select.module';
|
||||||
|
|
||||||
|
|
@ -45,14 +44,12 @@ export * from './lib/title-actions-toolbar/types';
|
||||||
|
|
||||||
export * from './lib/form/form.module';
|
export * from './lib/form/form.module';
|
||||||
export * from './lib/form/section/section.component';
|
export * from './lib/form/section/section.component';
|
||||||
export * from './lib/form/rok-url-input/rok-url-input.component';
|
|
||||||
|
|
||||||
export * from './lib/resource-table/types';
|
export * from './lib/resource-table/types';
|
||||||
export * from './lib/resource-table/status/types';
|
export * from './lib/resource-table/status/types';
|
||||||
export * from './lib/resource-table/table/utils';
|
export * from './lib/resource-table/table/utils';
|
||||||
export * from './lib/snack-bar/types';
|
export * from './lib/snack-bar/types';
|
||||||
export * from './lib/services/backend/types';
|
export * from './lib/services/backend/types';
|
||||||
export * from './lib/services/rok/types';
|
|
||||||
export * from './lib/confirm-dialog/types';
|
export * from './lib/confirm-dialog/types';
|
||||||
export * from './lib/polling/exponential-backoff';
|
export * from './lib/polling/exponential-backoff';
|
||||||
export * from './lib/form/validators';
|
export * from './lib/form/validators';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue