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

Merge branch '235-device_management' into 'master'

supported key suspend

See merge request !35
parents 3408af22 8edc7bea
No related branches found
No related tags found
1 merge request!35supported key suspend
[[constraint]]
branch = "master"
branch = "added_key_suspend"
name = "code.vereign.com/code/viam-apis"
[[constraint]]
name = "github.com/golang/protobuf"
version = "1.1.0"
[[constraint]]
name = "github.com/grpc-ecosystem/grpc-gateway"
version = "1.4.1"
[[constraint]]
branch = "master"
name = "golang.org/x/net"
......
......@@ -27,40 +27,72 @@ import (
)
func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest) (*api.RevokeResponse, error) {
auth := s.CreateAuthentication(ctx)
client := keyutils.CreateDataStorageClient(auth)
defer client.CloseClient()
revokeResponse := &api.RevokeResponse{}
revokeResponse.StatusList = revokeKey(client, in.Uuid, api.KeyType_PRIVATE)
revokeResponse.StatusList = s.updateAll(ctx, in.Uuid, func(k *api.Key) { k.Revoked = true })
if revokeResponse.StatusList != nil {
return revokeResponse, nil
}
revokeResponse.StatusList = utils.AddStatus(revokeResponse.StatusList, "200", api.StatusType_INFO, "Keys revoked")
return revokeResponse, nil
}
revokeResponse.StatusList = revokeKey(client, in.Uuid, api.KeyType_PUBLIC)
if revokeResponse.StatusList != nil {
return revokeResponse, nil
func (s *KeyStorageServerImpl) Suspend(ctx context.Context, in *api.SuspendRequest) (*api.SuspendResponse, error) {
suspendResponse := &api.SuspendResponse{}
suspendResponse.StatusList = s.updateAll(ctx, in.Uuid, func(k *api.Key) { k.Suspended = true })
if suspendResponse.StatusList != nil {
return suspendResponse, nil
}
suspendResponse.StatusList = utils.AddStatus(suspendResponse.StatusList, "200", api.StatusType_INFO, "Keys suspended")
return suspendResponse, nil
}
revokeResponse.StatusList = revokeKey(client, in.Uuid, api.KeyType_CERTIFICATE)
if revokeResponse.StatusList != nil {
return revokeResponse, nil
func (s *KeyStorageServerImpl) Resume(ctx context.Context, in *api.ResumeRequest) (*api.ResumeResponse, error) {
resumeResponse := &api.ResumeResponse{}
resumeResponse.StatusList = s.updateAll(ctx, in.Uuid, func(k *api.Key) { k.Suspended = false })
if resumeResponse.StatusList != nil {
return resumeResponse, nil
}
resumeResponse.StatusList = utils.AddStatus(resumeResponse.StatusList, "200", api.StatusType_INFO, "Keys resumed")
return resumeResponse, nil
}
revokeResponse.StatusList = utils.AddStatus(revokeResponse.StatusList, "200", api.StatusType_INFO, "Keys revoked")
return revokeResponse, nil
func (s *KeyStorageServerImpl) Rename(ctx context.Context, in *api.RenameRequest) (*api.RenameResponse, error) {
renameResponse := &api.RenameResponse{}
renameResponse.StatusList = s.updateAll(ctx, in.Uuid, func(k *api.Key) { k.Name = in.Name })
if renameResponse.StatusList != nil {
return renameResponse, nil
}
renameResponse.StatusList = utils.AddStatus(renameResponse.StatusList, "200", api.StatusType_INFO, "Keys renamed")
return renameResponse, nil
}
func revokeKey(client *client.DataStorageClientImpl, uuid string, keyType api.KeyType) []*api.Status {
func (s *KeyStorageServerImpl) updateAll(ctx context.Context, uuid string, update func(*api.Key)) []*api.Status {
auth := s.CreateAuthentication(ctx)
client := keyutils.CreateDataStorageClient(auth)
defer client.CloseClient()
for _, kType := range []api.KeyType{api.KeyType_PRIVATE, api.KeyType_PUBLIC, api.KeyType_CERTIFICATE} {
statusList := updateKey(client, uuid, kType, update)
if statusList != nil {
return statusList
}
}
return nil
}
func updateKey(client *client.DataStorageClientImpl, uuid string, keyType api.KeyType, update func(*api.Key)) []*api.Status {
key, statusList := keyutils.GetKey(client, uuid, keyType)
if statusList != nil {
return statusList
}
key.Revoked = true
update(key)
_, errors, err := client.DoPutDataCall("keys", uuid+"/"+api.KeyType.String(keyType), key, versions.EntitiesManagementAgentApiVersion)
statusList = keyutils.HandlePutDataErrors(statusList, errors, err)
......
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