@@ -5,18 +5,20 @@ import (
5
5
"encoding/hex"
6
6
"encoding/json"
7
7
"fmt"
8
- "io"
9
8
"net/http"
9
+ "net/url"
10
10
"os"
11
11
"path/filepath"
12
12
"sort"
13
13
"time"
14
14
15
+ "github.com/cenkalti/backoff/v3"
15
16
"github.com/joncrlsn/dque"
16
17
"github.com/pkg/errors"
17
18
"github.com/rs/zerolog/log"
18
19
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
19
20
"github.com/threefoldtech/zos4/pkg"
21
+ "github.com/threefoldtech/zos4/pkg/environment"
20
22
"github.com/threefoldtech/zos4/pkg/gridtypes"
21
23
"github.com/threefoldtech/zos4/pkg/gridtypes/zos"
22
24
"github.com/threefoldtech/zos4/pkg/stubs"
@@ -1022,8 +1024,15 @@ func (n *NativeEngine) CreateOrUpdate(twin uint32, deployment gridtypes.Deployme
1022
1024
}
1023
1025
1024
1026
// make sure the account used is verified
1025
- if getTwinVerificationState (twin ) != "VERIFIED" {
1026
- return fmt .Errorf ("user is not verified" )
1027
+ check := func () error {
1028
+ if ! isTwinVerified (twin ) {
1029
+ return fmt .Errorf ("user is not verified" )
1030
+ }
1031
+ return nil
1032
+ }
1033
+
1034
+ if err := backoff .Retry (check , backoff .WithMaxRetries (backoff .NewExponentialBackOff (), 5 )); err != nil {
1035
+ return err
1027
1036
}
1028
1037
1029
1038
if err := deployment .Verify (n .twins ); err != nil {
@@ -1180,18 +1189,23 @@ func (e *NativeEngine) GetWorkloadStatus(id string) (gridtypes.ResultState, bool
1180
1189
return wl .Result .State , true , nil
1181
1190
}
1182
1191
1183
- // getTwinVerificationState make sure the account used is verified we have the user public key in bytes(pkBytes)
1184
- func getTwinVerificationState (twinID uint32 ) (status string ) {
1185
- verificationServiceURL := "https://kyc1.gent01.dev.grid.tf/api/v1/status"
1186
- status = "FAILED"
1192
+ // isTwinVerified make sure the account used is verified
1193
+ func isTwinVerified (twinID uint32 ) (verified bool ) {
1194
+ const verifiedStatus = "VERIFIED"
1195
+ env := environment .MustGet ()
1196
+
1197
+ verificationServiceURL , err := url .JoinPath (env .KycURL , "/api/v1/status" )
1198
+ if err != nil {
1199
+ return
1200
+ }
1187
1201
1188
1202
request , err := http .NewRequest (http .MethodGet , verificationServiceURL , nil )
1189
1203
if err != nil {
1190
1204
return
1191
1205
}
1192
1206
1193
1207
q := request .URL .Query ()
1194
- q .Set ("twinID " , fmt .Sprint (twinID ))
1208
+ q .Set ("twin_id " , fmt .Sprint (twinID ))
1195
1209
request .URL .RawQuery = q .Encode ()
1196
1210
1197
1211
cl := & http.Client {
@@ -1204,21 +1218,17 @@ func getTwinVerificationState(twinID uint32) (status string) {
1204
1218
}
1205
1219
defer response .Body .Close ()
1206
1220
1207
- body , err := io . ReadAll ( response . Body )
1208
- if err != nil {
1221
+ if response . StatusCode != http . StatusOK {
1222
+ log . Error (). Msg ( "failed to get user status" )
1209
1223
return
1210
1224
}
1211
1225
1212
- bodyMap := map [string ]string {}
1213
- err = json .Unmarshal (body , & bodyMap )
1214
- if err != nil {
1215
- return
1216
- }
1226
+ var result struct { Result struct { Status string } }
1217
1227
1218
- if response . StatusCode != http . StatusOK {
1219
- log . Error (). Msgf ( "failed to verify user status: %s" , bodyMap [ "error" ])
1228
+ err = json . NewDecoder ( response . Body ). Decode ( & result )
1229
+ if err != nil {
1220
1230
return
1221
1231
}
1222
1232
1223
- return bodyMap [ "status" ]
1233
+ return result . Result . Status == verifiedStatus
1224
1234
}
0 commit comments