Skip to content

Commit

Permalink
update verifiction function to return bool representing verification …
Browse files Browse the repository at this point in the history
…status
  • Loading branch information
Eslam-Nawara committed Oct 30, 2024
1 parent 14c9747 commit 870feb7
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions pkg/provision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -1026,7 +1025,7 @@ func (n *NativeEngine) CreateOrUpdate(twin uint32, deployment gridtypes.Deployme

// make sure the account used is verified
check := func() error {
if getTwinVerificationStatus(twin) != "VERIFIED" {
if getTwinVerificationStatus(twin) {
return fmt.Errorf("user is not verified")
}
return nil
Expand Down Expand Up @@ -1191,8 +1190,8 @@ func (e *NativeEngine) GetWorkloadStatus(id string) (gridtypes.ResultState, bool
}

// getTwinVerificationStatus make sure the account used is verified we have the user public key in bytes(pkBytes)
func getTwinVerificationStatus(twinID uint32) (status string) {
status = "FAILED"
func getTwinVerificationStatus(twinID uint32) (verified bool) {
const verifiedStatus = "VERIFIED"
env := environment.MustGet()

verificationServiceURL, err := url.JoinPath(env.KycURL, "/api/v1/status")
Expand All @@ -1219,27 +1218,17 @@ func getTwinVerificationStatus(twinID uint32) (status string) {
}
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
if response.StatusCode != http.StatusOK {
log.Error().Msg("failed to verify user status")
return
}

var result struct {
Result struct {
Status string `json:"status"`
} `json:"result"`
Error string `json:"error"`
}
var result struct{ Result struct{ Status string } }

err = json.Unmarshal(body, &result)
err = json.NewDecoder(response.Body).Decode(&result)
if err != nil {
return
}

if response.StatusCode != http.StatusOK {
log.Error().Msgf("failed to verify user status: %s", result.Error)
return
}

return result.Result.Status
return result.Result.Status == verifiedStatus
}

0 comments on commit 870feb7

Please sign in to comment.