| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
import cockpit from "cockpit"; |
| 3 |
|
| 4 |
export function debug(...args: unknown[]) { |
| 5 |
if (window.debugging == 'all' || window.debugging?.includes('packagekit')) |
| 6 |
console.debug('packagekit:', ...args); |
| 7 |
} |
| 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 |
export function watchRedHatSubscription(callback: (registered: boolean) => void) { |
| 19 |
const sm = cockpit.dbus("com.redhat.RHSM1"); |
| 20 |
|
| 21 |
function check() { |
| 22 |
sm.call( |
| 23 |
"/com/redhat/RHSM1/Entitlement", "com.redhat.RHSM1.Entitlement", "GetStatus", ["", ""]) |
| 24 |
.then(([reply]) => { |
| 25 |
const result = reply as string; |
| 26 |
const status = JSON.parse(result); |
| 27 |
callback(status.valid); |
| 28 |
}) |
| 29 |
.catch(ex => console.warn("Failed to query RHEL subscription status:", JSON.stringify(ex))); |
| 30 |
} |
| 31 |
|
| 32 |
// check if subscription is required on this system, i.e. whether there are any installed products |
| 33 |
sm.call("/com/redhat/RHSM1/Products", "com.redhat.RHSM1.Products", "ListInstalledProducts", ["", {}, ""]) |
| 34 |
.then(([reply]) => { |
| 35 |
const result = reply as string; |
| 36 |
const products = JSON.parse(result); |
| 37 |
if (products.length === 0) |
| 38 |
return; |
| 39 |
|
| 40 |
// check if this is an unregistered RHEL system |
| 41 |
sm.subscribe( |
| 42 |
{ |
| 43 |
path: "/com/redhat/RHSM1/Entitlement", |
| 44 |
interface: "com.redhat.RHSM1.Entitlement", |
| 45 |
member: "EntitlementChanged" |
| 46 |
}, |
| 47 |
() => check() |
| 48 |
); |
| 49 |
|
| 50 |
check(); |
| 51 |
}) |
| 52 |
.catch(ex => { |
| 53 |
if (ex.problem != "not-found") |
| 54 |
console.warn("Failed to query RHSM products:", JSON.stringify(ex)); |
| 55 |
}); |
| 56 |
} |