summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-site.service.ts
blob: 49589c83f4e071a23a75a77a621713435585ef6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { Observable } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';

import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
import { cdEncode } from '~/app/shared/decorators/cd-encode';

@cdEncode
@Injectable({
  providedIn: 'root'
})
export class RgwSiteService {
  private url = 'api/rgw/site';

  constructor(private http: HttpClient, private rgwDaemonService: RgwDaemonService) {}

  get(query?: string) {
    return this.rgwDaemonService.request((params: HttpParams) => {
      if (query) {
        params = params.append('query', query);
      }
      return this.http.get(this.url, { params: params });
    });
  }

  isDefaultRealm(): Observable<boolean> {
    return this.get('default-realm').pipe(
      mergeMap((defaultRealm: string) =>
        this.rgwDaemonService.selectedDaemon$.pipe(
          map((selectedDaemon: RgwDaemon) => selectedDaemon.realm_name === defaultRealm)
        )
      )
    );
  }
}