Merge pull request #36 from Fedosin/folder_permissions
Allow to set custom permissions for the mounted folder
This commit is contained in:
commit
a92afa22ee
@ -20,6 +20,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -29,6 +30,7 @@ import (
|
||||
var (
|
||||
endpoint string
|
||||
nodeID string
|
||||
perm string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -55,6 +57,8 @@ func main() {
|
||||
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
|
||||
cmd.MarkPersistentFlagRequired("endpoint")
|
||||
|
||||
cmd.PersistentFlags().StringVar(&perm, "mount-permissions", "", "mounted folder permissions")
|
||||
|
||||
cmd.ParseFlags(os.Args[1:])
|
||||
if err := cmd.Execute(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s", err.Error())
|
||||
@ -65,6 +69,18 @@ func main() {
|
||||
}
|
||||
|
||||
func handle() {
|
||||
d := nfs.NewNFSdriver(nodeID, endpoint)
|
||||
// Converting string permission representation to *uint32
|
||||
var parsedPerm *uint32
|
||||
if perm != "" {
|
||||
permu64, err := strconv.ParseUint(perm, 8, 32)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Incorrect mount-permissions value: %q", perm)
|
||||
os.Exit(1)
|
||||
}
|
||||
permu32 := uint32(permu64)
|
||||
parsedPerm = &permu32
|
||||
}
|
||||
|
||||
d := nfs.NewNFSdriver(nodeID, endpoint, parsedPerm)
|
||||
d.Run()
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@ type nfsDriver struct {
|
||||
|
||||
endpoint string
|
||||
|
||||
perm *uint32
|
||||
|
||||
//ids *identityServer
|
||||
ns *nodeServer
|
||||
cap map[csi.VolumeCapability_AccessMode_Mode]bool
|
||||
@ -43,7 +45,7 @@ var (
|
||||
version = "2.0.0"
|
||||
)
|
||||
|
||||
func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
|
||||
func NewNFSdriver(nodeID, endpoint string, perm *uint32) *nfsDriver {
|
||||
glog.Infof("Driver: %v version: %v", driverName, version)
|
||||
|
||||
n := &nfsDriver{
|
||||
@ -52,6 +54,7 @@ func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
|
||||
nodeID: nodeID,
|
||||
endpoint: endpoint,
|
||||
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
|
||||
perm: perm,
|
||||
}
|
||||
|
||||
vcam := []csi.VolumeCapability_AccessMode_Mode{
|
||||
|
||||
@ -73,6 +73,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
if ns.Driver.perm != nil {
|
||||
if err := os.Chmod(targetPath, os.FileMode(*ns.Driver.perm)); err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return &csi.NodePublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user