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

Commit

Permalink
Address changes in review
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-ol committed May 2, 2017
1 parent 6d6b411 commit 3423948
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/snaptel/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var (
Subcommands: []cli.Command{
{
Name: "load",
Usage: "load <plugin_path>",
Usage: "load <plugin_path> [--plugin-cert=<plugin_cert_path> --plugin-key=<plugin_key_path>]",
Action: loadPlugin,
Flags: []cli.Flag{
flPluginAsc,
Expand All @@ -116,7 +116,7 @@ var (
},
{
Name: "swap",
Usage: "swap <load_plugin_path> <unload_plugin_type>:<unload_plugin_name>:<unload_plugin_version> or swap <load_plugin_path> -t <unload_plugin_type> -n <unload_plugin_name> -v <unload_plugin_version>",
Usage: "swap <load_plugin_path> <unload_plugin_type>:<unload_plugin_name>:<unload_plugin_version> or swap <load_plugin_path> -t <unload_plugin_type> -n <unload_plugin_name> -v <unload_plugin_version> [--plugin-cert=<plugin_cert_path> --plugin-key=<plugin_key_path>]",
Action: swapPlugins,
Flags: []cli.Flag{
flPluginAsc,
Expand Down
16 changes: 10 additions & 6 deletions cmd/snaptel/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"text/tabwriter"
"time"

"github.com/intelsdi-x/snap/mgmt/rest/v1"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -210,25 +211,28 @@ func listPlugins(ctx *cli.Context) error {
func storeTLSPaths(ctx *cli.Context, paths []string) ([]string, error) {
pCert := ctx.String("plugin-cert")
pKey := ctx.String("plugin-key")
if pCert != pKey && (pCert == "" || pKey == "") {
return paths, fmt.Errorf("Error processing plugin TLS arguments - one of (certificate, key) arguments is missing")
}
if pCert != "" {
tmpFile, err := ioutil.TempFile("", "crt.")
tmpFile, err := ioutil.TempFile("", v1.TLSCertPrefix)
if err != nil {
return paths, fmt.Errorf("Error processing plugin certificate - unable to create link:\n%v", err.Error())
return paths, fmt.Errorf("Error processing plugin TLS certificate - unable to create link:\n%v", err.Error())
}
_, err = tmpFile.WriteString(pCert)
if err != nil {
return paths, fmt.Errorf("Error processing plugin certificate - unable to write link:\n%v", err.Error())
return paths, fmt.Errorf("Error processing plugin TLS certificate - unable to write link:\n%v", err.Error())
}
paths = append(paths, tmpFile.Name())
}
if pKey != "" {
tmpFile, err := ioutil.TempFile("", "key.")
tmpFile, err := ioutil.TempFile("", v1.TLSKeyPrefix)
if err != nil {
return paths, fmt.Errorf("Error processing plugin key - unable to create link:\n%v", err.Error())
return paths, fmt.Errorf("Error processing plugin TLS key - unable to create link:\n%v", err.Error())
}
_, err = tmpFile.WriteString(pKey)
if err != nil {
return paths, fmt.Errorf("Error processing plugin key - unable to write link:\n%v", err.Error())
return paths, fmt.Errorf("Error processing plugin TLS key - unable to write link:\n%v", err.Error())
}
paths = append(paths, tmpFile.Name())
}
Expand Down
2 changes: 1 addition & 1 deletion control/available_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
)

const (
// DefaultClientTimeout - default timeout for a client connection attempt
// DefaultClientTimeout - default timeout for RPC method completion
DefaultClientTimeout = time.Second * 10
// DefaultHealthCheckTimeout - default timeout for a health check
DefaultHealthCheckTimeout = time.Second * 10
Expand Down
2 changes: 1 addition & 1 deletion control/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (a Arg) SetTLSEnabled(tlsEnabled bool) Arg {
return a
}

//
// NewArg returns new plugin arguments structure
func NewArg(logLevel int, pprof bool) Arg {
return Arg{
LogLevel: log.Level(logLevel),
Expand Down
3 changes: 2 additions & 1 deletion mgmt/rest/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

"github.com/asaskevich/govalidator"

"github.com/intelsdi-x/snap/mgmt/rest/v1"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

Expand Down Expand Up @@ -318,7 +319,7 @@ func (c *Client) pluginUploadRequest(pluginPaths []string) (*rbody.APIResponse,
defer file.Close()
bufin := bufio.NewReader(file)
bufins = append(bufins, bufin)
if baseName := filepath.Base(pluginPath); strings.HasPrefix(baseName, "crt.") || strings.HasPrefix(baseName, "key.") {
if baseName := filepath.Base(pluginPath); strings.HasPrefix(baseName, v1.TLSCertPrefix) || strings.HasPrefix(baseName, v1.TLSKeyPrefix) {
defer os.Remove(pluginPath)
}
paths = append(paths, filepath.Base(pluginPath))
Expand Down
5 changes: 5 additions & 0 deletions mgmt/rest/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
)

const (
// TLSCertPrefix defines a prefix for file fragment carrying path to TLS certificate
TLSCertPrefix = "crt."
// TLSKeyPrefix defines a prefix for file fragment carrying path to TLS private key
TLSKeyPrefix = "key."

version = "v1"
prefix = "/" + version
)
Expand Down
4 changes: 2 additions & 2 deletions mgmt/rest/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ func (s *apiV1) loadPlugin(w http.ResponseWriter, r *http.Request, _ httprouter.
case i < 4:
if filepath.Ext(p.FileName()) == ".asc" {
signature = b
} else if strings.HasPrefix(p.FileName(), "crt.") {
} else if strings.HasPrefix(p.FileName(), TLSCertPrefix) {
certPath = string(b)
if _, err := os.Stat(certPath); os.IsNotExist(err) {
e := errors.New("Error: given certificate file is not available")
rbody.Write(500, rbody.FromError(e), w)
return
}
} else if strings.HasPrefix(p.FileName(), "key.") {
} else if strings.HasPrefix(p.FileName(), TLSKeyPrefix) {
keyPath = string(b)
if _, err := os.Stat(keyPath); os.IsNotExist(err) {
e := errors.New("Error: given key file is not available")
Expand Down

0 comments on commit 3423948

Please sign in to comment.