-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config) use config api for server settings WD-7389
- Loading branch information
Showing
9 changed files
with
218 additions
and
530 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { FC } from "react"; | ||
import { LxdConfigField } from "types/config"; | ||
|
||
interface Props { | ||
configField: LxdConfigField; | ||
} | ||
|
||
const ConfigFieldDescription: FC<Props> = ({ configField }) => { | ||
const description = configField.longdesc | ||
? configField.longdesc | ||
: configField.shortdesc ?? ""; | ||
|
||
const clearString = (string: string) => | ||
string?.replace("`", "<code>").replace("`", "</code>") ?? ""; | ||
|
||
let count = 0; | ||
let stringElement = description; | ||
while (stringElement.includes("`") && count++ < 100) { | ||
stringElement = clearString(stringElement); | ||
} | ||
|
||
return ( | ||
<p | ||
className="p-text--small u-no-margin u-text--muted" | ||
dangerouslySetInnerHTML={{ __html: stringElement }} | ||
></p> | ||
); | ||
}; | ||
|
||
export default ConfigFieldDescription; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
export type LxdConfigPair = Record<string, string>; | ||
|
||
export interface LxdConfigField { | ||
default: string | boolean; | ||
description: string; | ||
export type LxdConfigField = LxdConfigOptionValue & { | ||
default: string; | ||
key: string; | ||
scope: "global" | "local"; | ||
type: "string" | "integer" | "bool"; | ||
}; | ||
|
||
export interface LxdConfigOptionValue { | ||
defaultdesc?: string; | ||
longdesc?: string; | ||
scope?: "global" | "local"; | ||
shortdesc?: string; | ||
type: "bool" | "string" | "integer"; | ||
} | ||
|
||
export interface LxcConfigOptionCategories { | ||
[category: string]: { | ||
keys: { | ||
[key: string]: LxdConfigOptionValue; | ||
}[]; | ||
}; | ||
} | ||
|
||
export interface LxdConfigOptions { | ||
configs: { | ||
cluster: LxcConfigOptionCategories; | ||
instance: LxcConfigOptionCategories; | ||
project: LxcConfigOptionCategories; | ||
server: LxcConfigOptionCategories; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { toConfigFields } from "./config"; | ||
import { LxcConfigOptionCategories } from "types/config"; | ||
|
||
const exampleConfig: LxcConfigOptionCategories = { | ||
acme: { | ||
keys: [ | ||
{ | ||
"acme.agree_tos": { | ||
defaultdesc: "`false`", | ||
shortdesc: "Agree to ACME terms of service", | ||
type: "bool", | ||
}, | ||
}, | ||
{ | ||
"acme.ca_url": { | ||
defaultdesc: "`https://acme-v02.api.letsencrypt.org/`", | ||
shortdesc: "", | ||
type: "string", | ||
}, | ||
}, | ||
], | ||
}, | ||
cluster: { | ||
keys: [ | ||
{ | ||
"cluster.healing_threshold": { | ||
defaultdesc: "`0`", | ||
shortdesc: "Threshold when to evacuate", | ||
type: "integer", | ||
}, | ||
}, | ||
{ | ||
"cluster.https_address": { | ||
shortdesc: "Address to use for clustering traffic", | ||
type: "string", | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
describe("toConfigFields", () => { | ||
it("translates config categories to flat array of fields", () => { | ||
const fields = toConfigFields(exampleConfig); | ||
|
||
expect(fields.length).toBe(4); | ||
|
||
expect(fields[0].key).toBe("acme.agree_tos"); | ||
expect(fields[0].shortdesc).toBe("Agree to ACME terms of service"); | ||
expect(fields[0].type).toBe("bool"); | ||
expect(fields[0].default).toBe("false"); | ||
|
||
expect(fields[1].key).toBe("acme.ca_url"); | ||
expect(fields[1].shortdesc).toBe(""); | ||
expect(fields[1].type).toBe("string"); | ||
expect(fields[1].default).toBe("https://acme-v02.api.letsencrypt.org/"); | ||
|
||
expect(fields[2].key).toBe("cluster.healing_threshold"); | ||
expect(fields[2].shortdesc).toBe("Threshold when to evacuate"); | ||
expect(fields[2].type).toBe("integer"); | ||
expect(fields[2].default).toBe("0"); | ||
|
||
expect(fields[3].key).toBe("cluster.https_address"); | ||
expect(fields[3].shortdesc).toBe("Address to use for clustering traffic"); | ||
expect(fields[3].type).toBe("string"); | ||
expect(fields[3].default).toBe(""); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { LxcConfigOptionCategories, LxdConfigField } from "types/config"; | ||
|
||
export const toConfigFields = ( | ||
categories: LxcConfigOptionCategories, | ||
): LxdConfigField[] => { | ||
return Object.values(categories).flatMap((value) => | ||
value.keys.flatMap( | ||
(item) => | ||
Object.entries(item).flatMap(([key, value]) => ({ | ||
...value, | ||
default: value.defaultdesc?.startsWith("`") | ||
? value.defaultdesc.substring(1, value.defaultdesc.length - 1) | ||
: "", | ||
key, | ||
}))[0], | ||
), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters