Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: Even more types #21425

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/lib/cockpit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ declare module 'cockpit' {
interface DBusOptions {
bus?: string;
address?: string;
host?: string;
superuser?: "require" | "try";
track?: boolean;
}
Expand Down
34 changes: 2 additions & 32 deletions pkg/shell/machines/machines.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import { EventSource, EventMap } from "cockpit";

import { Manifests } from "../manifests";

export function generate_connection_string(user: string | null, port: string | null, addr: string) : string;
export function split_connection_string (conn_to: string) : { address: string, user?: string, port?: number };

export interface ManifestKeyword {
matches: string[];
goto?: string;
weight: number;
translate: boolean;
}

export interface ManifestDocs {
label: string;
url: string;
}

export interface ManifestEntry {
path?: string;
label?: string;
order?: number;
docs?: ManifestDocs[];
keywords?: ManifestKeyword[];
}

export interface ManifestSection {
[name: string]: ManifestEntry;
}

export interface Manifest {
[section: string]: ManifestSection;
}

export interface Manifests {
[pkg: string]: Manifest;
}

export interface Machine {
key: string;
connection_string: string;
Expand Down
5 changes: 3 additions & 2 deletions pkg/shell/machines/machines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cockpit from "cockpit";
import { import_Manifests } from "../manifests";

import ssh_add_key_sh from "../../lib/ssh-add-key.sh";

Expand Down Expand Up @@ -572,7 +573,7 @@ function Loader(machines, session_only) {
request.responseType = "json";
request.open("GET", url, true);
request.addEventListener("load", () => {
const overlay = { manifests: request.response };
const overlay = { manifests: import_Manifests(request.response) };
const etag = request.getResponseHeader("ETag");
if (etag) /* and remove quotes */
overlay.checksum = etag.replace(/^"(.+)"$/, '$1');
Expand Down Expand Up @@ -610,7 +611,7 @@ function Loader(machines, session_only) {
if (args[0] == "cockpit.Packages") {
if (args[1].Manifests) {
const manifests = JSON.parse(args[1].Manifests.v);
machines.overlay(host, { manifests });
machines.overlay(host, { manifests: import_Manifests(manifests) });
}
}
});
Expand Down
78 changes: 78 additions & 0 deletions pkg/shell/manifests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of Cockpit.
*
* Copyright (C) 2024 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <https://www.gnu.org/licenses/>.
*/

import { JsonValue } from "cockpit";

export interface ManifestKeyword {
matches: string[];
goto?: string;
weight?: number;
translate?: boolean;
}

export interface ManifestDocs {
label: string;
url: string;
}

export interface ManifestEntry {
path?: string;
label?: string;
order?: number;
docs?: ManifestDocs[];
keywords?: ManifestKeyword[];
}

export interface ManifestSection {
[name: string]: ManifestEntry;
}

export interface ManifestParentSection {
component?: string;
docs?: ManifestDocs[];
}

export interface Manifest {
dashboard?: ManifestSection;
menu?: ManifestSection;
tools?: ManifestSection;

preload?: string[];
parent?: ManifestParentSection;
".checksum"?: string;
}

export interface Manifests {
[pkg: string]: Manifest;
}

export function import_Manifests(val: JsonValue): Manifests {
// TODO - validate against schema
martinpitt marked this conversation as resolved.
Show resolved Hide resolved
return val as unknown as Manifests;
}

export interface ShellManifest {
docs?: ManifestDocs[];
locales?: { [id: string]: string };
}

export function import_ShellManifest(val: JsonValue): ShellManifest {
// TODO - validate against schema
return val as unknown as ShellManifest;
}
Loading
Loading