Skip to content

Commit

Permalink
fix: return binary data size instead of content
Browse files Browse the repository at this point in the history
  • Loading branch information
lsq645599166 committed Nov 1, 2024
1 parent b4bf1f1 commit 68326b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions modules/api/pkg/resource/configmap/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ConfigMapDetail struct {

// BinaryData contains the configuration binary data.
// Each key must be a valid DNS_SUBDOMAIN with an optional leading dot.
BinaryData map[string][]byte `json:"binaryData,omitempty"`
BinaryData map[string]int `json:"binaryData,omitempty"`
}

// GetConfigMapDetail returns detailed information about a config map
Expand All @@ -55,6 +55,16 @@ func getConfigMapDetail(rawConfigMap *v1.ConfigMap) *ConfigMapDetail {
return &ConfigMapDetail{
ConfigMap: toConfigMap(rawConfigMap.ObjectMeta),
Data: rawConfigMap.Data,
BinaryData: rawConfigMap.BinaryData,
BinaryData: getBinaryDataKeySize(rawConfigMap.BinaryData),
}
}

func getBinaryDataKeySize(binaryData map[string][]byte) map[string]int {
converted := make(map[string]int)

for key, value := range binaryData {
converted[key] = len(string(value))
}

return converted
}
2 changes: 1 addition & 1 deletion modules/api/schema/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10006,7 +10006,7 @@
"binaryData": {
"type": "object",
"additionalProperties": {
"type": "string"
"type": "integer"
}
},
"data": {
Expand Down
4 changes: 2 additions & 2 deletions modules/web/src/resource/config/configmap/detail/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export class ConfigMapDetailComponent implements OnInit, OnDestroy {
return [];
}

return Object.entries(cm.binaryData).map(([name, value]) => ({
return Object.entries(cm.binaryData).map(([name, size]) => ({
name,
size: atob(value).length,
size,
}));
}

Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/typings/root.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export interface IngressClassDetail extends ResourceDetail {

export interface ConfigMapDetail extends ResourceDetail {
data: StringMap;
binaryData: StringMap;
binaryData: Record<string, number>;
}

export interface CRDDetail extends ResourceDetail {
Expand Down

0 comments on commit 68326b8

Please sign in to comment.