Skip to content

Commit

Permalink
Add webdav config
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Sep 26, 2023
1 parent 4532f51 commit 4f23f6a
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 99 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Please check out `examples` for more information.
| user | iRODS user id | "irods_user" |
| password | iRODS user password | "password" in plain text |
| url | URL | "https://data.cyverse.org/dav/iplant/home/irods_user" |
| config | additional config parameters in comma-separated kv pairs to be passed to 'davfs2.conf' | "key1=val1,key2=val2" |

Mounts **url**

Expand Down
63 changes: 9 additions & 54 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,19 @@ import (
"google.golang.org/grpc/status"
"k8s.io/klog"

"github.com/cyverse/irods-csi-driver/pkg/client/common"
"github.com/cyverse/irods-csi-driver/pkg/client/irods"
"github.com/cyverse/irods-csi-driver/pkg/client/nfs"
"github.com/cyverse/irods-csi-driver/pkg/client/webdav"
"github.com/cyverse/irods-csi-driver/pkg/metrics"
"github.com/cyverse/irods-csi-driver/pkg/mounter"
)

// ClientType is a mount client type
type ClientType string

// mount driver (iRODS Client) types
const (
// IrodsFuseClientType is for iRODS FUSE
IrodsFuseClientType ClientType = "irodsfuse"
// WebdavClientType is for WebDav client (Davfs2)
WebdavClientType ClientType = "webdav"
// NfsClientType is for NFS client
NfsClientType ClientType = "nfs"
)

// GetClientType returns iRODS Client value from param map
func GetClientType(params map[string]string) ClientType {
return GetValidClientType(params["client"])
}

// IsValidClientType checks if given client string is valid
func IsValidClientType(client string) bool {
switch client {
case string(IrodsFuseClientType):
return true
case string(WebdavClientType):
return true
case string(NfsClientType):
return true
default:
return false
}
}

// GetValidClientType checks if given client string is valid
func GetValidClientType(client string) ClientType {
switch client {
case string(IrodsFuseClientType):
return IrodsFuseClientType
case string(WebdavClientType):
return WebdavClientType
case string(NfsClientType):
return NfsClientType
default:
return IrodsFuseClientType
}
}

