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

Commit 5bf1023

Browse files
author
Mateusz Kleina
authored
Merge pull request #8 from mkleina/standalone-v2
Add support for standalone plugins
2 parents af85fe2 + 02295e8 commit 5bf1023

1 file changed

Lines changed: 37 additions & 22 deletions

File tree

snaptel/plugin.go

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package snaptel
2121

2222
import (
2323
"fmt"
24+
"net/url"
2425
"os"
2526
"path/filepath"
2627
"strconv"
@@ -29,37 +30,51 @@ import (
2930
"time"
3031

3132
"github.com/intelsdi-x/snap-client-go/client/plugins"
33+
"github.com/intelsdi-x/snap-client-go/models"
3234
"github.com/urfave/cli"
3335
)
3436

3537
func loadPlugin(ctx *cli.Context) error {
36-
pAsc := ctx.String("plugin-asc")
37-
var paths []string
38-
if len(ctx.Args()) != 1 {
39-
return newUsageError("Incorrect usage:", ctx)
40-
}
41-
paths = append(paths, ctx.Args().First())
42-
if pAsc != "" {
43-
if !strings.Contains(pAsc, ".asc") {
44-
return newUsageError("Must be a .asc file for the -a flag", ctx)
38+
var p *models.Plugin
39+
if _, err := url.ParseRequestURI(ctx.Args().First()); err != nil {
40+
pAsc := ctx.String("plugin-asc")
41+
var paths []string
42+
if len(ctx.Args()) != 1 {
43+
return newUsageError("Incorrect usage:", ctx)
44+
}
45+
paths = append(paths, ctx.Args().First())
46+
if pAsc != "" {
47+
if !strings.Contains(pAsc, ".asc") {
48+
return newUsageError("Must be a .asc file for the -a flag", ctx)
49+
}
50+
paths = append(paths, pAsc)
4551
}
46-
paths = append(paths, pAsc)
47-
}
4852

49-
params := plugins.NewLoadPluginParamsWithTimeout(FlTimeout.Value)
50-
f, err := os.Open(filepath.Join(paths...))
51-
if err != nil {
52-
return newUsageError("Cannot open the plugin", ctx)
53-
}
54-
defer f.Close()
55-
params.SetPluginData(f)
53+
params := plugins.NewLoadPluginParamsWithTimeout(FlTimeout.Value)
54+
f, err := os.Open(filepath.Join(paths...))
55+
if err != nil {
56+
return newUsageError("Cannot open the plugin", ctx)
57+
}
58+
defer f.Close()
59+
params.SetPluginData(f)
5660

57-
resp, err := client.Plugins.LoadPlugin(params, authInfoWriter)
58-
if err != nil {
59-
return getErrorDetail(err, ctx)
61+
resp, err := client.Plugins.LoadPlugin(params, authInfoWriter)
62+
if err != nil {
63+
return getErrorDetail(err, ctx)
64+
}
65+
p = resp.Payload
66+
} else {
67+
params := plugins.NewLoadPluginParamsWithTimeout(FlTimeout.Value)
68+
pluginURI := ctx.Args().First()
69+
params.SetPluginURI(&pluginURI)
70+
71+
resp, err := client.Plugins.LoadPlugin(params, authInfoWriter)
72+
if err != nil {
73+
return getErrorDetail(err, ctx)
74+
}
75+
p = resp.Payload
6076
}
6177

62-
p := resp.Payload
6378
fmt.Println("Plugin loaded")
6479
fmt.Printf("Name: %s\n", p.Name)
6580
fmt.Printf("Version: %d\n", p.Version)

0 commit comments

Comments
 (0)