Skip to content
Snippets Groups Projects
Commit bbf6ea8d authored by Alexander Holodov's avatar Alexander Holodov
Browse files

supported key suspend

parent a805c8bc
Branches
Tags
1 merge request!32supported key suspend
[[constraint]] [[constraint]]
branch = "master" branch = "added_key_suspend"
name = "code.vereign.com/code/viam-apis" name = "code.vereign.com/code/viam-apis"
[[constraint]] [[constraint]]
name = "github.com/golang/protobuf" name = "github.com/golang/protobuf"
version = "1.1.0" version = "1.1.0"
[[constraint]]
name = "github.com/grpc-ecosystem/grpc-gateway"
version = "1.4.1"
[[constraint]] [[constraint]]
branch = "master" branch = "master"
name = "golang.org/x/net" name = "golang.org/x/net"
......
...@@ -26,41 +26,73 @@ import ( ...@@ -26,41 +26,73 @@ import (
) )
func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest) (*api.RevokeResponse, error) { func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest) (*api.RevokeResponse, error) {
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertPEM, s.KeyPEM, s.CaCertPEM, s.MaxMessageSize)
defer client.CloseClient()
revokeResponse := &api.RevokeResponse{} 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 { if revokeResponse.StatusList != nil {
return revokeResponse, 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) func (s *KeyStorageServerImpl) Suspend(ctx context.Context, in *api.SuspendRequest) (*api.SuspendResponse, error) {
if revokeResponse.StatusList != nil { suspendResponse := &api.SuspendResponse{}
return revokeResponse, nil
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) func (s *KeyStorageServerImpl) Resume(ctx context.Context, in *api.ResumeRequest) (*api.ResumeResponse, error) {
if revokeResponse.StatusList != nil { resumeResponse := &api.ResumeResponse{}
return revokeResponse, nil
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") func (s *KeyStorageServerImpl) Rename(ctx context.Context, in *api.RenameRequest) (*api.RenameResponse, error) {
return revokeResponse, nil 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 := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertPEM, s.KeyPEM, s.CaCertPEM, s.MaxMessageSize)
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 := getKey(client, uuid, keyType) key, statusList := getKey(client, uuid, keyType)
if statusList != nil { if statusList != nil {
return statusList return statusList
} }
key.Revoked = true update(key)
_, errors, err := client.DoPutDataCall("keys", uuid+"/"+api.KeyType.String(keyType), key, versions.EntitiesManagementAgentApiVersion) _, errors, err := client.DoPutDataCall("keys", uuid+"/"+api.KeyType.String(keyType), key, versions.EntitiesManagementAgentApiVersion)
statusList = handlePutDataErrors(statusList, errors, err) statusList = handlePutDataErrors(statusList, errors, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment