Commit b708176a authored by Akshay Mahendrakar's avatar Akshay Mahendrakar
Browse files

variable naming convention changes, and method description(more specific).

parent 4684e851
Branches
Tags
3 merge requests!270Core ImmuDB package and TOTP plugin - Implementation,!269Core ImmuDB package and TOTP plugin - Implementation,!267List users and list databases feature, Creating specified (hidden) directory…
Showing with 42 additions and 38 deletions
......@@ -85,49 +85,49 @@ func InitUsingJson(filePath string) error {
mutex.Lock()
defer mutex.Unlock()
for _, h := range hosts {
if h.IsDisabled { // Not connecting to database if isDisabled == true
for _, host := range hosts {
if host.IsDisabled { // Not connecting to database if isDisabled == true
continue
}
var client immudb.ImmuClient
opts := immudb.DefaultOptions()
opts.Address = h.Server
opts.Port = h.Port
if h.Dir != "" {
opts.Address = host.Server
opts.Port = host.Port
if host.Dir != "" {
// Checking if folder name contains extension
if filepath.Ext(h.Dir) != "" {
return errormdl.Wrap("DIRECTORY NAME CONTAINS EXTENSION " + filepath.Ext(h.Dir))
if filepath.Ext(host.Dir) != "" {
return errormdl.Wrap("DIRECTORY NAME CONTAINS EXTENSION " + filepath.Ext(host.Dir))
}
path := strings.Split(h.Dir, "/")
path := strings.Split(host.Dir, "/")
// Hiding folder by adding prefix '.'
if !strings.HasPrefix(path[len(path)-1], ".") {
path[len(path)-1] = "." + path[len(path)-1]
}
h.Dir = strings.Join(path, "/")
host.Dir = strings.Join(path, "/")
if _, err := os.Stat(h.Dir); os.IsNotExist(err) { // Checking directory is present and accessible
if err = os.Mkdir(h.Dir, 0740); err != nil {
if _, err := os.Stat(host.Dir); os.IsNotExist(err) { // Checking directory is present and accessible
if err = os.Mkdir(host.Dir, 0740); err != nil {
return err
}
}
opts.Dir = h.Dir
opts.Dir = host.Dir
}
if h.MaxRecvMsgSize > 0 { // Setting maximum receive message size if provided
opts.MaxRecvMsgSize = h.MaxRecvMsgSize * 1024 * 1024
if host.MaxRecvMsgSize > 0 { // Setting maximum receive message size if provided
opts.MaxRecvMsgSize = host.MaxRecvMsgSize * 1024 * 1024
}
client = immudb.NewClient().WithOptions(opts)
err := client.OpenSession(context.TODO(), []byte(h.Username), []byte(h.Password), h.Database)
err := client.OpenSession(context.TODO(), []byte(host.Username), []byte(host.Password), host.Database)
if err != nil {
instances = make(map[string]immudb.ImmuClient)
return err
}
instances[h.HostName] = client
if h.IsDefault {
DefaultHostName = h.HostName
instances[host.HostName] = client
if host.IsDefault {
DefaultHostName = host.HostName
}
}
return nil
......@@ -138,47 +138,47 @@ func InitImmuDBConnections(hosts []ImmuHost) error {
instances = make(map[string]immudb.ImmuClient)
mutex.Lock()
defer mutex.Unlock()
for _, v := range hosts {
if v.IsDisabled { // Not connecting to database if isDisabled == true
for _, host := range hosts {
if host.IsDisabled { // Not connecting to database if isDisabled == true
continue
}
var client immudb.ImmuClient
opts := immudb.DefaultOptions()
opts.Address = v.Server
opts.Port = v.Port
if v.Dir != "" {
opts.Address = host.Server
opts.Port = host.Port
if host.Dir != "" {
// Checking if folder name contains extension
if filepath.Ext(v.Dir) != "" {
return errormdl.Wrap("DIRECTORY NAME CONTAINS EXTENSION " + filepath.Ext(v.Dir))
if filepath.Ext(host.Dir) != "" {
return errormdl.Wrap("DIRECTORY NAME CONTAINS EXTENSION " + filepath.Ext(host.Dir))
}
path := strings.Split(v.Dir, "/")
path := strings.Split(host.Dir, "/")
// Hiding folder by adding prefix '.'
if !strings.HasPrefix(path[len(path)-1], ".") {
path[len(path)-1] = "." + path[len(path)-1]
}
v.Dir = strings.Join(path, "/")
if _, err := os.Stat(v.Dir); os.IsNotExist(err) { // Checking directory is present and accessible
if err = os.Mkdir(v.Dir, 0740); err != nil {
host.Dir = strings.Join(path, "/")
if _, err := os.Stat(host.Dir); os.IsNotExist(err) { // Checking directory is present and accessible
if err = os.Mkdir(host.Dir, 0740); err != nil {
return err
}
}
opts.Dir = v.Dir
opts.Dir = host.Dir
}
if v.MaxRecvMsgSize > 0 { // Setting maximum receive message size if provided
opts.MaxRecvMsgSize = v.MaxRecvMsgSize * 1024 * 1024
if host.MaxRecvMsgSize > 0 { // Setting maximum receive message size if provided
opts.MaxRecvMsgSize = host.MaxRecvMsgSize * 1024 * 1024
}
client = immudb.NewClient().WithOptions(opts)
err := client.OpenSession(context.TODO(), []byte(v.Username), []byte(v.Password), v.Database)
err := client.OpenSession(context.TODO(), []byte(host.Username), []byte(host.Password), host.Database)
if err != nil {
instances = make(map[string]immudb.ImmuClient)
return err
}
instances[v.HostName] = client
if v.IsDefault {
DefaultHostName = v.HostName
instances[host.HostName] = client
if host.IsDefault {
DefaultHostName = host.HostName
}
}
return nil
......@@ -404,7 +404,7 @@ func (i *ImmuDAO) ExpirableKeySet(key, value []byte, expiresAt time.Time) (*sche
/* END OF WRITE OPERATIONS */
// CreateDatabase - Creates new database in ImmuDB
// CreateDatabase - Creates new database in ImmuDB, current database user requires SysAdmin permission level.
func (i *ImmuDAO) CreateDatabase(dbName string, dbSettings *schema.DatabaseNullableSettings) (*schema.CreateDatabaseResponse, error) {
client, err := GetImmuDbConnection(i.HostName)
if err != nil {
......@@ -464,7 +464,11 @@ func (i *ImmuDAO) CreateUser(username, password, dbName string, permission int)
}
/*
ListUsers - List all database users
ListUsers - List all database of user
This call requires Admin or SysAdmin permission level.
When called as a SysAdmin user, all users in the database are returned. When called as an Admin user, users for currently selected database are returned.
*/
func (i *ImmuDAO) ListUsers() (*schema.UserList, error) {
client, err := GetImmuDbConnection(i.HostName)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment