LCOV - code coverage report
Current view: top level - pkg/packagekit - utils.tsx Coverage Total Hit
Test: cockpit Lines: 60.5 % 38 23
Test Date: 2026-07-13 10:00:01

            Line data    Source code
       1              : // SPDX-License-Identifier: LGPL-2.1-or-later
       2           19 : import cockpit from "cockpit";
       3              : 
       4           18 : export function debug(...args: unknown[]) {
       5            3 :     if (window.debugging == 'all' || window.debugging?.includes('packagekit'))
       6            3 :         console.debug('packagekit:', ...args);
       7           18 : }
       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           18 : export function watchRedHatSubscription(callback: (registered: boolean) => void) {
      19           18 :     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           18 :     sm.call("/com/redhat/RHSM1/Products", "com.redhat.RHSM1.Products", "ListInstalledProducts", ["", {}, ""])
      34           18 :             .then(([reply]) => {
      35           18 :                 const result = reply as string;
      36           18 :                 const products = JSON.parse(result);
      37           18 :                 if (products.length === 0)
      38           18 :                     return;
      39              : 
      40              :                 // check if this is an unregistered RHEL system
      41            2 :                 sm.subscribe(
      42            2 :                     {
      43            2 :                         path: "/com/redhat/RHSM1/Entitlement",
      44            2 :                         interface: "com.redhat.RHSM1.Entitlement",
      45            2 :                         member: "EntitlementChanged"
      46            2 :                     },
      47            0 :                     () => check()
      48            2 :                 );
      49              : 
      50            2 :                 check();
      51           18 :             })
      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           18 : }
        

Generated by: LCOV version 2.0-1