fix: add GetEncryptKeysRpc (#13799)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-03-27 14:49:00 +08:00
committed by GitHub
co-authored by Qiu Jian
parent a5c27565d5
commit 79affb7c81
2 changed files with 13 additions and 7 deletions
-7
View File
@@ -82,13 +82,6 @@ func (manager *SEncryptedResourceManager) ValidateCreateData(
if err != nil {
return input, errors.Wrap(err, "GetString key Id")
}
userId, err := keyObj.GetString("user_id")
if err != nil {
return input, errors.Wrap(err, "GetString user id")
}
if userId != ownerId.GetUserId() {
return input, errors.Wrap(httperrors.ErrForbidden, "non-owner not allow to access key")
}
input.EncryptKeyId = &keyId
}
return input, nil
@@ -321,6 +321,19 @@ func DecodeEncryptKey(secret jsonutils.JSONObject) (SEncryptKeySecret, error) {
return curr, nil
}
func (manager *SCredentialManager) GetEncryptKeysRpc(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.
JSONObject, error) {
keys, err := manager.GetEncryptKeys(s, "")
if err != nil {
return nil, errors.Wrap(err, "GetEncryptKeys")
}
ret := jsonutils.NewArray()
for _, key := range keys {
ret.Add(key.Marshal())
}
return ret, nil
}
func (manager *SCredentialManager) GetEncryptKeys(s *mcclient.ClientSession, uid string) ([]SEncryptKeySecret, error) {
secrets, err := manager.FetchEncryptionKeys(s, uid)
if err != nil {