Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
ef482c1b
Commit
ef482c1b
authored
2 years ago
by
Akshay Mahendrakar
Browse files
Options
Downloads
Patches
Plain Diff
Immudb config map removed
AddNewImmuDbConnection - method removed
parent
45d1cd57
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!270
Core ImmuDB package and TOTP plugin - Implementation
,
!269
Core ImmuDB package and TOTP plugin - Implementation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dalmdl/coreimmudb/coreimmudb.go
+11
-44
dalmdl/coreimmudb/coreimmudb.go
dalmdl/coreimmudb/coreimmudb_test.go
+6
-27
dalmdl/coreimmudb/coreimmudb_test.go
with
17 additions
and
71 deletions
dalmdl/coreimmudb/coreimmudb.go
+
11
−
44
View file @
ef482c1b
...
...
@@ -11,7 +11,6 @@ import (
)
var
(
configs
map
[
string
]
*
ImmuHost
// Immudb config details with host
instances
map
[
string
]
immudb
.
ImmuClient
// Immudb client connection with host
defaultHostName
string
mutex
sync
.
Mutex
...
...
@@ -38,14 +37,11 @@ type KeyValue struct {
}
func
init
()
{
configs
=
make
(
map
[
string
]
*
ImmuHost
)
instances
=
make
(
map
[
string
]
immudb
.
ImmuClient
)
}
// InitNewImmuDbSession - Initializes connection to ImmuDB server using []ImmuHost data
func
InitNewImmuDbSession
(
hosts
[]
ImmuHost
)
error
{
configs
=
make
(
map
[
string
]
*
ImmuHost
)
func
InitImmuDBConnections
(
hosts
[]
ImmuHost
)
error
{
instances
=
make
(
map
[
string
]
immudb
.
ImmuClient
)
mutex
.
Lock
()
defer
mutex
.
Unlock
()
...
...
@@ -61,11 +57,9 @@ func InitNewImmuDbSession(hosts []ImmuHost) error {
client
=
immudb
.
NewClient
()
.
WithOptions
(
dbConfig
)
err
:=
client
.
OpenSession
(
context
.
TODO
(),
[]
byte
(
v
.
Username
),
[]
byte
(
v
.
Password
),
v
.
Database
)
if
err
!=
nil
{
configs
=
make
(
map
[
string
]
*
ImmuHost
)
instances
=
make
(
map
[
string
]
immudb
.
ImmuClient
)
return
err
}
configs
[
v
.
HostName
]
=
&
v
instances
[
v
.
HostName
]
=
client
if
v
.
IsDefault
{
defaultHostName
=
v
.
HostName
...
...
@@ -74,33 +68,6 @@ func InitNewImmuDbSession(hosts []ImmuHost) error {
return
nil
}
// AddNewImmuDbConnection - Creating and connecting to ImmuDB server using ImmuHost details
func
AddNewImmuDbConnection
(
host
ImmuHost
)
error
{
mutex
.
Lock
()
defer
mutex
.
Unlock
()
if
host
.
IsDisabled
{
return
nil
}
var
client
immudb
.
ImmuClient
dbconfig
:=
immudb
.
DefaultOptions
()
dbconfig
.
Address
=
host
.
Address
dbconfig
.
Port
=
host
.
Port
client
=
immudb
.
NewClient
()
.
WithOptions
(
dbconfig
)
err
:=
client
.
OpenSession
(
context
.
TODO
(),
[]
byte
(
host
.
Username
),
[]
byte
(
host
.
Password
),
host
.
Database
)
if
err
!=
nil
{
return
err
}
configs
[
host
.
HostName
]
=
&
host
instances
[
host
.
HostName
]
=
client
if
host
.
IsDefault
{
defaultHostName
=
host
.
HostName
}
return
nil
}
// DeleteImmuDbSession - Disconnecting Immu Database connection
func
DeleteImmuDbSession
(
hostName
string
)
error
{
mutex
.
Lock
()
...
...
@@ -115,7 +82,7 @@ func DeleteImmuDbSession(hostName string) error {
}
// Get ImmuDB connection - immudb.ImmuClient
func
g
etImmuDbConnection
(
hostName
string
)
(
immudb
.
ImmuClient
,
error
)
{
func
G
etImmuDbConnection
(
hostName
string
)
(
immudb
.
ImmuClient
,
error
)
{
mutex
.
Lock
()
defer
mutex
.
Unlock
()
// Returning if there are no immudb connections present
...
...
@@ -152,7 +119,7 @@ func GetImmuDAOWithHost(hostname string) *ImmuDAO {
// GetKeyData - Get single value for provided key
func
(
i
*
ImmuDAO
)
GetKeyData
(
key
[]
byte
)
(
*
schema
.
Entry
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -161,7 +128,7 @@ func (i *ImmuDAO) GetKeyData(key []byte) (*schema.Entry, error) {
// GetVerifiedKeyData - Get single value for provided key with additional server-provided proof validation.
func
(
i
*
ImmuDAO
)
GetVerifiedKeyData
(
key
[]
byte
)
(
*
schema
.
Entry
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -170,7 +137,7 @@ func (i *ImmuDAO) GetVerifiedKeyData(key []byte) (*schema.Entry, error) {
// GetAllKeysData - Getting all keys data
func
(
i
*
ImmuDAO
)
GetAllKeysData
(
keys
[][]
byte
)
(
*
schema
.
Entries
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -184,7 +151,7 @@ func (i *ImmuDAO) GetAllKeysData(keys [][]byte) (*schema.Entries, error) {
Desc - Sorting in descending order
*/
func
(
i
*
ImmuDAO
)
GetKeyHistory
(
key
[]
byte
,
offset
uint64
,
limit
int32
,
desc
bool
)
(
*
schema
.
Entries
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -203,7 +170,7 @@ func (i *ImmuDAO) GetKeyHistory(key []byte, offset uint64, limit int32, desc boo
// SetKeyData - Commits provided value for provided key
func
(
i
*
ImmuDAO
)
SetKeyData
(
key
,
value
[]
byte
)
(
*
schema
.
TxHeader
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -212,7 +179,7 @@ func (i *ImmuDAO) SetKeyData(key, value []byte) (*schema.TxHeader, error) {
// SetVerifiedKeyData - Commits provided value for provided key and also requests a server-generated proof
func
(
i
*
ImmuDAO
)
SetVerifiedKeyData
(
key
,
value
[]
byte
)
(
*
schema
.
TxHeader
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -222,7 +189,7 @@ func (i *ImmuDAO) SetVerifiedKeyData(key, value []byte) (*schema.TxHeader, error
// SetAllKeysData - Set multiple keys with their values in a single transaction.
func
(
i
*
ImmuDAO
)
SetAllKeysData
(
kv
[]
KeyValue
)
(
*
schema
.
TxHeader
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -236,7 +203,7 @@ func (i *ImmuDAO) SetAllKeysData(kv []KeyValue) (*schema.TxHeader, error) {
// DeleteKey - Key is deleted logically from Database, physically it is present in database
func
(
i
*
ImmuDAO
)
DeleteKey
(
keys
[][]
byte
)
(
*
schema
.
TxHeader
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
// ImmuDB connection for the provided host
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -249,7 +216,7 @@ func (i *ImmuDAO) DeleteKey(keys [][]byte) (*schema.TxHeader, error) {
// ExpirableKeySet - Sets value for the key with expiration time
func
(
i
*
ImmuDAO
)
ExpirableKeySet
(
key
,
value
[]
byte
,
expiresAt
time
.
Time
)
(
*
schema
.
TxHeader
,
error
)
{
client
,
err
:=
g
etImmuDbConnection
(
i
.
HostName
)
client
,
err
:=
G
etImmuDbConnection
(
i
.
HostName
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
dalmdl/coreimmudb/coreimmudb_test.go
+
6
−
27
View file @
ef482c1b
...
...
@@ -12,7 +12,7 @@ import (
func
init
()
{
// Creating and connecting two Immu database connection: ImmuDbHost1,ImmuDbHost4
// err := Init
New
ImmuD
bSess
ion([]ImmuHost{{"ImmuDbHost1", "localhost", 3322, "defaultdb", "immudb", "immudb", true, false},
// err := InitImmuD
BConnect
ion
s
([]ImmuHost{{"ImmuDbHost1", "localhost", 3322, "defaultdb", "immudb", "immudb", true, false},
// {"ImmuDbHost4", "localhost", 3322, "defaultdb", "immudb", "immudb", false, false}})
// if err != nil {
// panic(err)
...
...
@@ -20,8 +20,8 @@ func init() {
}
// Test - Init
New
ImmuD
bSess
ion
func
TestInit
New
ImmuD
bSess
ion
(
t
*
testing
.
T
)
{
// Test - InitImmuD
BConnect
ion
s
func
TestInitImmuD
BConnect
ion
s
(
t
*
testing
.
T
)
{
type
args
struct
{
hosts
[]
ImmuHost
}
...
...
@@ -37,29 +37,8 @@ func TestInitNewImmuDbSession(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
err
:=
InitNewImmuDbSession
(
tt
.
args
.
hosts
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"InitNewImmuDbSession() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
})
}
}
func
TestAddNewImmuDbConnection
(
t
*
testing
.
T
)
{
type
args
struct
{
host
ImmuHost
}
tests
:=
[]
struct
{
name
string
args
args
wantErr
bool
}{
{
name
:
"Test 1"
,
args
:
args
{
host
:
ImmuHost
{
"LocalHostDB1"
,
"localhost"
,
3322
,
"defaultdb"
,
"immudb"
,
"immudb"
,
true
,
false
}},
wantErr
:
false
},
// PASS
{
name
:
"Test 2"
,
args
:
args
{
host
:
ImmuHost
{
"LocalHostDB2"
,
"localhost"
,
3422
,
"defaultdbname"
,
"wrongimmudb"
,
"immudb"
,
true
,
false
}},
wantErr
:
true
},
// FAIL - Wrong connection details
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
err
:=
AddNewImmuDbConnection
(
tt
.
args
.
host
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"AddNewImmuDbConnection() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
if
err
:=
InitImmuDBConnections
(
tt
.
args
.
hosts
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"InitImmuDBConnections() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
})
}
...
...
@@ -108,7 +87,7 @@ func Test_getImmuDbConnection(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
,
err
:=
g
etImmuDbConnection
(
tt
.
args
.
hostName
)
got
,
err
:=
G
etImmuDbConnection
(
tt
.
args
.
hostName
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"getImmuDbConnection() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets