]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
0b1b24287299d8d815e243a15f2985f4270a7848
[ceph-ci.git] /
1 import { AfterViewChecked, ChangeDetectorRef, Component, OnInit } from '@angular/core';
2 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
3 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
4 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
5 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
6 import { NotificationService } from '~/app/shared/services/notification.service';
7 import { RgwRealm } from '../models/rgw-multisite';
8 import { Icons } from '~/app/shared/enum/icons.enum';
9
10 @Component({
11   selector: 'cd-rgw-multisite-export',
12   templateUrl: './rgw-multisite-export.component.html',
13   styleUrls: ['./rgw-multisite-export.component.scss']
14 })
15 export class RgwMultisiteExportComponent implements OnInit, AfterViewChecked {
16   exportTokenForm: CdFormGroup;
17   realms: any;
18   realmList: RgwRealm[];
19   multisiteInfo: any;
20   tokenValid = false;
21   loading = true;
22   icons = Icons;
23
24   constructor(
25     public activeModal: NgbActiveModal,
26     public rgwRealmService: RgwRealmService,
27     public actionLabels: ActionLabelsI18n,
28     public notificationService: NotificationService,
29     private readonly changeDetectorRef: ChangeDetectorRef
30   ) {
31     this.createForm();
32   }
33
34   createForm() {
35     this.exportTokenForm = new CdFormGroup({});
36   }
37
38   onSubmit() {
39     this.activeModal.close();
40   }
41
42   ngOnInit(): void {
43     this.rgwRealmService.getRealmTokens().subscribe((data: object[]) => {
44       this.loading = false;
45       this.realms = data;
46       var base64Matcher = new RegExp(
47         '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$'
48       );
49       this.realms.forEach((realmInfo: any) => {
50         if (base64Matcher.test(realmInfo.token)) {
51           this.tokenValid = true;
52         } else {
53           this.tokenValid = false;
54         }
55       });
56     });
57   }
58
59   ngAfterViewChecked(): void {
60     this.changeDetectorRef.detectChanges();
61   }
62 }