Skip to content

Commit

Permalink
update URL check and make handshake-config global
Browse files Browse the repository at this point in the history
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
  • Loading branch information
jimil749 committed Aug 25, 2021
1 parent b0bd1e2 commit 13ac310
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
10 changes: 2 additions & 8 deletions examples/plugin/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
22 changes: 4 additions & 18 deletions pkg/plugin/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"bytes"
"context"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 13ac310

Please sign in to comment.