diff --git a/examples/plugin/json/json.go b/examples/plugin/json/json.go index a205f9fd05..356e9ac47b 100644 --- a/examples/plugin/json/json.go +++ b/examples/plugin/json/json.go @@ -27,6 +27,7 @@ import ( userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" "github.com/cs3org/reva/pkg/errtypes" + revaPlugin "github.com/cs3org/reva/pkg/plugin" "github.com/cs3org/reva/pkg/user" "github.com/hashicorp/go-plugin" "github.com/mitchellh/mapstructure" @@ -145,16 +146,9 @@ func (m *Manager) GetUserGroups(ctx context.Context, uid *userpb.UserId) ([]stri return user.Groups, nil } -// Handshake hashicorp go-plugin handshake -var Handshake = plugin.HandshakeConfig{ - ProtocolVersion: 1, - MagicCookieKey: "BASIC_PLUGIN", - MagicCookieValue: "reva", -} - func main() { plugin.Serve(&plugin.ServeConfig{ - HandshakeConfig: Handshake, + HandshakeConfig: revaPlugin.Handshake, Plugins: map[string]plugin.Plugin{ "userprovider": &user.ProviderPlugin{Impl: &Manager{}}, }, diff --git a/examples/plugin/plugin.toml b/examples/plugin/plugin.toml index 7a3ab0b961..cf392b6aa0 100644 --- a/examples/plugin/plugin.toml +++ b/examples/plugin/plugin.toml @@ -9,7 +9,7 @@ address = "0.0.0.0:19000" userprovidersvc = "localhost:19000" [grpc.services.userprovider] -driver = "git::https://github.com/jimil749/json" +driver = "/home/jimil/Desktop/reva/examples/plugin/json" [grpc.services.userprovider.drivers.json] users = "users.demo.json" diff --git a/pkg/plugin/loader.go b/pkg/plugin/loader.go index 15e4ddc60a..ec645890ce 100644 --- a/pkg/plugin/loader.go +++ b/pkg/plugin/loader.go @@ -22,7 +22,6 @@ import ( "bytes" "context" "fmt" - "net/url" "os" "os/exec" "path/filepath" @@ -43,14 +42,14 @@ type RevaPlugin struct { const dirname = "/var/tmp/reva" var isAlphaNum = regexp.MustCompile(`^[A-Za-z0-9_-]+$`).MatchString -var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`) +var isURL = regexp.MustCompile(`^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$`).MatchString // Kill kills the plugin process func (plug *RevaPlugin) Kill() { plug.Client.Kill() } -var handshake = plugin.HandshakeConfig{ +var Handshake = plugin.HandshakeConfig{ ProtocolVersion: 1, MagicCookieKey: "BASIC_PLUGIN", MagicCookieValue: "reva", @@ -108,20 +107,7 @@ func downloadAndCompilePlugin(pluginType, driver string) (string, error) { // isValidURL tests a string to determine if it is a well-structure URL func isValidURL(driver string) bool { - if driverURL := forcedRegexp.FindStringSubmatch(driver); driverURL != nil { - driver = driverURL[2] - } - _, err := url.ParseRequestURI(driver) - if err != nil { - return false - } - - u, err := url.Parse(driver) - if err != nil || u.Scheme == "" || u.Host == "" { - return false - } - - return true + return isURL(driver) } func fetchBinary(pluginType, driver string) (string, error) { @@ -158,7 +144,7 @@ func Load(pluginType, driver string) (*RevaPlugin, error) { }) client := plugin.NewClient(&plugin.ClientConfig{ - HandshakeConfig: handshake, + HandshakeConfig: Handshake, Plugins: PluginMap, Cmd: exec.Command(bin), AllowedProtocols: []plugin.Protocol{