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

Generalize REST/client API for multiple users #1989

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinpitt
Copy link
Member

@martinpitt martinpitt commented Feb 3, 2025

Preparation and heavy lifting for https://issues.redhat.com/browse/COCKPIT-1086 . But this PR does not yet change visible behaviour or pixels.

@martinpitt martinpitt force-pushed the generalize-isSystem branch 5 times, most recently from 96e6c60 to 89c7bd8 Compare February 5, 2025 09:56
@martinpitt

This comment was marked as resolved.

Replacing an array variable with its first entry rightfully gives us the
type check finger wagging.
Change `connnect()` and `call()` to accept a `uid` parameter instead of an
address/superuser pair. Compute the Unix address within rest.js, move
`getAddress()` from client for that. For now, just accept `0` for root
and `null` for "current cockpit user", until we actually use that.

Drop the `system` argument from `debug()`, and let the caller specify an
appropriate string. We were only calling `debug()` from rest.js so far anyway,
so that isn't very intrusive.

Keep `isSystem` for the client.js API for the time being. That will be the next
step, but let's not change everything at once.
@martinpitt
Copy link
Member Author

Yay -- that was a hard piece of work, so let's record d00421a as a milestone where everything is green. I'll commit fixups from now on. There is still some things which I don't like, such as the repeated uid ?? "user" pattern; and the higher-level states still use isSystem a lot.

@martinpitt martinpitt force-pushed the generalize-isSystem branch 3 times, most recently from 277d09e to d1f4652 Compare February 6, 2025 13:20
Similarly to the previous commit for rest.js, change the API to accept an user
id instead of an `isSystem` boolean. Change the Container, Pod, and Image
properties accordingly.

However, keep the UI logic and higher-level `isSystem` flags/helpers as-is for
now, as this is intrusive enough.

Clean up the often repeated "id + isSystem" index key calculation for
the app's containers/images/pods states, and centralize it into a
`makeKey()` helper. Put the uid in front, so that they have more natural
sorting (in the UI we sort by owner first), and add a `-` in between so
that they are easier to read.
@@ -607,7 +607,7 @@ class Containers extends React.Component {
const lcf = this.props.textFilter.toLowerCase();
filtered = filtered.filter(id => this.props.containers[id].Name.toLowerCase().indexOf(lcf) >= 0 ||
(this.props.containers[id].Pod &&
this.props.pods[this.props.containers[id].Pod + this.props.containers[id].isSystem.toString()].Name.toLowerCase().indexOf(lcf) >= 0) ||
this.props.pods[utils.makeKey(this.props.containers[id].uid, this.props.containers[id].Pod)].Name.toLowerCase().indexOf(lcf) >= 0) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

@@ -641,7 +641,7 @@ class Containers extends React.Component {
filtered.forEach(id => {
const container = this.props.containers[id];
if (container)
(partitionedContainers[container.Pod ? (container.Pod + container.isSystem.toString()) : 'no-pod'] || []).push(container);
(partitionedContainers[container.Pod ? utils.makeKey(container.uid, container.Pod) : 'no-pod'] || []).push(container);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

((this.props.ownerFilter === "system" && !pod.isSystem) ||
(this.props.ownerFilter !== "system" && pod.isSystem))))
((this.props.ownerFilter === "system" && pod.uid !== 0) ||
(this.props.ownerFilter !== "system" && pod.uid === 0))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

if (this.props.pods[a].isSystem !== this.props.pods[b].isSystem)
return this.props.pods[a].isSystem ? 1 : -1;
if (this.props.pods[a].uid !== this.props.pods[b].uid)
return this.props.pods[a].uid === 0 ? 1 : -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

@@ -667,7 +668,7 @@ export class ImageRunModal extends React.Component {

async validateContainerName(containerName) {
try {
await client.containerExists(this.isSystem(), containerName);
await client.containerExists(this.isSystem() ? 0 : null, containerName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

}
})
.catch(ex => {
console.warn("Failed to do Update Pod:", JSON.stringify(ex));
console.warn("Failed to do updatePod for uid", uid, ":", JSON.stringify(ex));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

Comment on lines +33 to +34
console.warn("$XDG_RUNTIME_DIR is not present. Cannot use user service.");
return { path: "", superuser: null };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 added lines are not executed by any test.

if (uid === 0)
return { path: PODMAN_SYSTEM_ADDRESS, superuser: "require" };

throw new Error(`getAddress: uid ${uid} not supported`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

const connection = {};
const decoder = new TextDecoder();
const user_str = (uid === null) ? "user" : (uid === 0) ? "root" : `uid ${uid}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

if (window.debugging === "all" || window.debugging?.includes("podman"))
console.debug("podman", system ? "system" : "user", ...args);
console.debug("podman", ...args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants