Upstream sync

This commit is contained in:
Senad Uka
2023-10-24 05:48:19 +02:00
parent 2c267b71e4
commit fd880aeaa2
8 changed files with 83 additions and 77 deletions

View File

@@ -46,7 +46,16 @@ func SaveDeviceInfo(c *gin.Context) {
if deviceContract.Status == models.ContractStatusActive {
deviceInfoBytes, _ := json.Marshal(deviceInfo)
deviceInfoEncryptedStr, err := shared.NewEncryptionClient(config.AppConfig.Service.BlockchainSecret).Encrypt(string(deviceInfoBytes))
if deviceContract.BlockchainSecret == "" {
deviceContract.BlockchainSecret = shared.GenerateRandomString(BlockchainSecretLength)
_, _, err := contract.UpdateContract(deviceContract)
if err != nil {
log.Printf("SaveDeviceInfo Update Contract error: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not update contract secret"})
return
}
}
deviceInfoEncryptedStr, err := shared.NewEncryptionClient(deviceContract.BlockchainSecret).Encrypt(string(deviceInfoBytes))
if err != nil {
log.Printf("SaveDeviceInfo - Enrypt error : %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt device info"})