Line data Source code
1 : // SPDX-License-Identifier: LGPL-2.1-or-later
2 1 : import cockpit from "cockpit";
3 :
4 1 : export function debug(...args: unknown[]) {
5 1 : if (window.debugging == 'all' || window.debugging?.includes('packagekit'))
6 1 : console.debug('packagekit:', ...args);
7 1 : }
8 :
9 : /**
10 : * Check Red Hat subscription-manager if if this is an unregistered RHEL
11 : * system. If subscription-manager is not installed or required (not a
12 : * Red Hat product), nothing happens.
13 : *
14 : * callback: Called with a boolean (true: registered, false: not registered)
15 : * after querying subscription-manager once, and whenever the value
16 : * changes.
17 : */
18 0 : export function watchRedHatSubscription(callback: (registered: boolean) => void) {
19 0 : const sm = cockpit.dbus("com.redhat.RHSM1");
20 :
21 0 : function check() {
22 0 : sm.call(
23 0 : "/com/redhat/RHSM1/Entitlement", "com.redhat.RHSM1.Entitlement", "GetStatus", ["", ""])
24 0 : .then(([reply]) => {
25 0 : const result = reply as string;
26 0 : const status = JSON.parse(result);
27 0 : callback(status.valid);
28 0 : })
29 0 : .catch(ex => console.warn("Failed to query RHEL subscription status:", JSON.stringify(ex)));
30 0 : }
31 :
32 : // check if subscription is required on this system, i.e. whether there are any installed products
33 0 : sm.call("/com/redhat/RHSM1/Products", "com.redhat.RHSM1.Products", "ListInstalledProducts", ["", {}, ""])
34 0 : .then(([reply]) => {
35 0 : const result = reply as string;
36 0 : const products = JSON.parse(result);
37 0 : if (products.length === 0)
38 0 : return;
39 :
40 : // check if this is an unregistered RHEL system
41 0 : sm.subscribe(
42 0 : {
43 0 : path: "/com/redhat/RHSM1/Entitlement",
44 0 : interface: "com.redhat.RHSM1.Entitlement",
45 0 : member: "EntitlementChanged"
46 0 : },
47 0 : () => check()
48 0 : );
49 :
50 0 : check();
51 0 : })
52 0 : .catch(ex => {
53 0 : if (ex.problem != "not-found")
54 0 : console.warn("Failed to query RHSM products:", JSON.stringify(ex));
55 0 : });
56 0 : }
|