| ... | ... |
@@ -243,6 +243,9 @@ echo "templates: ok" |
| 243 | 243 |
[ "$(openshift cli get 2>&1 | grep 'you must provide one or more resources')" ] |
| 244 | 244 |
[ "$(openshift kubectl get 2>&1 | grep 'you must provide one or more resources')" ] |
| 245 | 245 |
|
| 246 |
+# commands that expect file paths must validate and error out correctly |
|
| 247 |
+[ "$(osc login --certificate-authority=/path/to/invalid 2>&1 | grep 'no such file or directory')" ] |
|
| 248 |
+ |
|
| 246 | 249 |
osc get pods --match-server-version |
| 247 | 250 |
osc create -f examples/hello-openshift/hello-pod.json |
| 248 | 251 |
osc describe pod hello-openshift |
| ... | ... |
@@ -91,14 +91,12 @@ func (o *LoginOptions) gatherServerInfo() error {
|
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
// we know the server we are expected to use |
| 94 |
- |
|
| 95 | 94 |
clientCfg, err := o.ClientConfig.ClientConfig() |
| 96 | 95 |
if err != nil {
|
| 97 | 96 |
return err |
| 98 | 97 |
} |
| 99 | 98 |
|
| 100 | 99 |
// ping to check if server is reachable |
| 101 |
- |
|
| 102 | 100 |
osClient, err := client.New(clientCfg) |
| 103 | 101 |
if err != nil {
|
| 104 | 102 |
return err |
| ... | ... |
@@ -117,6 +115,8 @@ func (o *LoginOptions) gatherServerInfo() error {
|
| 117 | 117 |
return fmt.Errorf(clientcmd.GetPrettyMessageFor(result.Error())) |
| 118 | 118 |
} |
| 119 | 119 |
fmt.Println() |
| 120 |
+ } else {
|
|
| 121 |
+ return result.Error() |
|
| 120 | 122 |
} |
| 121 | 123 |
} |
| 122 | 124 |
|
| ... | ... |
@@ -11,6 +11,7 @@ const ( |
| 11 | 11 |
unknownReason = 0 |
| 12 | 12 |
noServerFoundReason = 1 |
| 13 | 13 |
certificateAuthorityUnknownReason = 2 |
| 14 |
+ configurationInvalidReason = 3 |
|
| 14 | 15 |
|
| 15 | 16 |
certificateAuthorityUnknownMsg = "The server uses a certificate signed by unknown authority. You may need to use the --certificate-authority flag to provide the path to a certificate file for the certificate authority, or --insecure-skip-tls-verify to bypass the certificate check and use insecure connections." |
| 16 | 17 |
notConfiguredMsg = `OpenShift is not configured. You need to run the login command in order to create a default config for your server and credentials: |
| ... | ... |
@@ -41,6 +42,10 @@ func IsNoServerFound(err error) bool {
|
| 41 | 41 |
return detectReason(err) == noServerFoundReason |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
+func IsConfigurationInvalid(err error) bool {
|
|
| 45 |
+ return detectReason(err) == configurationInvalidReason |
|
| 46 |
+} |
|
| 47 |
+ |
|
| 44 | 48 |
func IsCertificateAuthorityUnknown(err error) bool {
|
| 45 | 49 |
return detectReason(err) == certificateAuthorityUnknownReason |
| 46 | 50 |
} |
| ... | ... |
@@ -54,8 +59,10 @@ func detectReason(err error) int {
|
| 54 | 54 |
switch {
|
| 55 | 55 |
case strings.Contains(err.Error(), "certificate signed by unknown authority"): |
| 56 | 56 |
return certificateAuthorityUnknownReason |
| 57 |
- case clientcmd.IsConfigurationInvalid(err), strings.Contains(err.Error(), "no server found for"): |
|
| 57 |
+ case strings.Contains(err.Error(), "no server defined"): |
|
| 58 | 58 |
return noServerFoundReason |
| 59 |
+ case clientcmd.IsConfigurationInvalid(err): |
|
| 60 |
+ return configurationInvalidReason |
|
| 59 | 61 |
} |
| 60 | 62 |
} |
| 61 | 63 |
return unknownReason |