Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 88595aa

Browse files
committed
resolved the merge conflicts and removed the fix for third party loading a plugin error
1 parent 18bac5d commit 88595aa

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

snaptel/common.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"io/ioutil"
26+
"strings"
2627

2728
"golang.org/x/crypto/ssh/terminal"
2829

@@ -129,8 +130,6 @@ func getErrorDetail(err error, ctx *cli.Context) error {
129130
return newUsageError(fmt.Sprintf("%v", err.(*plugins.GetPluginConfigItemBadRequest).Payload.ErrorMessage), ctx)
130131
case *plugins.GetPluginConfigItemUnauthorized:
131132
return newUsageError(fmt.Sprintf("%v", err.(*plugins.GetPluginConfigItemUnauthorized).Payload.Message), ctx)
132-
case *plugins.LoadPluginDefault:
133-
return newUsageError(fmt.Sprintf("%v", err.(*plugins.LoadPluginDefault).Message), ctx)
134133
case *tasks.GetTaskNotFound:
135134
return newUsageError(fmt.Sprintf("%v", err.(*tasks.GetTaskNotFound).Payload.ErrorMessage), ctx)
136135
case *tasks.GetTaskUnauthorized:
@@ -150,6 +149,9 @@ func getErrorDetail(err error, ctx *cli.Context) error {
150149
case *tasks.UpdateTaskStateUnauthorized:
151150
return newUsageError(fmt.Sprintf("%v", err.(*tasks.UpdateTaskStateUnauthorized).Payload.Message), ctx)
152151
default:
152+
if strings.Contains(err.Error(), "tls: oversized record") || strings.Contains(err.Error(), "malformed HTTP response") {
153+
return newUsageError(extractError(err.Error()), ctx)
154+
}
153155
return newUsageError(fmt.Sprintf("Error: %v", err), ctx)
154156
}
155157
}
@@ -218,3 +220,19 @@ func BasicAuth(ctx *cli.Context) runtime.ClientAuthInfoWriter {
218220
}
219221
return nil
220222
}
223+
224+
// extractError is a hack for SSL/TLS handshake error.
225+
func extractError(m string) string {
226+
ts := strings.Split(m, "\"")
227+
228+
var tss []string
229+
if len(ts) > 0 {
230+
tss = strings.Split(ts[0], "malformed")
231+
}
232+
233+
errMsg := "Error connecting to API. Do you have an http/https mismatching API request?"
234+
if len(tss) > 0 {
235+
errMsg = tss[0] + errMsg
236+
}
237+
return errMsg
238+
}

snaptel/plugin.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,46 @@ func loadPlugin(ctx *cli.Context) error {
5151
}
5252

5353
params := plugins.NewLoadPluginParamsWithTimeout(FlTimeout.Value)
54-
f, err := os.Open(filepath.Join(paths...))
54+
55+
// Sets the plugin data.
56+
f, err := os.Open(filepath.Join(paths[0]))
5557
if err != nil {
5658
return newUsageError("Cannot open the plugin", ctx)
5759
}
5860
defer f.Close()
5961
params.SetPluginData(f)
6062

63+
if !hasValidFlags(ctx.IsSet("plugin-cert"), ctx.IsSet("plugin-key")) {
64+
return newUsageError("Both plugin certification and key are mandatory.", ctx)
65+
}
66+
67+
// Sets the plugin certificate.
68+
if ctx.IsSet("plugin-cert") {
69+
pCert := ctx.String("plugin-cert")
70+
if _, err := os.Stat(pCert); os.IsNotExist(err) {
71+
return newUsageError("Cannot reach the plugin certificate", ctx)
72+
}
73+
params.SetPluginCert(&pCert)
74+
}
75+
76+
// Sets the plugin key.
77+
if ctx.IsSet("plugin-key") {
78+
pKey := ctx.String("plugin-key")
79+
if _, err := os.Stat(pKey); os.IsNotExist(err) {
80+
return newUsageError("Cannot reach the plugin key", ctx)
81+
}
82+
params.SetPluginKey(&pKey)
83+
}
84+
85+
// Sets the CA ceritificate.
86+
if ctx.IsSet("plugin-ca-certs") {
87+
caCerts := ctx.String("plugin-ca-certs")
88+
if _, err := os.Stat(caCerts); os.IsNotExist(err) {
89+
return newUsageError("Cannot reach the CA certificates", ctx)
90+
}
91+
params.SetCaCerts(&caCerts)
92+
}
93+
6194
resp, err := client.Plugins.LoadPlugin(params, authInfoWriter)
6295
if err != nil {
6396
return getErrorDetail(err, ctx)
@@ -176,7 +209,7 @@ func hasValidFlags(key, cert bool) bool {
176209
return true
177210
}
178211

179-
// Don't block normal flow which has not certs at all.
212+
// Don't block normal flow which has no certs at all.
180213
if !key && !cert {
181214
return true
182215
}

0 commit comments

Comments
 (0)