Skip to content

Commit

Permalink
fix: update url check
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 7, 2021
1 parent 21b0500 commit e524a64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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 = "github.com/jimil749/json"
driver = "https://github.com/jimil749/json"

[grpc.services.userprovider.drivers.json]
users = "users.demo.json"
19 changes: 15 additions & 4 deletions pkg/plugin/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"bytes"
"context"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/cs3org/reva/pkg/errtypes"
"github.com/hashicorp/go-getter"
Expand All @@ -43,8 +45,6 @@ const dirname = "/var/tmp/reva"

var isAlphaNum = regexp.MustCompile(`^[A-Za-z0-9]+$`).MatchString

var isURL = regexp.MustCompile(`^(www\.)?[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()
Expand Down Expand Up @@ -89,11 +89,12 @@ func checkDirAndCompile(pluginType, driver string) (string, error) {

// downloadPlugin downloads the plugin and stores it into local filesystem
func downloadAndCompilePlugin(pluginType, driver string) (string, error) {
driverURL := strings.TrimPrefix(driver, "https://")
destination := fmt.Sprintf("%s/ext/%s/%s", dirname, pluginType, filepath.Base(driver))
client := &getter.Client{
Ctx: context.Background(),
Dst: destination,
Src: driver,
Src: driverURL,
Mode: getter.ClientModeDir,
}
if err := client.Get(); err != nil {
Expand All @@ -108,7 +109,17 @@ 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 {
return isURL(driver)
_, 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
}

// Load loads the plugin using the hashicorp go-plugin system
Expand Down

0 comments on commit e524a64

Please sign in to comment.