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

feat: Added levels of connectivity to connect command #179

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

Conversation

jirihnidek
Copy link
Contributor

@jirihnidek jirihnidek commented Dec 9, 2024

  • Card ID: CCT-1005
  • First step of levels of connectivity
  • When connect command is used, then it is possible to
    enabled or disable three features using command line
    options --enable-feature or --disable-feature. Following
    features are supported
    • content
    • analytics
    • remote-management
  • Added checks for allowed combination of CLI options
  • Modified UI little bit to be able to visualize that
    feature was not started
  • Output to JSON format is still supported
  • When machine readable format is used, then add information
    about enabled/disabled content to generated JSON file
  • When machine readable output is used, then list of
    enabled/disable features is added to the generated JSON doc
  • Unified UI for colorful and not colorful mode
  • Changed UI for disconnect command to looks similar to connect command
  • Connecting looks like this in interactive mode:
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [✓] This system is already connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

* Card ID: CCT-1005
* First step of levels of connectivity
* When connect command is used, then it is possible to
  enabled or disable three features using command line
  options --enable-feature or --disable-feature. Following
  features are supported
  - content
  - analytics
  - remote-mamanagement
* Added checks for allowed combination of CLI options
* Modified UI little bit to be able to visualize that
  feature was not started
* Output to JSON format is still supported
* Card ID: CCT-1005
* When machine readable format is used, then add information
  about enabled/disabled content to generated JSON file
@jirihnidek
Copy link
Contributor Author

jirihnidek commented Dec 9, 2024

Open question:

  • How should we list enabled/disabled features in generated JSON document?
  • Current output looks like this:
{
    "hostname": "localhost",
    "uid": 0,
    "enabled_features": [
        "analytics",
        "remote-management"
    ],
    "disabled_features": [
        "content"
    ],
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

Another possible solution could be following:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "enabled": [
            "analytics",
            "remote-management"
        ],
        "disabled": [
            "content"
        ],
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

Or we can introduce something like this. This has potential to add there more attributes in the future:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "content": {
            "enabled": false,
        },
        "analytics": {
            "enabled": true,
        },
        "remote-management": {
            "enabled": true,
        },
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

TODO:

  • Allow to enabled/disable features in interactive mode, when user has to input username & password (this should be part of another PR)

* Card ID: CCT-1005
* When machine readable output is used (JSON format), then
  include list of enabled and list of disabled features
  in JSON document
Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

The patch seems solid. I won't comment much on the code itself; we'll likely see further changes done in near future as we stabilize it before new features come.

The output seems to jump around, were the two spaces intentional?

$ rhc connect --disable-feature analytics
...
 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
 [ ] Analytics ... Connecting to Red Hat Insights disabled
  [✓] Remote Management ... Activated the yggdrasil service

When disconnecting, Insights reported status 1 even though we should have detected we're (already) unregistered:

 [✓] Deactivated the yggdrasil service
 [𐄂] Cannot disconnect from Red Hat Insights: exit status 1
 [✓] Disconnected from Red Hat Subscription Management

The same goes for disconnection: with nothing connected in the first place, the output doesn't say yggdrasil wasn't enabled in the first place. That's a non-blocking note, but it feels strange.

$ rhc connect --enable-feature remote-management --disable-feature remote-management
cannot enable feature: "remote-management": feature "remote-management" explicitly disabled

Are we able to display something prettier and more human-understandable? Non-blocking note, may be addressed later.

if uiSettings.isMachineReadable {
connectResult.EnabledFeatures = append(connectResult.EnabledFeatures, feature.ID)
}
featuresStr = append(featuresStr, "["+symbolOK+"]"+feature.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a space between the checkbox and the text.

if uiSettings.isMachineReadable {
connectResult.DisabledFeatures = append(connectResult.EnabledFeatures, feature.ID)
}
featuresStr = append(featuresStr, "[ ]"+feature.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a space between the checkbox and the text.

@m-horky
Copy link
Contributor

m-horky commented Dec 17, 2024

Or we can introduce something like this. This has potential to add there more attributes in the future:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "content": {
            "enabled": false,
        },
        "analytics": {
            "enabled": true,
        },
        "remote-management": {
            "enabled": true,
        },
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

I like the nested approach. Would it make sense to move the _connected, _enabled keys into the features map?

"features": {
  "content": {
    "enabled": true,
    "connected": true,
  },
  "analytics": {
    "enabled": true,
    "connected": false,
  },
  ...
}

Copy link
Collaborator

@subpop subpop left a comment

Choose a reason for hiding this comment

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

One small change I think we can make. I will test the behavior of this branch and follow up with another review.

Comment on lines +136 to +141
var enabledContentStr string
if enableContent {
enabledContentStr = "true"
} else {
enabledContentStr = "false"
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this could be simplified into a single Sprintf statement, using the Stringer implementation of the bool type.

Suggested change
var enabledContentStr string
if enableContent {
enabledContentStr = "true"
} else {
enabledContentStr = "false"
}
enableContentStr := fmt.Sprintf("%v", enableContent)

@@ -157,6 +157,16 @@ func main() {
Usage: "register with `KEY`",
Aliases: []string{"a"},
},
&cli.StringSliceFlag{
Name: "enable-feature",
Usage: "enable feature during connection",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using the backtick notation in the usage string will encode it in help output,
making the output consistent with other, existing flags.

Suggested change
Usage: "enable feature during connection",
Usage: "enable `FEATURE` during connection",

},
&cli.StringSliceFlag{
Name: "disable-feature",
Usage: "disable feature during connection",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Usage: "disable feature during connection",
Usage: "disable `FEATURE` during connection",

if err := privConn.Object(
"com.redhat.RHSM1",
"/com/redhat/RHSM1/Register").Call(
"com.redhat.RHSM1.Register.RegisterWithActivationKeys",
dbus.Flags(0),
orgID,
activationKeys,
map[string]string{},
map[string]string{"enable_content": enabledContentStr},
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I try to register with my activation key, I get the following error:

[link@lima-rhel-10 rhc]$ sudo ./builddir/rhc connect -o 12671438 -a developer
Connecting lima-rhel-10 to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [𐄂] Cannot connect to Red Hat Subscription Management
  [𐄂] Skipping generation of Red Hat repository file
  [𐄂] Skipping connection to Red Hat Insights
  [𐄂] Skipping activation of yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

The following errors were encountered during connect:

TYPE   STEP  ERROR
ERROR  rhsm  cannot connect to Red Hat Subscription Management: error: Unknown arguments: dict_keys(['enable_content'])

Does the D-Bus method RegisterWithActivationKeys not accept 'enable_content' as
a parameter option? If so, does this mean that we cannot opt out of content if
registering with an activation key?

connectResult.InsightsConnected = true
interactivePrintf("%v Connected to Red Hat Insights\n", uiSettings.iconOK)
start = time.Now()
err = showProgress(" Connecting to Red Hat Insights...", registerInsights)
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the introduction of the space-indented results printout in the interactive
mode, the in-progress spinner looks awkward.

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
 / Connecting to Red Hat Insights...

Can we put that spinner inside brackets too? That can reduce the bouncing back
and forth as new lines are printed.

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [/] Connecting to Red Hat Insights...

durations[ServiceName] = time.Since(start)
interactivePrintf("\nSuccessfully connected to Red Hat!\n")
} else {
interactivePrintf(" [ ] Management .... Starting %s service disabled\n", ServiceName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I disabled the 'remote-management' feature, it looks like the space-indents
were missing one:

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
 [ ] Management .... Starting yggdrasil service disabled

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.

3 participants