mirror of
https://github.com/ceph/ceph
synced 2025-02-23 02:57:21 +00:00
Merge pull request #60173 from rhcs-dashboard/fix-lc
mgr/dashboard: fix lifecycle issues Reviewed-by: Afreen Misbah <afreen@ibm.com>
This commit is contained in:
commit
6258acbfa0
@ -158,8 +158,14 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<pre *ngIf="lifecycleFormat === 'json'">{{selection.lifecycle | json}}</pre>
|
||||
<pre *ngIf="lifecycleFormat === 'xml'">{{ (selection.lifecycle | xml) || '-'}}</pre>
|
||||
<cds-code-snippet display="multi"
|
||||
*ngIf="lifecycleFormat === 'json'">
|
||||
{{selection.lifecycle | json}}
|
||||
</cds-code-snippet>
|
||||
<cds-code-snippet display="multi"
|
||||
*ngIf="lifecycleFormat === 'xml'">
|
||||
{{ (selection.lifecycle | xml:{'Rules':'Rule'}) || '-'}}
|
||||
</cds-code-snippet>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -70,7 +70,8 @@ import {
|
||||
IconModule,
|
||||
LoadingModule,
|
||||
ModalModule,
|
||||
ProgressIndicatorModule
|
||||
ProgressIndicatorModule,
|
||||
CodeSnippetModule
|
||||
} from 'carbon-components-angular';
|
||||
import { CephSharedModule } from '../shared/ceph-shared.module';
|
||||
|
||||
@ -94,6 +95,7 @@ import { CephSharedModule } from '../shared/ceph-shared.module';
|
||||
ModalModule,
|
||||
GridModule,
|
||||
ProgressIndicatorModule,
|
||||
CodeSnippetModule,
|
||||
ButtonModule,
|
||||
LoadingModule,
|
||||
IconModule,
|
||||
|
@ -7,9 +7,13 @@ import { JsonToXmlService } from '../services/json-to-xml.service';
|
||||
export class XmlPipe implements PipeTransform {
|
||||
constructor(private jsonToXmlService: JsonToXmlService) {}
|
||||
|
||||
transform(value: string, valueFormat: string = 'json'): string {
|
||||
transform(
|
||||
value: string,
|
||||
replaceKey: Record<string, string> = {},
|
||||
valueFormat: string = 'json'
|
||||
): string {
|
||||
if (valueFormat === 'json') {
|
||||
value = this.jsonToXmlService.format(value);
|
||||
value = this.jsonToXmlService.format(value, replaceKey);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@ -6,29 +6,39 @@ import { Injectable } from '@angular/core';
|
||||
export class JsonToXmlService {
|
||||
constructor() {}
|
||||
|
||||
format(json: any, indentSize: number = 2, currentIndent: number = 0): string {
|
||||
format(
|
||||
json: any,
|
||||
replaceKey: Record<string, string> = null,
|
||||
indentSize: number = 2,
|
||||
currentIndent: number = 0
|
||||
): string {
|
||||
if (!json) return null;
|
||||
let xml = '';
|
||||
if (typeof json === 'string') {
|
||||
json = JSON.parse(json);
|
||||
}
|
||||
|
||||
for (const key in json) {
|
||||
for (let key in json) {
|
||||
if (json.hasOwnProperty(key)) {
|
||||
const value = json[key];
|
||||
const indentation = ' '.repeat(currentIndent);
|
||||
|
||||
if (replaceKey) {
|
||||
const [oldKey, newKey] = Object.entries(replaceKey)[0];
|
||||
if (key === oldKey) {
|
||||
key = newKey;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item) => {
|
||||
xml +=
|
||||
`${indentation}<${key}>\n` +
|
||||
this.format(item, indentSize, currentIndent + indentSize) +
|
||||
this.format(item, replaceKey, indentSize, currentIndent + indentSize) +
|
||||
`${indentation}</${key}>\n`;
|
||||
});
|
||||
} else if (typeof value === 'object') {
|
||||
xml +=
|
||||
`${indentation}<${key}>\n` +
|
||||
this.format(value, indentSize, currentIndent + indentSize) +
|
||||
this.format(value, replaceKey, indentSize, currentIndent + indentSize) +
|
||||
`${indentation}</${key}>\n`;
|
||||
} else {
|
||||
xml += `${indentation}<${key}>${value}</${key}>\n`;
|
||||
|
@ -142,3 +142,10 @@ Dashboard page
|
||||
cd-dashboard {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/******************************************
|
||||
Code snippet
|
||||
******************************************/
|
||||
.cds--snippet {
|
||||
width: fit-content;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import re
|
||||
import time
|
||||
import uuid
|
||||
import xml.etree.ElementTree as ET # noqa: N814
|
||||
from collections import defaultdict
|
||||
from enum import Enum
|
||||
from subprocess import SubprocessError
|
||||
from urllib.parse import urlparse
|
||||
@ -701,12 +702,28 @@ class RgwClient(RestClient):
|
||||
raise DashboardException(msg=str(e), component='rgw')
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _handle_rules(pairs):
|
||||
result = defaultdict(list)
|
||||
for key, value in pairs:
|
||||
if key == 'Rule':
|
||||
result['Rules'].append(value)
|
||||
else:
|
||||
result[key] = value
|
||||
return result
|
||||
|
||||
@RestClient.api_get('/{bucket_name}?lifecycle')
|
||||
def get_lifecycle(self, bucket_name, request=None):
|
||||
# pylint: disable=unused-argument
|
||||
try:
|
||||
result = request() # type: ignore
|
||||
result = {'LifecycleConfiguration': result}
|
||||
decoded_request = request(raw_content=True).decode("utf-8") # type: ignore
|
||||
result = {
|
||||
'LifecycleConfiguration':
|
||||
json.loads(
|
||||
decoded_request,
|
||||
object_pairs_hook=RgwClient._handle_rules
|
||||
)
|
||||
}
|
||||
except RequestException as e:
|
||||
if e.content:
|
||||
content = json_str_to_object(e.content)
|
||||
@ -758,15 +775,15 @@ class RgwClient(RestClient):
|
||||
lifecycle = RgwClient.dict_to_xml(lifecycle)
|
||||
try:
|
||||
if lifecycle and '<LifecycleConfiguration>' not in str(lifecycle):
|
||||
lifecycle = f'<LifecycleConfiguration>{lifecycle}</LifecycleConfiguration>'
|
||||
lifecycle = f'<LifecycleConfiguration>\n{lifecycle}\n</LifecycleConfiguration>'
|
||||
result = request(data=lifecycle) # type: ignore
|
||||
except RequestException as e:
|
||||
msg = ''
|
||||
if e.content:
|
||||
content = json_str_to_object(e.content)
|
||||
if content.get("Code") == "MalformedXML":
|
||||
msg = "Invalid Lifecycle document"
|
||||
raise DashboardException(msg=msg, component='rgw')
|
||||
raise DashboardException(msg=str(e), component='rgw')
|
||||
raise DashboardException(msg=msg or str(e), component='rgw')
|
||||
return result
|
||||
|
||||
@RestClient.api_delete('/{bucket_name}?lifecycle')
|
||||
|
Loading…
Reference in New Issue
Block a user