changed bookmark label format to requested format
This commit is contained in:
parent
2fa46066ae
commit
fdffdc1a80
@ -4,7 +4,7 @@ import path from "path";
|
|||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import Docker from "dockerode";
|
import Docker from "dockerode";
|
||||||
|
|
||||||
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { getSettings, CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||||
import getDockerArguments from "utils/config/docker";
|
import getDockerArguments from "utils/config/docker";
|
||||||
import * as shvl from "utils/config/shvl";
|
import * as shvl from "utils/config/shvl";
|
||||||
|
|
||||||
@ -91,6 +91,8 @@ export async function bookmarksFromDocker() {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { instanceName } = getSettings();
|
||||||
|
|
||||||
const bookmarkServers = await Promise.all(
|
const bookmarkServers = await Promise.all(
|
||||||
Object.keys(servers).map(async (serverName) => {
|
Object.keys(servers).map(async (serverName) => {
|
||||||
try {
|
try {
|
||||||
@ -99,26 +101,28 @@ export async function bookmarksFromDocker() {
|
|||||||
const discovered = containers.map((container) => {
|
const discovered = containers.map((container) => {
|
||||||
let constructedBookmark = null;
|
let constructedBookmark = null;
|
||||||
const containerLabels = isSwarm ? shvl.get(container, "Spec.Labels") : container.Labels;
|
const containerLabels = isSwarm ? shvl.get(container, "Spec.Labels") : container.Labels;
|
||||||
|
const containerName = isSwarm ? shvl.get(container, "Spec.Name") : container.Names[0];
|
||||||
|
|
||||||
Object.keys(containerLabels).forEach((label) => {
|
Object.keys(containerLabels).forEach((label) => {
|
||||||
if (label.startsWith("homepage.bookmarks.")) {
|
if (label.startsWith("homepage.bookmarks.")) {
|
||||||
const cleanLabel = label.replace("homepage.bookmarks.", "");
|
const containerNameNoSlash = containerName.replace(/^\//, "");
|
||||||
|
const cleanLabel = label.replace(`homepage.bookmarks.${containerNameNoSlash}.`, "");
|
||||||
|
|
||||||
// homepage.bookmarks.this_is_bookmark_group.this_is_bookmark_name.abbr = "href"
|
let value = cleanLabel;
|
||||||
|
if (instanceName && value.startsWith(`instance.${instanceName}.`)) {
|
||||||
// this_is_bookmark_group.this_is_bookmark_name.abbr = "href"
|
value = value.replace(`instance.${instanceName}.`, "");
|
||||||
// TODO should I add error handling for badly formatted labels?
|
} else if (value.startsWith("instance.")) {
|
||||||
const [bookmarkGroup, bookmarkName, bookmarkAbbr] = cleanLabel.split('.');
|
return;
|
||||||
const bookmarkHref= containerLabels[label];
|
}
|
||||||
|
|
||||||
|
if (!constructedBookmark) {
|
||||||
constructedBookmark = {
|
constructedBookmark = {
|
||||||
group: bookmarkGroup,
|
container: containerNameNoSlash,
|
||||||
name: bookmarkName,
|
server: serverName,
|
||||||
href: bookmarkHref,
|
type: "bookmark",
|
||||||
abbr: bookmarkAbbr,
|
|
||||||
type: "bookmark"
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
shvl.set(constructedBookmark, value, substituteEnvironmentVars(containerLabels[label]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user