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
2
Issue boards
Milestones
Wiki
Code
Merge requests
2
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
1585b6eb
Commit
1585b6eb
authored
5 years ago
by
Gospodin Bodurov
Browse files
Options
Downloads
Patches
Plain Diff
Fix MR
parent
72186e26
No related branches found
No related tags found
1 merge request
!41
Fix MR
This commit is part of merge request
!41
. Comments created here will be created in the context of that merge request.
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Gopkg.toml
+1
-1
1 addition, 1 deletion
Gopkg.toml
config/configs.go
+3
-0
3 additions, 0 deletions
config/configs.go
handler/handler.go
+80
-0
80 additions, 0 deletions
handler/handler.go
utils/utils.go
+6
-0
6 additions, 0 deletions
utils/utils.go
with
90 additions
and
1 deletion
Gopkg.toml
+
1
−
1
Edit
View file @
1585b6eb
[[constraint]]
branch
=
"
mas
te
r
"
branch
=
"
activity_upda
te"
name
=
"code.vereign.com/code/viam-apis"
[[constraint]]
...
...
This diff is collapsed.
Click to expand it.
config/configs.go
+
3
−
0
Edit
View file @
1585b6eb
...
...
@@ -25,6 +25,7 @@ var MaxMessageSize int
var
GrpcListenAddress
string
var
RestListenAddress
string
var
DataStorageUrl
string
var
EntitiesManagerUrl
string
var
CertDir
string
func
SetConfigValues
()
{
...
...
@@ -34,6 +35,7 @@ func SetConfigValues() {
viper
.
SetDefault
(
"grpcListenAddress"
,
"localhost:7877"
)
viper
.
SetDefault
(
"restListenAddress"
,
"localhost:7878"
)
viper
.
SetDefault
(
"dataStorageUrl"
,
"localhost:7777"
)
viper
.
SetDefault
(
"entitiesManagerUrl"
,
"localhost:7779"
)
viper
.
SetDefault
(
"viamUUID"
,
"viam-system"
)
viper
.
SetDefault
(
"viamSession"
,
"viam-session"
)
...
...
@@ -106,6 +108,7 @@ func SetConfigValues() {
RestListenAddress
=
viper
.
GetString
(
"restListenAddress"
)
DataStorageUrl
=
viper
.
GetString
(
"dataStorageUrl"
)
EntitiesManagerUrl
=
viper
.
GetString
(
"entitiesManagerUrl"
)
SystemAuth
.
Uuid
=
viper
.
GetString
(
"viamUUID"
)
SystemAuth
.
Session
=
viper
.
GetString
(
"viamSession"
)
...
...
This diff is collapsed.
Click to expand it.
handler/handler.go
+
80
−
0
Edit
View file @
1585b6eb
...
...
@@ -18,9 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package
handler
import
(
"encoding/base64"
"errors"
"log"
"strings"
"code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/versions"
"github.com/golang/protobuf/proto"
...
...
@@ -32,6 +35,10 @@ import (
"google.golang.org/grpc/metadata"
)
const
(
keyToKeyIdTable
=
"authenticationKeyToKeyId"
)
// Server represents the gRPC server
type
KeyStorageServerImpl
struct
{
DataStorageUrl
string
...
...
@@ -165,6 +172,17 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
"200"
,
api
.
StatusType_INFO
,
result
)
}
if
in
.
KeyType
==
api
.
KeyType_PUBLIC
{
keyContent
:=
base64
.
StdEncoding
.
EncodeToString
(
in
.
Key
.
Content
)
_
,
_
,
err
=
client
.
DoPutDataCallWithString
(
keyToKeyIdTable
,
keyContent
,
in
.
Uuid
,
versions
.
EntitiesManagementAgentApiVersion
)
if
err
!=
nil
{
log
.
Printf
(
"can't DoPutDataCallWithString: %s"
,
err
)
return
nil
,
err
}
}
return
setKeyResponse
,
nil
}
...
...
@@ -209,6 +227,68 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser
return
reserveKeyUUIDResponse
,
nil
}
func
(
s
*
KeyStorageServerImpl
)
GetKeyId
(
ctx
context
.
Context
,
in
*
api
.
GetKeyIdByKeyRequest
)
(
*
api
.
GetKeyIdByKeyResponse
,
error
)
{
auth
:=
s
.
CreateAuthentication
(
ctx
)
//in.PublicKey
entitiesMagamentClient
:=
keyutils
.
CreateEntitiesManagementClient
(
auth
)
defer
entitiesMagamentClient
.
CloseClient
()
dataStorageClient
:=
keyutils
.
CreateDataStorageClient
(
auth
)
defer
dataStorageClient
.
CloseClient
()
keyIdResponse
:=
&
api
.
GetKeyIdByKeyResponse
{}
response
,
err
:=
dataStorageClient
.
DoGetDataCall
(
keyToKeyIdTable
,
in
.
PublicKey
)
if
err
==
nil
&&
response
.
Data
!=
nil
&&
response
.
Data
.
Data
!=
nil
{
keyID
:=
string
(
response
.
Data
.
Data
)
keyIdResponse
.
KeyId
=
keyID
return
keyIdResponse
,
nil
}
entity
,
err
:=
clientutils
.
GetLastEntity
(
entitiesMagamentClient
,
auth
.
Uuid
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
checkID
:=
range
entity
.
AuthenticationKeys
{
key
:=
&
api
.
Key
{}
data
,
err
:=
dataStorageClient
.
DoGetDataCall
(
"keys"
,
checkID
+
"/"
+
api
.
KeyType_PUBLIC
.
String
())
if
err
!=
nil
{
log
.
Printf
(
"grpc call GetKeyId to DataStorage failed: %s"
,
err
)
return
nil
,
err
}
if
data
.
Errors
!=
""
{
return
nil
,
errors
.
New
(
data
.
Errors
)
}
else
{
proto
.
Unmarshal
(
data
.
Data
.
Data
,
key
)
}
keyFromStorage
:=
base64
.
StdEncoding
.
EncodeToString
(
key
.
Content
)
if
in
.
PublicKey
!=
keyFromStorage
{
continue
}
_
,
_
,
err
=
dataStorageClient
.
DoPutDataCallWithString
(
keyToKeyIdTable
,
in
.
PublicKey
,
checkID
,
versions
.
EntitiesManagementAgentApiVersion
)
if
err
!=
nil
{
log
.
Printf
(
"can't DoPutDataCallWithString: %s"
,
err
)
return
nil
,
err
}
keyIdResponse
.
KeyId
=
checkID
return
keyIdResponse
,
nil
}
//getKeyFromContent
return
keyIdResponse
,
nil
}
func
(
s
*
KeyStorageServerImpl
)
GetVersionKSA
(
ctx
context
.
Context
,
in
*
api
.
GetVersionKSAMessage
)
(
*
api
.
GetVersionKSAResponseMessage
,
error
)
{
log
.
Println
(
"Version: "
+
version
)
return
&
api
.
GetVersionKSAResponseMessage
{
Version
:
version
,
Errors
:
""
},
nil
...
...
This diff is collapsed.
Click to expand it.
utils/utils.go
+
6
−
0
Edit
View file @
1585b6eb
...
...
@@ -33,6 +33,7 @@ import (
"code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/data-storage-agent/client"
dsclient
"code.vereign.com/code/viam-apis/data-storage-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/utils"
"github.com/golang/protobuf/proto"
...
...
@@ -151,3 +152,8 @@ func CreateDataStorageClient(auth *authentication.Authentication) *dsclient.Data
return
clientutils
.
CreateDataStorageClient
(
auth
,
config
.
DataStorageUrl
,
config
.
CertificatePEM
,
config
.
PrivateKeyPEM
,
config
.
CaCertificatePEM
,
config
.
MaxMessageSize
)
}
func
CreateEntitiesManagementClient
(
auth
*
authentication
.
Authentication
)
*
emclient
.
EntitiesManagerClientImpl
{
return
clientutils
.
CreateEntitiesManagementClient
(
auth
,
config
.
EntitiesManagerUrl
,
config
.
CertificatePEM
,
config
.
PrivateKeyPEM
,
config
.
CaCertificatePEM
,
config
.
MaxMessageSize
)
}
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