// MountClient mounts a fs client
func MountClient(mounter mounter.Mounter, volID string, configs map[string]string, mountOptions []string, targetPath string) error {
irodsClientType := GetClientType(configs)
irodsClientType := common.GetClientType(configs)
switch irodsClientType {
case IrodsFuseClientType:
case common.IrodsFuseClientType:
klog.V(5).Infof("mounting %s", irodsClientType)

if err := irods.Mount(mounter, volID, configs, mountOptions, targetPath); err != nil {
Expand All @@ -76,7 +31,7 @@ func MountClient(mounter mounter.Mounter, volID string, configs map[string]strin
metrics.IncreaseCounterForVolumeMount()
metrics.IncreaseCounterForActiveVolumeMount()
return nil
case WebdavClientType:
case common.WebdavClientType:
klog.V(5).Infof("mounting %s", irodsClientType)

if err := webdav.Mount(mounter, volID, configs, mountOptions, targetPath); err != nil {
Expand All @@ -88,7 +43,7 @@ func MountClient(mounter mounter.Mounter, volID string, configs map[string]strin
metrics.IncreaseCounterForVolumeMount()
metrics.IncreaseCounterForActiveVolumeMount()
return nil
case NfsClientType:
case common.NfsClientType:
klog.V(5).Infof("mounting %s", irodsClientType)

if err := nfs.Mount(mounter, volID, configs, mountOptions, targetPath); err != nil {
Expand All @@ -114,9 +69,9 @@ func ClearFailedMount(mounter mounter.Mounter, targetPath string) {
}

// UnmountClient unmounts a fs client
func UnmountClient(mounter mounter.Mounter, volID string, irodsClientType ClientType, configs map[string]string, targetPath string) error {
func UnmountClient(mounter mounter.Mounter, volID string, irodsClientType common.ClientType, configs map[string]string, targetPath string) error {
switch irodsClientType {
case IrodsFuseClientType:
case common.IrodsFuseClientType:
klog.V(5).Infof("unmounting %s", irodsClientType)

if err := irods.Unmount(mounter, volID, configs, targetPath); err != nil {
Expand All @@ -127,7 +82,7 @@ func UnmountClient(mounter mounter.Mounter, volID string, irodsClientType Client
metrics.IncreaseCounterForVolumeUnmount()
metrics.DecreaseCounterForActiveVolumeMount()
return nil
case WebdavClientType:
case common.WebdavClientType:
klog.V(5).Infof("unmounting %s", irodsClientType)

if err := webdav.Unmount(mounter, volID, configs, targetPath); err != nil {
Expand All @@ -138,7 +93,7 @@ func UnmountClient(mounter mounter.Mounter, volID string, irodsClientType Client
metrics.IncreaseCounterForVolumeUnmount()
metrics.DecreaseCounterForActiveVolumeMount()
return nil
case NfsClientType:
case common.NfsClientType:
klog.V(5).Infof("unmounting %s", irodsClientType)

if err := nfs.Unmount(mounter, volID, configs, targetPath); err != nil {
Expand Down
81 changes: 81 additions & 0 deletions pkg/client/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package common

import (
"path/filepath"
"strconv"
"strings"
)

// ClientType is a mount client type
type ClientType string

// mount driver (iRODS Client) types
const (
// IrodsFuseClientType is for iRODS FUSE
IrodsFuseClientType ClientType = "irodsfuse"
// WebdavClientType is for WebDav client (Davfs2)
WebdavClientType ClientType = "webdav"
// NfsClientType is for NFS client
NfsClientType ClientType = "nfs"
)

// GetClientType returns iRODS Client value from param map
func GetClientType(params map[string]string) ClientType {
return GetValidClientType(params["client"])
}

// IsValidClientType checks if given client string is valid
func IsValidClientType(client string) bool {
switch client {
case string(IrodsFuseClientType):
return true
case string(WebdavClientType):
return true
case string(NfsClientType):
return true
default:
return false
}
}

// GetValidClientType checks if given client string is valid
func GetValidClientType(client string) ClientType {
switch client {
case string(IrodsFuseClientType):
return IrodsFuseClientType
case string(WebdavClientType):
return WebdavClientType
case string(NfsClientType):
return NfsClientType
default:
return IrodsFuseClientType
}
}

// GetConfigEnforceProxyAccess checks if proxy access is enforced via driver config
func GetConfigEnforceProxyAccess(configs map[string]string) bool {
enforce := configs["enforceproxyaccess"]
bEnforce, _ := strconv.ParseBool(enforce)
return bEnforce
}

// GetConfigMountPathWhitelist returns a whitelist of collections that users can mount
func GetConfigMountPathWhitelist(configs map[string]string) []string {
whitelist := configs["mountpathwhitelist"]

whitelistItems := strings.Split(whitelist, ",")
if len(whitelistItems) > 0 {
for idx := range whitelistItems {
whitelistItems[idx] = strings.TrimSpace(whitelistItems[idx])
}
return whitelistItems
}

return []string{"/"}
}

// GetConfigDataRootPath returns a data root path
func GetConfigDataRootPath(configs map[string]string, volID string) string {
irodsClientType := GetClientType(configs)
return filepath.Join(configs["storagepath"], string(irodsClientType), volID)
}
33 changes: 0 additions & 33 deletions pkg/client/irods/config.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/client/irods/connection_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strconv"

client_common "github.com/cyverse/irods-csi-driver/pkg/client/common"
"github.com/cyverse/irods-csi-driver/pkg/common"
"github.com/cyverse/irods-csi-driver/pkg/mounter"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -167,7 +168,7 @@ func GetConnectionInfo(configs map[string]string) (*IRODSFSConnectionInfo, error
return nil, status.Error(codes.InvalidArgument, "Argument clientUser must be a non-anonymous user")
}

if getConfigEnforceProxyAccess(configs) {
if client_common.GetConfigEnforceProxyAccess(configs) {
// we don't allow anonymous user
if connInfo.IsAnonymousUser() {
return nil, status.Error(codes.InvalidArgument, "Argument user must be a non-anonymous user")
Expand Down Expand Up @@ -225,7 +226,7 @@ func GetConnectionInfo(configs map[string]string) (*IRODSFSConnectionInfo, error
return nil, status.Error(codes.InvalidArgument, "Argument path and path_mappings are empty, one must be given")
}

whitelist := getConfigMountPathWhitelist(configs)
whitelist := client_common.GetConfigMountPathWhitelist(configs)
for _, mapping := range connInfo.PathMappings {
if !mounter.IsMountPathAllowed(whitelist, mapping.IRODSPath) {
return nil, status.Errorf(codes.InvalidArgument, "Argument path %s is not allowed to mount", mapping.IRODSPath)
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/irods/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

client_common "github.com/cyverse/irods-csi-driver/pkg/client/common"
"github.com/cyverse/irods-csi-driver/pkg/mounter"
"golang.org/x/xerrors"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -34,7 +35,7 @@ func Mount(mounter mounter.Mounter, volID string, configs map[string]string, mnt
irodsFsConfig := NewDefaultIRODSFSConfig()

// create irodsfs dataroot
dataRootPath := getConfigDataRootPath(configs, volID)
dataRootPath := client_common.GetConfigDataRootPath(configs, volID)
err = makeIrodsFuseLiteDataRootPath(dataRootPath)
if err != nil {
return status.Error(codes.Internal, err.Error())
Expand Down Expand Up @@ -89,7 +90,7 @@ func Unmount(mounter mounter.Mounter, volID string, configs map[string]string, t
}

// manage logs
dataRootPath := getConfigDataRootPath(configs, volID)
dataRootPath := client_common.GetConfigDataRootPath(configs, volID)
err = deleteIrodsFuseLiteData(dataRootPath)
if err != nil {
klog.V(5).Infof("Error deleting iRODS FUSE Lite data at %s - ignoring", dataRootPath)
Expand Down
11 changes: 11 additions & 0 deletions pkg/client/webdav/connection_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webdav

import (
"net/url"
"strings"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -16,6 +17,7 @@ type WebDAVConnectionInfo struct {
URL string
User string
Password string
Config map[string]string
}

// SetAnonymousUser sets anonymous user
Expand All @@ -37,6 +39,15 @@ func getConnectionInfoFromMap(params map[string]string, connInfo *WebDAVConnecti
connInfo.Password = v
case "url":
connInfo.URL = v
case "config":
connInfo.Config = map[string]string{}
configStrings := strings.Split(v, ",")
for _, configString := range configStrings {
configKV := strings.Split(strings.TrimSpace(configString), "=")
if len(configKV) == 2 {
connInfo.Config[strings.TrimSpace(configKV[0])] = strings.TrimSpace(configKV[1])
}
}
default:
// ignore
}
Expand Down
38 changes: 38 additions & 0 deletions pkg/client/webdav/davfs_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package webdav

import (
"fmt"
"os"
"strings"
)

type DavFSConfig struct {
Params map[string]string
}

// NewDefaultDavFSConfig creates default DavFS config map
func NewDefaultDavFSConfig() *DavFSConfig {
return &DavFSConfig{
Params: map[string]string{},
}
}

func (config *DavFSConfig) AddParam(key string, value string) {
config.Params[key] = value
}

func (config *DavFSConfig) AddParams(params map[string]string) {
for k, v := range params {
config.Params[k] = v
}
}

func (config *DavFSConfig) SaveToFile(name string) error {
sb := strings.Builder{}

for k, v := range config.Params {
sb.WriteString(fmt.Sprintf("%s %s\n", k, v))
}

return os.WriteFile(name, []byte(sb.String()), 0o664)
}
Loading

0 comments on commit 4f23f6a

Please sign in to comment.