Skip to content

Commit

Permalink
Fix icommands configuration support
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Dec 6, 2022
1 parent 20f24c9 commit 8668d16
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 138 deletions.
2 changes: 1 addition & 1 deletion cmd/commons/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func ProcessCommonFlags(command *cobra.Command, args []string) (*commons.Config,
readConfig = true
} else {
// icommands environment
serverConfig, err := commons.LoadICommandsEnvironmentFile(configPath)
serverConfig, err := commons.LoadICommandsEnvironmentDir(configPath)
if err != nil {
logger.Error(err)
return nil, nil, false, err // stop here
Expand Down
137 changes: 0 additions & 137 deletions commons/icomannds.go

This file was deleted.

148 changes: 148 additions & 0 deletions commons/icommands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package commons

import (
"fmt"
"os"
"path/filepath"

irodsclient_icommands "github.com/cyverse/go-irodsclient/utils/icommands"
irodsfs_common_vpath "github.com/cyverse/irodsfs-common/vpath"
log "github.com/sirupsen/logrus"
)

func isICommandsEnvDir(dirPath string) bool {
st, err := os.Stat(dirPath)
if err != nil {
return false
}

if !st.IsDir() {
return false
}

envFilePath := filepath.Join(dirPath, "irods_environment.json")
passFilePath := filepath.Join(dirPath, ".irodsA")

stEnv, err := os.Stat(envFilePath)
if err != nil {
return false
}

if stEnv.IsDir() {
return false
}

stPass, err := os.Stat(passFilePath)
if err != nil {
return false
}

if stPass.IsDir() {
return false
}

return true
}

func LoadICommandsEnvironmentDir(configDirPath string) (*Config, error) {
logger := log.WithFields(log.Fields{
"package": "commons",
"function": "LoadICommandsEnvironmentDir",
})

configDirPath, err := filepath.Abs(configDirPath)
if err != nil {
return nil, err
}

// check if it is iRODS FUSE Lite Config YAML or iCommands JSON file
if isICommandsEnvDir(configDirPath) {
logger.Debugf("reading iCommands environment dir - %s", configDirPath)

envFilePath := filepath.Join(configDirPath, "irods_environment.json")
return LoadICommandsEnvironmentFile(envFilePath)
}

return nil, fmt.Errorf("failed to read iCommands environment dir %s", configDirPath)
}

func LoadICommandsEnvironmentFile(configPath string) (*Config, error) {
logger := log.WithFields(log.Fields{
"package": "commons",
"function": "LoadICommandsEnvironmentFile",
})

configPath, err := filepath.Abs(configPath)
if err != nil {
return nil, err
}

logger.Debugf("reading iCommands environment file - %s", configPath)

// read from iCommands JSON File
iCommandsEnvMgr, err := irodsclient_icommands.CreateIcommandsEnvironmentManager()
if err != nil {
return nil, err
}

iCommandsEnvMgr.SetEnvironmentFilePath(configPath)

err = iCommandsEnvMgr.Load(os.Getppid())
if err != nil {
return nil, err
}

loadedAccount, err := iCommandsEnvMgr.ToIRODSAccount()
if err != nil {
return nil, err
}

config := NewDefaultConfig()

// Fill more
config.AuthScheme = string(loadedAccount.AuthenticationScheme)
config.CSNegotiationPolicy = string(loadedAccount.CSNegotiationPolicy)
config.ClientServerNegotiation = loadedAccount.ClientServerNegotiation
config.Host = loadedAccount.Host
config.Port = loadedAccount.Port
config.ClientUser = loadedAccount.ClientUser
config.Zone = loadedAccount.ClientZone
config.ProxyUser = loadedAccount.ProxyUser
config.Password = loadedAccount.Password
config.Resource = loadedAccount.DefaultResource
config.CACertificateFile = loadedAccount.SSLConfiguration.CACertificateFile
config.EncryptionKeySize = loadedAccount.SSLConfiguration.EncryptionKeySize
config.EncryptionAlgorithm = loadedAccount.SSLConfiguration.EncryptionAlgorithm
config.SaltSize = loadedAccount.SSLConfiguration.SaltSize
config.HashRounds = loadedAccount.SSLConfiguration.HashRounds
if iCommandsEnvMgr.Session != nil {
if len(iCommandsEnvMgr.Session.CurrentWorkingDir) > 0 {
config.PathMappings = []irodsfs_common_vpath.VPathMapping{
{
IRODSPath: iCommandsEnvMgr.Session.CurrentWorkingDir,
MappingPath: "/",
ResourceType: irodsfs_common_vpath.VPathMappingDirectory,
ReadOnly: false,
CreateDir: false,
IgnoreNotExistError: false,
},
}
}
}

if len(config.PathMappings) == 0 {
iRODSHomePath := fmt.Sprintf("/%s/home/%s", config.Zone, config.ClientUser)
config.PathMappings = []irodsfs_common_vpath.VPathMapping{
{
IRODSPath: iRODSHomePath,
MappingPath: "/",
ResourceType: irodsfs_common_vpath.VPathMappingDirectory,
ReadOnly: false,
CreateDir: false,
IgnoreNotExistError: false,
},
}
}

return config, nil
}

0 comments on commit 8668d16

Please sign in to comment.