Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
key-storage-agent
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
key-storage-agent
Commits
fe9f2da2
Commit
fe9f2da2
authored
5 years ago
by
Olgun Cengiz
Browse files
Options
Downloads
Patches
Plain Diff
replaced DoGetDataCall
parent
12f75754
No related branches found
No related tags found
2 merge requests
!48
Master
,
!47
16 refactor deprecated functions
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
handler/handler.go
+39
-33
39 additions, 33 deletions
handler/handler.go
utils/utils.go
+17
-8
17 additions, 8 deletions
utils/utils.go
with
56 additions
and
41 deletions
handler/handler.go
+
39
−
33
View file @
fe9f2da2
...
@@ -22,14 +22,13 @@ import (
...
@@ -22,14 +22,13 @@ import (
"errors"
"errors"
"log"
"log"
"strings"
"strings"
"code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/clientutils"
"github.com/golang/protobuf/proto"
keyutils
"code.vereign.com/code/key-storage-agent/utils"
keyutils
"code.vereign.com/code/key-storage-agent/utils"
"code.vereign.com/code/viam-apis/authentication"
"code.vereign.com/code/viam-apis/authentication"
"code.vereign.com/code/viam-apis/key-storage-agent/api"
"code.vereign.com/code/viam-apis/key-storage-agent/api"
"code.vereign.com/code/viam-apis/utils"
"code.vereign.com/code/viam-apis/utils"
"code.vereign.com/code/viam-apis/system"
"golang.org/x/net/context"
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/metadata"
)
)
...
@@ -99,25 +98,33 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
...
@@ -99,25 +98,33 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
return
getKeyResponse
,
nil
return
getKeyResponse
,
nil
}
}
data
,
err
:=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
in
.
KeyType
))
key
:=
&
api
.
Key
{}
hasData
,
errorsString
,
err
:=
client
.
GetData
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
in
.
KeyType
),
key
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"grpc call
Do
GetData
Call
to DataStorage failed: %s"
,
err
)
log
.
Printf
(
"grpc call GetData to DataStorage failed: %s"
,
err
)
getKeyResponse
.
Key
=
nil
getKeyResponse
.
Key
=
nil
getKeyResponse
.
StatusList
=
utils
.
AddStatus
(
getKeyResponse
.
StatusList
,
getKeyResponse
.
StatusList
=
utils
.
AddStatus
(
getKeyResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
getKeyResponse
,
nil
return
getKeyResponse
,
nil
}
}
if
data
.
Errors
!=
""
{
if
errorsString
!=
""
{
getKeyResponse
.
Key
=
nil
getKeyResponse
.
Key
=
nil
getKeyResponse
.
StatusList
=
utils
.
AddStatus
(
getKeyResponse
.
StatusList
,
getKeyResponse
.
StatusList
=
utils
.
AddStatus
(
getKeyResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
"500"
,
api
.
StatusType_ERROR
,
errorsString
)
}
else
{
}
key
:=
&
api
.
Key
{}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
key
)
if
!
hasData
{
getKeyResponse
.
Key
=
key
log
.
Println
(
"No such key "
+
in
.
Uuid
)
getKeyResponse
.
Key
=
nil
getKeyResponse
.
StatusList
=
utils
.
AddStatus
(
getKeyResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
getKeyResponse
,
nil
}
}
getKeyResponse
.
Key
=
key
return
getKeyResponse
,
nil
return
getKeyResponse
,
nil
}
}
...
@@ -141,23 +148,17 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
...
@@ -141,23 +148,17 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
return
setKeyResponse
,
nil
return
setKeyResponse
,
nil
}
}
data
,
err
:=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
in
.
KeyType
))
key
:=
&
api
.
Key
{}
_
,
_
,
err
:=
client
.
GetData
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
in
.
KeyType
),
key
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"grpc call
Do
GetData
Call
to DataStorage failed: %s"
,
err
)
log
.
Printf
(
"grpc call GetData to DataStorage failed: %s"
,
err
)
setKeyResponse
.
StatusList
=
utils
.
AddStatus
(
setKeyResponse
.
StatusList
,
setKeyResponse
.
StatusList
=
utils
.
AddStatus
(
setKeyResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
setKeyResponse
,
nil
return
setKeyResponse
,
nil
}
}
if
data
.
Errors
!=
""
{
if
len
(
key
.
Content
)
>
0
{
setKeyResponse
.
StatusList
=
utils
.
AddStatus
(
setKeyResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
return
setKeyResponse
,
nil
}
key
:=
&
api
.
Key
{}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
key
)
if
key
!=
nil
&&
key
.
Content
!=
nil
&&
len
(
key
.
Content
)
>
0
{
setKeyResponse
.
StatusList
=
utils
.
AddStatus
(
setKeyResponse
.
StatusList
,
setKeyResponse
.
StatusList
=
utils
.
AddStatus
(
setKeyResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
"Key is already set"
)
"400"
,
api
.
StatusType_ERROR
,
"Key is already set"
)
return
setKeyResponse
,
nil
return
setKeyResponse
,
nil
...
@@ -176,7 +177,7 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
...
@@ -176,7 +177,7 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
_
,
_
,
err
=
client
.
PutString
(
keyToKeyIdTable
,
keyContent
,
in
.
Uuid
)
_
,
_
,
err
=
client
.
PutString
(
keyToKeyIdTable
,
keyContent
,
in
.
Uuid
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"can't
Do
Put
DataCallWith
String: %s"
,
err
)
log
.
Printf
(
"can't PutString: %s"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -236,10 +237,11 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
...
@@ -236,10 +237,11 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
keyIdResponse
:=
&
api
.
GetKeyIdByKeyResponse
{}
keyIdResponse
:=
&
api
.
GetKeyIdByKeyResponse
{}
response
,
err
:=
dataStorageClient
.
DoGetDataCall
(
keyToKeyIdTable
,
in
.
PublicKey
)
stringMessage
:=
&
system
.
String
{}
if
err
==
nil
&&
response
.
Data
!=
nil
&&
response
.
Data
.
Data
!=
nil
{
keyID
:=
string
(
response
.
Data
.
Data
)
hasData
,
errorsString
,
err
:=
dataStorageClient
.
GetData
(
keyToKeyIdTable
,
in
.
PublicKey
,
stringMessage
)
keyIdResponse
.
KeyId
=
keyID
if
err
==
nil
&&
errorsString
==
""
&&
hasData
{
keyIdResponse
.
KeyId
=
stringMessage
.
Value
return
keyIdResponse
,
nil
return
keyIdResponse
,
nil
}
else
{
}
else
{
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -258,17 +260,21 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
...
@@ -258,17 +260,21 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
for
_
,
checkID
:=
range
entity
.
AuthenticationKeys
{
for
_
,
checkID
:=
range
entity
.
AuthenticationKeys
{
key
:=
&
api
.
Key
{}
key
:=
&
api
.
Key
{}
d
ata
,
err
:=
dataStorageClient
.
Do
GetData
Call
(
"keys"
,
checkID
+
"/"
+
api
.
KeyType_PUBLIC
.
String
())
hasD
ata
,
errorsString
,
err
:=
dataStorageClient
.
GetData
(
"keys"
,
checkID
+
"/"
+
api
.
KeyType_PUBLIC
.
String
()
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"grpc call Get
KeyId
to DataStorage failed: %s"
,
err
)
log
.
Printf
(
"grpc call Get
Data
to DataStorage failed: %s"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
if
data
.
Errors
!=
""
{
if
errorsString
!=
""
{
return
nil
,
errors
.
New
(
data
.
Errors
)
log
.
Printf
(
"Error: %s"
,
errorsString
)
}
else
{
return
nil
,
errors
.
New
(
errorsString
)
proto
.
Unmarshal
(
data
.
Data
.
Data
,
key
)
}
if
!
hasData
{
log
.
Println
(
"No such checkID "
+
checkID
)
return
nil
,
errors
.
New
(
"No such checkID "
+
checkID
)
}
}
keyFromStorage
:=
base64
.
StdEncoding
.
EncodeToString
(
key
.
Content
)
keyFromStorage
:=
base64
.
StdEncoding
.
EncodeToString
(
key
.
Content
)
...
@@ -279,7 +285,7 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
...
@@ -279,7 +285,7 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
_
,
_
,
err
=
dataStorageClient
.
PutString
(
keyToKeyIdTable
,
in
.
PublicKey
,
checkID
)
_
,
_
,
err
=
dataStorageClient
.
PutString
(
keyToKeyIdTable
,
in
.
PublicKey
,
checkID
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"can't
Do
Put
DataCallWith
String: %s"
,
err
)
log
.
Printf
(
"can't PutString: %s"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
...
...
This diff is collapsed.
Click to expand it.
utils/utils.go
+
17
−
8
View file @
fe9f2da2
...
@@ -36,7 +36,6 @@ import (
...
@@ -36,7 +36,6 @@ import (
emclient
"code.vereign.com/code/viam-apis/entities-management-agent/client"
emclient
"code.vereign.com/code/viam-apis/entities-management-agent/client"
"code.vereign.com/code/viam-apis/key-storage-agent/api"
"code.vereign.com/code/viam-apis/key-storage-agent/api"
"code.vereign.com/code/viam-apis/utils"
"code.vereign.com/code/viam-apis/utils"
"github.com/golang/protobuf/proto"
)
)
func
GenerateUnusedUUID
(
client
*
client
.
DataStorageClientImpl
)
(
string
,
error
)
{
func
GenerateUnusedUUID
(
client
*
client
.
DataStorageClientImpl
)
(
string
,
error
)
{
...
@@ -45,9 +44,10 @@ func GenerateUnusedUUID(client *client.DataStorageClientImpl) (string, error) {
...
@@ -45,9 +44,10 @@ func GenerateUnusedUUID(client *client.DataStorageClientImpl) (string, error) {
uuid
,
err
:=
NewUUID
()
uuid
,
err
:=
NewUUID
()
// check that uuid is not used
// check that uuid is not used
data
,
_
:=
client
.
DoGetDataCall
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
))
key
:=
&
api
.
Key
{}
if
data
==
nil
||
data
.
Errors
!=
""
||
err
!=
nil
{
hasData
,
errorsString
,
err
:=
client
.
GetData
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
),
key
)
if
err
!=
nil
&&
errorsString
!=
""
&&
!
hasData
{
return
uuid
,
nil
return
uuid
,
nil
}
}
if
count
>=
10
{
if
count
>=
10
{
...
@@ -136,14 +136,23 @@ func ReadPemBlockFromFile(fileName string) (*pem.Block, error) {
...
@@ -136,14 +136,23 @@ func ReadPemBlockFromFile(fileName string) (*pem.Block, error) {
func
GetKey
(
client
*
client
.
DataStorageClientImpl
,
uuid
string
,
keyType
api
.
KeyType
)
(
*
api
.
Key
,
[]
*
api
.
Status
)
{
func
GetKey
(
client
*
client
.
DataStorageClientImpl
,
uuid
string
,
keyType
api
.
KeyType
)
(
*
api
.
Key
,
[]
*
api
.
Status
)
{
statusList
:=
[]
*
api
.
Status
{}
statusList
:=
[]
*
api
.
Status
{}
data
,
_
:=
client
.
DoGetDataCall
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
keyType
))
key
:=
&
api
.
Key
{}
if
data
.
Errors
!=
""
{
statusList
=
utils
.
AddStatus
(
statusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
hasData
,
errorsString
,
err
:=
client
.
GetData
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
keyType
),
key
)
if
err
!=
nil
{
statusList
=
utils
.
AddStatus
(
statusList
,
"400"
,
api
.
StatusType_ERROR
,
errorsString
)
return
nil
,
statusList
return
nil
,
statusList
}
}
key
:=
&
api
.
Key
{}
if
errorsString
!=
""
{
proto
.
Unmarshal
(
data
.
Data
.
Data
,
key
)
statusList
=
utils
.
AddStatus
(
statusList
,
"400"
,
api
.
StatusType_ERROR
,
errorsString
)
return
nil
,
statusList
}
if
!
hasData
{
statusList
=
utils
.
AddStatus
(
statusList
,
"400"
,
api
.
StatusType_ERROR
,
errorsString
)
return
nil
,
statusList
}
return
key
,
nil
return
key
,
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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