Skip to content
Snippets Groups Projects
Commit 1585b6eb authored by Gospodin Bodurov's avatar Gospodin Bodurov
Browse files

Fix MR

parent 72186e26
Branches activity_update
No related tags found
1 merge request!41Fix MR
This commit is part of merge request !41. Comments created here will be created in the context of that merge request.
[[constraint]] [[constraint]]
branch = "master" branch = "activity_update"
name = "code.vereign.com/code/viam-apis" name = "code.vereign.com/code/viam-apis"
[[constraint]] [[constraint]]
......
...@@ -25,6 +25,7 @@ var MaxMessageSize int ...@@ -25,6 +25,7 @@ var MaxMessageSize int
var GrpcListenAddress string var GrpcListenAddress string
var RestListenAddress string var RestListenAddress string
var DataStorageUrl string var DataStorageUrl string
var EntitiesManagerUrl string
var CertDir string var CertDir string
func SetConfigValues() { func SetConfigValues() {
...@@ -34,6 +35,7 @@ func SetConfigValues() { ...@@ -34,6 +35,7 @@ func SetConfigValues() {
viper.SetDefault("grpcListenAddress", "localhost:7877") viper.SetDefault("grpcListenAddress", "localhost:7877")
viper.SetDefault("restListenAddress", "localhost:7878") viper.SetDefault("restListenAddress", "localhost:7878")
viper.SetDefault("dataStorageUrl", "localhost:7777") viper.SetDefault("dataStorageUrl", "localhost:7777")
viper.SetDefault("entitiesManagerUrl", "localhost:7779")
viper.SetDefault("viamUUID", "viam-system") viper.SetDefault("viamUUID", "viam-system")
viper.SetDefault("viamSession", "viam-session") viper.SetDefault("viamSession", "viam-session")
...@@ -106,6 +108,7 @@ func SetConfigValues() { ...@@ -106,6 +108,7 @@ func SetConfigValues() {
RestListenAddress = viper.GetString("restListenAddress") RestListenAddress = viper.GetString("restListenAddress")
DataStorageUrl = viper.GetString("dataStorageUrl") DataStorageUrl = viper.GetString("dataStorageUrl")
EntitiesManagerUrl = viper.GetString("entitiesManagerUrl")
SystemAuth.Uuid = viper.GetString("viamUUID") SystemAuth.Uuid = viper.GetString("viamUUID")
SystemAuth.Session = viper.GetString("viamSession") SystemAuth.Session = viper.GetString("viamSession")
......
...@@ -18,9 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -18,9 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package handler package handler
import ( import (
"encoding/base64"
"errors"
"log" "log"
"strings" "strings"
"code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/versions" "code.vereign.com/code/viam-apis/versions"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
...@@ -32,6 +35,10 @@ import ( ...@@ -32,6 +35,10 @@ import (
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
) )
const (
keyToKeyIdTable = "authenticationKeyToKeyId"
)
// Server represents the gRPC server // Server represents the gRPC server
type KeyStorageServerImpl struct { type KeyStorageServerImpl struct {
DataStorageUrl string DataStorageUrl string
...@@ -165,6 +172,17 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest ...@@ -165,6 +172,17 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
"200", api.StatusType_INFO, result) "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 return setKeyResponse, nil
} }
...@@ -209,6 +227,68 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser ...@@ -209,6 +227,68 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser
return reserveKeyUUIDResponse, nil 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) { func (s *KeyStorageServerImpl) GetVersionKSA(ctx context.Context, in *api.GetVersionKSAMessage) (*api.GetVersionKSAResponseMessage, error) {
log.Println("Version: " + version) log.Println("Version: " + version)
return &api.GetVersionKSAResponseMessage{Version: version, Errors: ""}, nil return &api.GetVersionKSAResponseMessage{Version: version, Errors: ""}, nil
......
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
"code.vereign.com/code/viam-apis/clientutils" "code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/data-storage-agent/client" "code.vereign.com/code/viam-apis/data-storage-agent/client"
dsclient "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/key-storage-agent/api"
"code.vereign.com/code/viam-apis/utils" "code.vereign.com/code/viam-apis/utils"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
...@@ -151,3 +152,8 @@ func CreateDataStorageClient(auth *authentication.Authentication) *dsclient.Data ...@@ -151,3 +152,8 @@ func CreateDataStorageClient(auth *authentication.Authentication) *dsclient.Data
return clientutils.CreateDataStorageClient(auth, config.DataStorageUrl, config.CertificatePEM, return clientutils.CreateDataStorageClient(auth, config.DataStorageUrl, config.CertificatePEM,
config.PrivateKeyPEM, config.CaCertificatePEM, config.MaxMessageSize) 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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment