Skip to content

Commit

Permalink
face deletion implemented in eskimo
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus committed Jun 7, 2024
1 parent ee69332 commit 2b24c91
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ kyc/face:
bafToken: bogus
bafHost: http://bogus.com/
availabilityUrl:
secretApiToken: bogus-secret
concurrentUsers: 1
kyc/quiz:
environment: local
Expand Down
3 changes: 3 additions & 0 deletions cmd/eskimo-hut/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ func (s *service) DeleteUser( //nolint:gocritic // False negative.
if err := server.Auth(ctx).DeleteUser(ctx, req.Data.UserID); err != nil && !errors.Is(err, auth.ErrUserNotFound) {
return nil, server.Unexpected(errors.Wrapf(err, "failed to delete auth user:%#v", req.Data.UserID))
}
if err := s.faceKycClient.Reset(ctx, req.Data.UserID, false); err != nil {
return nil, server.Unexpected(errors.Wrapf(err, "failed to delete users face:%#v", req.Data.UserID))
}

return server.OK[any](), nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.137.0
github.com/ice-blockchain/wintr v1.138.0
github.com/imroc/req/v3 v3.43.7
github.com/ip2location/ip2location-go/v9 v9.7.0
github.com/jackc/pgx/v5 v5.6.0
Expand Down Expand Up @@ -91,7 +91,7 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -121,7 +121,7 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.44.0 // indirect
github.com/quic-go/quic-go v0.45.0 // indirect
github.com/refraction-networking/utls v1.6.6 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.137.0 h1:/AM6wcOW0Y20rWfCO0oLoEiLOqqNHlwawCszNFy6BTs=
github.com/ice-blockchain/wintr v1.137.0/go.mod h1:kUsre9Uz1PgqDjug+Rj3fDaFDiKQyz8ul9yCPraeEIA=
github.com/ice-blockchain/wintr v1.138.0 h1:vzNUBL9zHxpdWZ7ywlNCAdHjSKwCLKuW0e/6X3BrjcE=
github.com/ice-blockchain/wintr v1.138.0/go.mod h1:zUkkpYZ9P3F2F4ripoy1LsbYJPCvwGTMVBxNCtIEV0o=
github.com/imroc/req/v3 v3.43.7 h1:dOcNb9n0X83N5/5/AOkiU+cLhzx8QFXjv5MhikazzQA=
github.com/imroc/req/v3 v3.43.7/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA=
github.com/ip2location/ip2location-go/v9 v9.7.0 h1:ipwl67HOWcrw+6GOChkEXcreRQR37NabqBd2ayYa4Q0=
github.com/ip2location/ip2location-go/v9 v9.7.0/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
Expand Down Expand Up @@ -326,8 +326,8 @@ github.com/prometheus/prometheus v0.52.1 h1:BrQ29YG+mzdGh8DgHPirHbeMGNqtL+INe0rq
github.com/prometheus/prometheus v0.52.1/go.mod h1:3z74cVsmVH0iXOR5QBjB7Pa6A0KJeEAK5A6UsmAFb1g=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0=
github.com/quic-go/quic-go v0.44.0/go.mod h1:z4cx/9Ny9UtGITIPzmPTXh1ULfOyWh4qGQlpnPcWmek=
github.com/quic-go/quic-go v0.45.0 h1:OHmkQGM37luZITyTSu6ff03HP/2IrwDX1ZFiNEhSFUE=
github.com/quic-go/quic-go v0.45.0/go.mod h1:1dLehS7TIR64+vxGR70GDcatWTOtMX2PUtnKsjbTurI=
github.com/refraction-networking/utls v1.6.6 h1:igFsYBUJPYM8Rno9xUuDoM5GQrVEqY4llzEXOkL43Ig=
github.com/refraction-networking/utls v1.6.6/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
Expand Down
2 changes: 1 addition & 1 deletion kyc/face/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type (
ThreeDiVi threedivi.Config `mapstructure:",squash"` //nolint:tagliatelle // .
}
Client interface {
Reset(ctx context.Context, userID string) error
Reset(ctx context.Context, userID string, fetchState bool) error
CheckStatus(ctx context.Context, userID string, nextKYCStep users.KYCStep) (available bool, err error)
}
)
Expand Down
4 changes: 2 additions & 2 deletions kyc/face/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ func (c *client) CheckStatus(ctx context.Context, userID string, nextKYCStep use
return kycFaceAvailable, nil
}

func (c *client) Reset(ctx context.Context, userID string) error {
return errors.Wrapf(c.client.Reset(ctx, userID), "failed to reset face auth state for userID %s", userID)
func (c *client) Reset(ctx context.Context, userID string, fetchState bool) error {
return errors.Wrapf(c.client.Reset(ctx, userID, fetchState), "failed to reset face auth state for userID %s", userID)
}
2 changes: 1 addition & 1 deletion kyc/face/internal/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type (
Client interface {
Available(ctx context.Context) error
CheckAndUpdateStatus(ctx context.Context, userID string) (hasFaceKYCResult bool, err error)
Reset(ctx context.Context, userID string) error
Reset(ctx context.Context, userID string, fetchState bool) error
}
UserRepository interface {
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) error
Expand Down
1 change: 1 addition & 0 deletions kyc/face/internal/threedivi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type (
ThreeDiVi struct {
BAFHost string `yaml:"bafHost"`
BAFToken string `yaml:"bafToken"`
SecretAPIToken string `yaml:"secretApiToken"`
AvailabilityURL string `yaml:"availabilityUrl"`
ConcurrentUsers int `yaml:"concurrentUsers"`
} `yaml:"threeDiVi"`
Expand Down
13 changes: 9 additions & 4 deletions kyc/face/internal/threedivi/threedivi.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func (t *threeDivi) CheckAndUpdateStatus(ctx context.Context, userID string) (ha
return hasFaceKYCResult, errors.Wrapf(t.users.ModifyUser(ctx, usr, nil), "failed to update user with face kyc result")
}

//nolint:funlen // .
func (t *threeDivi) Reset(ctx context.Context, userID string) error {
//nolint:funlen,revive // .
func (t *threeDivi) Reset(ctx context.Context, userID string, fetchState bool) error {
bafApplicant, err := t.searchIn3DiviForApplicant(ctx, userID)
if err != nil {
if errors.Is(err, errFaceAuthNotStarted) {
Expand Down Expand Up @@ -157,16 +157,21 @@ func (t *threeDivi) Reset(ctx context.Context, userID string) error {
}).
AddQueryParam("caller", "eskimo-hut").
SetHeader("Authorization", fmt.Sprintf("Bearer %v", t.cfg.ThreeDiVi.BAFToken)).
SetHeader("X-Secret-Api-Token", t.cfg.ThreeDiVi.SecretAPIToken).
Delete(fmt.Sprintf("%v/publicapi/api/v2/private/Applicants/%v", t.cfg.ThreeDiVi.BAFHost, bafApplicant.ApplicantID)); err != nil {
return errors.Wrapf(err, "failed to delete face auth state for userID:%v", userID)
} else if statusCode := resp.GetStatusCode(); statusCode != http.StatusOK && statusCode != http.StatusNoContent {
return errors.Errorf("[%v]failed to delete face auth state for userID:%v", statusCode, userID)
} else if _, err2 := resp.ToBytes(); err2 != nil {
return errors.Wrapf(err2, "failed to read body of delete face auth state request for userID:%v", userID)
} else { //nolint:revive // .
_, err = t.CheckAndUpdateStatus(ctx, userID)
if fetchState {
_, err = t.CheckAndUpdateStatus(ctx, userID)

return errors.Wrapf(err, "failed to check user's face auth state after reset for userID %v", userID)
return errors.Wrapf(err, "failed to check user's face auth state after reset for userID %v", userID)
}

return nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion users/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type (
IsEmailUsedBySomebodyElse(ctx context.Context, userID, email string) (bool, error)
}
ResetKycClient interface {
Reset(ctx context.Context, userID string) error
Reset(ctx context.Context, userID string, fetchState bool) error
}
WriteRepository interface {
CreateUser(ctx context.Context, usr *User, clientIP net.IP) error
Expand Down
2 changes: 1 addition & 1 deletion users/kyc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *repository) resetKYCSteps(ctx context.Context, resetClient ResetKycClie
func (r *repository) resetKYCStep(ctx context.Context, resetClient ResetKycClient, userID string, step KYCStep) error {
switch step { //nolint:exhaustive // Not needed yet.
case FacialRecognitionKYCStep:
if err := resetClient.Reset(ctx, userID); err != nil {
if err := resetClient.Reset(ctx, userID, true); err != nil {
return errors.Wrapf(err, "failed to resetFacialRecognitionKYCStep for userID:%v", userID)
}
default:
Expand Down

0 comments on commit 2b24c91

Please sign in to comment.