fix: password not saved correctly when editing asset
This commit is contained in:
+11
-1
@@ -212,7 +212,7 @@ func (assetApi AssetApi) AssetGetEndpoint(c echo.Context) (err error) {
|
|||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
var item model.Asset
|
var item model.Asset
|
||||||
if item, err = service.AssetService.FindByIdAndDecrypt(context.TODO(), id); err != nil {
|
if item, err = repository.AssetRepository.FindById(context.TODO(), id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
attributeMap, err := repository.AssetRepository.FindAssetAttrMapByAssetId(context.TODO(), id)
|
attributeMap, err := repository.AssetRepository.FindAssetAttrMapByAssetId(context.TODO(), id)
|
||||||
@@ -224,6 +224,16 @@ func (assetApi AssetApi) AssetGetEndpoint(c echo.Context) (err error) {
|
|||||||
itemMap[key] = attributeMap[key]
|
itemMap[key] = attributeMap[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.Password != "" && item.Password != "-" {
|
||||||
|
itemMap["password"] = ""
|
||||||
|
}
|
||||||
|
if item.PrivateKey != "" && item.PrivateKey != "-" {
|
||||||
|
itemMap["privateKey"] = ""
|
||||||
|
}
|
||||||
|
if item.Passphrase != "" && item.Passphrase != "-" {
|
||||||
|
itemMap["passphrase"] = ""
|
||||||
|
}
|
||||||
|
|
||||||
return Success(c, itemMap)
|
return Success(c, itemMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -248,6 +248,11 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingAsset, err := repository.AssetRepository.FindById(context.TODO(), id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
switch item.AccountType {
|
switch item.AccountType {
|
||||||
case "credential":
|
case "credential":
|
||||||
item.Username = "-"
|
item.Username = "-"
|
||||||
@@ -261,9 +266,9 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
item.Username = "-"
|
item.Username = "-"
|
||||||
}
|
}
|
||||||
if len(item.Passphrase) == 0 {
|
if len(item.Passphrase) == 0 {
|
||||||
item.Passphrase = "-"
|
item.Passphrase = existingAsset.Passphrase
|
||||||
}
|
}
|
||||||
case "custom":
|
case "password":
|
||||||
item.PrivateKey = "-"
|
item.PrivateKey = "-"
|
||||||
item.Passphrase = "-"
|
item.Passphrase = "-"
|
||||||
item.CredentialId = "-"
|
item.CredentialId = "-"
|
||||||
@@ -271,7 +276,8 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
item.Username = "-"
|
item.Username = "-"
|
||||||
}
|
}
|
||||||
if len(item.Password) == 0 {
|
if len(item.Password) == 0 {
|
||||||
item.Password = "-"
|
item.Password = existingAsset.Password
|
||||||
|
item.Encrypted = existingAsset.Encrypted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,8 +293,10 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
|||||||
item.AccessGatewayId = "-"
|
item.AccessGatewayId = "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
if item.Password != "" && item.Password != "-" && !item.Encrypted {
|
||||||
return err
|
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.Transaction(context.Background(), func(ctx context.Context) error {
|
return s.Transaction(context.Background(), func(ctx context.Context) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user