zrok/drives/sync/target.go

35 lines
901 B
Go
Raw Normal View History

2024-01-10 20:35:27 +01:00
package sync
import (
"github.com/openziti/zrok/environment/env_core"
"github.com/pkg/errors"
"net/url"
"strings"
2024-01-10 20:35:27 +01:00
)
func TargetForURL(url *url.URL, root env_core.Root, basicAuth string) (Target, error) {
2024-01-10 20:35:27 +01:00
switch url.Scheme {
case "file":
return NewFilesystemTarget(&FilesystemTargetConfig{Root: url.Path}), nil
case "zrok":
return NewZrokTarget(&ZrokTargetConfig{URL: url, Root: root})
case "http", "https":
var username string
var password string
if basicAuth != "" {
authTokens := strings.Split(basicAuth, ":")
if len(authTokens) != 2 {
return nil, errors.Errorf("invalid basic authentication (expect 'username:password')")
}
username = authTokens[0]
password = authTokens[1]
}
return NewWebDAVTarget(&WebDAVTargetConfig{URL: url, Username: username, Password: password})
2024-01-10 20:35:27 +01:00
default:
return nil, errors.Errorf("unknown URL scheme '%v'", url.Scheme)
}
}