Skip to content

Commit c48d561

Browse files
committed
Remove not used to debug option
Signed-off-by: Petr Kotas <[email protected]>
1 parent 656441f commit c48d561

File tree

2 files changed

+2
-64
lines changed

2 files changed

+2
-64
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package investigate
1919
import (
2020
"fmt"
2121
"os"
22-
"path/filepath"
2322
"strconv"
2423
"strings"
2524

@@ -111,7 +110,7 @@ func run(cmd *cobra.Command, _ []string) error {
111110
return err
112111
}
113112

114-
ocmClient, err := GetOCMClient()
113+
ocmClient, err := ocm.New()
115114
if err != nil {
116115
return fmt.Errorf("could not initialize ocm client: %w", err)
117116
}
@@ -191,22 +190,6 @@ func handleCADFailure(err error, resources *investigation.Resources, pdClient *p
191190
}
192191
}
193192

194-
// GetOCMClient will retrieve the OcmClient from the 'ocm' package
195-
func GetOCMClient() (*ocm.SdkClient, error) {
196-
cadOcmFilePath := os.Getenv("CAD_OCM_FILE_PATH")
197-
198-
_, err := os.Stat(cadOcmFilePath)
199-
if os.IsNotExist(err) {
200-
configDir, err := os.UserConfigDir()
201-
if err != nil {
202-
return nil, err
203-
}
204-
cadOcmFilePath = filepath.Join(configDir, "/ocm/ocm.json")
205-
}
206-
207-
return ocm.New(cadOcmFilePath)
208-
}
209-
210193
// Checks pre-requisites for a cluster investigation:
211194
// - the cluster's state is supported by CAD for an investigation (= not uninstalling)
212195
// - the cloud provider is supported by CAD (cluster is AWS)

pkg/ocm/ocm.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"net/http"
99
"os"
10-
"strconv"
1110
"strings"
1211

1312
sdk "github.com/openshift-online/ocm-sdk-go"
@@ -57,34 +56,10 @@ type SdkClient struct {
5756

5857
// New will create a new ocm client by using the path to a config file
5958
// if no path is provided, it will assume it in the default path
60-
func New(ocmConfigFile string) (*SdkClient, error) {
59+
func New() (*SdkClient, error) {
6160
var err error
6261
client := SdkClient{}
6362

64-
// The debug environment variable ensures that we will never use
65-
// an ocm config file on a cluster deployment. The debug environment variable
66-
// is only for local cadctl development
67-
debugMode := os.Getenv("CAD_DEBUG")
68-
69-
// strconv.ParseBool raises an error when debugMode is empty, thus
70-
// we have to set it to false if the value is empty.
71-
if debugMode == "" {
72-
debugMode = "false"
73-
}
74-
75-
debugEnabled, err := strconv.ParseBool(debugMode)
76-
if err != nil {
77-
return nil, fmt.Errorf("failed to parse CAD_DEBUG value '%s': %w", debugMode, err)
78-
}
79-
80-
if debugEnabled {
81-
client.conn, err = newConnectionFromFile(ocmConfigFile)
82-
if err != nil {
83-
return nil, fmt.Errorf("failed to create connection from ocm.json config file: %w", err)
84-
}
85-
return &client, nil
86-
}
87-
8863
client.conn, err = newConnectionFromClientPair()
8964
if err != nil {
9065
return nil, fmt.Errorf("failed to create connection from client key pair: %w", err)
@@ -93,26 +68,6 @@ func New(ocmConfigFile string) (*SdkClient, error) {
9368
return &client, nil
9469
}
9570

96-
// newConnectionFromFile loads the configuration file (ocmConfigFile, ~/.ocm.json, /ocm/ocm.json)
97-
// and creates a connection.
98-
func newConnectionFromFile(ocmConfigFile string) (*sdk.Connection, error) {
99-
if ocmConfigFile != "" {
100-
err := os.Setenv("OCM_CONFIG", ocmConfigFile)
101-
if err != nil {
102-
return nil, err
103-
}
104-
}
105-
// Load the configuration file from std path
106-
cfg, err := Load()
107-
if err != nil {
108-
return nil, err
109-
}
110-
if cfg == nil || cfg == (&Config{}) {
111-
return nil, fmt.Errorf("not logged in")
112-
}
113-
return cfg.Connection()
114-
}
115-
11671
// newConnectionFromClientPair creates a new connection via set of client ID, client secret
11772
// and the target OCM API URL.
11873
func newConnectionFromClientPair() (*sdk.Connection, error) {

0 commit comments

Comments
 (0)