]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/configuration.service.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / configuration.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { ConfigFormCreateRequestModel } from '../../ceph/cluster/configuration/configuration-form/configuration-form-create-request.model';
5 import { ApiModule } from './api.module';
6
7 @Injectable({
8 providedIn: ApiModule
9 })
10 export class ConfigurationService {
11 constructor(private http: HttpClient) {}
12
13 private findValue(config: any, section: string) {
14 if (!config.value) {
15 return undefined;
16 }
17 return config.value.find((v: any) => v.section === section);
18 }
19
20 getValue(config: any, section: string) {
21 let val = this.findValue(config, section);
22 if (!val) {
23 const indexOfDot = section.indexOf('.');
24 if (indexOfDot !== -1) {
25 val = this.findValue(config, section.substring(0, indexOfDot));
26 }
27 }
28 if (!val) {
29 val = this.findValue(config, 'global');
30 }
31 if (val) {
32 return val.value;
33 }
34 return config.default;
35 }
36
37 getConfigData() {
38 return this.http.get('api/cluster_conf/');
39 }
40
41 get(configOption: string) {
42 return this.http.get(`api/cluster_conf/${configOption}`);
43 }
44
45 filter(configOptionNames: Array<string>) {
46 return this.http.get(`api/cluster_conf/filter?names=${configOptionNames.join(',')}`);
47 }
48
49 create(configOption: ConfigFormCreateRequestModel) {
50 return this.http.post('api/cluster_conf/', configOption);
51 }
52
53 delete(configOption: string, section: string) {
54 return this.http.delete(`api/cluster_conf/${configOption}?section=${section}`);
55 }
56
57 bulkCreate(configOptions: object) {
58 return this.http.put('api/cluster_conf/', configOptions);
59 }
60 }