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: Remove the RHC Manager status from rhc client #149

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"text/tabwriter"
Expand All @@ -14,7 +13,6 @@ import (
"golang.org/x/term"

"github.com/briandowns/spinner"
"github.com/redhatinsights/rhc/internal/http"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
Expand Down Expand Up @@ -124,55 +122,6 @@ func showErrorMessages(action string, errorMessages map[string]LogMessage) error
return nil
}

// getConfProfile will retrieve the profile the system is configured
func getConfProfile(client *http.Client) (map[string]interface{}, error) {
var profile map[string]interface{}

url, err := GuessAPIURL()
if err != nil {
return nil, err
}

res, err := client.Get(url)
if err != nil {
return nil, err
}
defer res.Body.Close()

if res.StatusCode != 200 {
return nil, fmt.Errorf("cannot get system profile: %s", res.Status)
}
// Read the response body
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if err = json.Unmarshal(body, &profile); err != nil {
return nil, fmt.Errorf("cannot unmarshal profile: %s", res.Status)

}

return profile, nil
}

// showConfProfile shows a list of the system profile enabled features gathered from API
// https://github.com/RedHatInsights/config-manager/blob/master/internal/http/v2/openapi.json
func showConfProfile(p *map[string]interface{}) {
services := []string{}
for service, status := range *p {
switch status.(type) {
case bool:
if service == "active" {
service = "remote configuration"
}
services = append(services, service)
}
}
output := strings.Join(services, `, `)
fmt.Printf("%v", output)
}

// registerRHSM tries to register system against Red Hat Subscription Management server (candlepin server)
func registerRHSM(ctx *cli.Context) (string, error) {
uuid, err := getConsumerUUID()
Expand Down Expand Up @@ -424,42 +373,6 @@ func connectAction(ctx *cli.Context) error {
interactivePrintf("%v Activated the %v service\n", uiSettings.iconOK, ServiceName)
}
durations[ServiceName] = time.Since(start)
}

/* 4. Show Configuration Profile */
if len(errorMessages) == 0 {
// Update the configuration file
// Call D-bus to get the CA directory from rhsm
if err = getRHSMConfigOption("rhsm.ca_cert_dir", &config.CADir); err != nil {
errorMessages[ServiceName] = LogMessage{
level: log.LevelWarn,
message: fmt.Errorf("cannot get rhsm configuration: %w",
err)}
}
// Generate a new http client configured with mutual TLS certificate
tlsConfig, err := config.CreateTLSClientConfig()
if err != nil {
errorMessages[ServiceName] = LogMessage{
level: log.LevelWarn,
message: fmt.Errorf("cannot configure TLS: %w",
err)}
}
client := http.NewHTTPClient(tlsConfig)

// Get the user profile
profile, err := getConfProfile(client)
if err != nil {
errorMessages[ServiceName] = LogMessage{
level: log.LevelWarn,
message: fmt.Errorf("cannot get the user profile: %w",
err)}
} else {
if !uiSettings.isMachineReadable {
fmt.Printf("%v Enabled console.redhat.com services: ", uiSettings.iconInfo)
showConfProfile(&profile)
fmt.Printf("\n")
}
}
interactivePrintf("\nSuccessfully connected to Red Hat!\n")
}

Expand Down
Loading