Skip to content

Commit

Permalink
fix merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
husobee committed Aug 18, 2023
2 parents 240ffcf + 0477b4e commit 5fd9b51
Show file tree
Hide file tree
Showing 50 changed files with 1,906 additions and 458 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ services:
- pg_data:/var/lib/postgresql/data
- ./create_dbs.sh:/docker-entrypoint-initdb.d/00_create_dbs.sh
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
test: ["CMD-SHELL", "pg_isready -U grants -d grants"]
interval: 5s
timeout: 5s
retries: 5
Expand Down
68 changes: 49 additions & 19 deletions libs/clients/gemini/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"

Expand All @@ -26,6 +27,19 @@ import (
"github.com/shopspring/decimal"
)

// isIssueCountryEnabled temp feature flag for Gemini endpoint update
func isIssueCountryEnabled() bool {
var toggle = false
if os.Getenv("GEMINI_ISSUING_COUNTRY_ENABLED") != "" {
var err error
toggle, err = strconv.ParseBool(os.Getenv("GEMINI_ISSUING_COUNTRY_ENABLED"))
if err != nil {
return false
}
}
return toggle
}

var (
balanceGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gemini_account_balance",
Expand All @@ -40,24 +54,29 @@ var (
[]string{"country_code", "status"},
)

countGeminiDocumentTypeByIssuingCountry = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "count_gemini_document_type_by_issuing_country",
Help: "Counts the number document types being used for KYC broken down by country",
},
[]string{"document_type", "issuing_country"},
)

documentTypePrecedence = []string{
"passport",
"drivers_license",
"national_identity_card",
"passport_card",
"tax_id",
"residence_permit",
"work_permit",
"voter_id",
"visa",
"national_insurance_card",
"indigenous_card",
}
)

// ErrNoAcceptedDocumentType is the returned error when no accepted documents exist in the Gemini response.
var ErrNoAcceptedDocumentType = errors.New("no accepted document type")

func init() {
prometheus.MustRegister(balanceGauge)
prometheus.MustRegister(countGeminiWalletAccountValidation)
prometheus.MustRegister(countGeminiDocumentTypeByIssuingCountry)
}

// WatchGeminiBalance - when called reports the balance to prometheus
Expand Down Expand Up @@ -497,13 +516,24 @@ func (c *HTTPClient) ValidateAccount(ctx context.Context, verificationToken, rec
return "", res.CountryCode, err
}

if len(res.ValidDocuments) <= 0 {
return "", "", errors.New("error no valid documents in response")
}
issuingCountry := res.CountryCode

if isIssueCountryEnabled() {
if len(res.ValidDocuments) <= 0 {
return "", "", errors.New("error no valid documents in response")
}

for i := range res.ValidDocuments {
countGeminiDocumentTypeByIssuingCountry.With(prometheus.Labels{
"document_type": res.ValidDocuments[i].Type,
"issuing_country": res.ValidDocuments[i].IssuingCountry,
}).Inc()
}

issuingCountry := strings.ToUpper(res.ValidDocuments[0].IssuingCountry)
if dcountry := countryForDocByPrecendence(documentTypePrecedence, res.ValidDocuments); dcountry != "" {
issuingCountry = strings.ToUpper(dcountry)
issuingCountry = countryForDocByPrecedence(documentTypePrecedence, res.ValidDocuments)
if issuingCountry == "" {
return "", "", ErrNoAcceptedDocumentType
}
}

// feature flag for using new custodian regions
Expand All @@ -513,7 +543,7 @@ func (c *HTTPClient) ValidateAccount(ctx context.Context, verificationToken, rec
allowed := custodianRegions.Gemini.Verdict(issuingCountry)
if !allowed {
countGeminiWalletAccountValidation.With(prometheus.Labels{
"country_code": res.CountryCode,
"country_code": issuingCountry,
"status": "failure",
}).Inc()
return res.ID, issuingCountry, errorutils.ErrInvalidCountry
Expand All @@ -523,7 +553,7 @@ func (c *HTTPClient) ValidateAccount(ctx context.Context, verificationToken, rec
if blacklist, ok := ctx.Value(appctx.BlacklistedCountryCodesCTXKey).([]string); ok {
// check country code
for _, v := range blacklist {
if strings.EqualFold(res.CountryCode, v) {
if strings.EqualFold(issuingCountry, v) {
if issuingCountry != "" {
countGeminiWalletAccountValidation.With(prometheus.Labels{
"country_code": issuingCountry,
Expand All @@ -535,7 +565,7 @@ func (c *HTTPClient) ValidateAccount(ctx context.Context, verificationToken, rec
}
}
}
if res.CountryCode != "" {
if issuingCountry != "" {
countGeminiWalletAccountValidation.With(prometheus.Labels{
"country_code": issuingCountry,
"status": "success",
Expand Down Expand Up @@ -593,13 +623,13 @@ func (c *HTTPClient) FetchBalances(
return &body, err
}

func countryForDocByPrecendence(prec []string, docs []ValidDocument) string {
func countryForDocByPrecedence(precedence []string, docs []ValidDocument) string {
var result string

for _, pdoc := range prec {
for _, pdoc := range precedence {
for _, vdoc := range docs {
if strings.EqualFold(pdoc, vdoc.Type) {
return vdoc.IssuingCountry
return strings.ToUpper(vdoc.IssuingCountry)
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions libs/clients/gemini/clientx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
should "github.com/stretchr/testify/assert"
)

func TestCountryForDocByPrecendence(t *testing.T) {
func TestCountryForDocByPrecedence(t *testing.T) {
type testCase struct {
name string
given []ValidDocument
Expand Down Expand Up @@ -60,13 +60,39 @@ func TestCountryForDocByPrecendence(t *testing.T) {
},
exp: "US",
},

{
name: "no_valid_document_type",
given: []ValidDocument{
{
Type: "invalid_type",
IssuingCountry: "US",
},
},
exp: "",
},

{
name: "valid_and_invalid_document_type_lower_case",
given: []ValidDocument{
{
Type: "invalid_type",
IssuingCountry: "US",
},
{
Type: "passport",
IssuingCountry: "uk",
},
},
exp: "UK",
},
}

for i := range tests {
tc := tests[i]

t.Run(tc.name, func(t *testing.T) {
act := countryForDocByPrecendence(documentTypePrecedence, tc.given)
act := countryForDocByPrecedence(documentTypePrecedence, tc.given)
should.Equal(t, tc.exp, act)
})
}
Expand Down
8 changes: 4 additions & 4 deletions libs/context/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ const (
BuildTimeCTXKey CTXKey = "build_time"
// ReputationClientCTXKey - context key for the build time of code
ReputationClientCTXKey CTXKey = "reputation_client"
// XyzAbcLinkingKeyCTXKey - context key for the build time of code
XyzAbcLinkingKeyCTXKey CTXKey = "xyzabc_linking_key"
// DisableXyzAbcLinkingCTXKey - context key for the build time of code
DisableXyzAbcLinkingCTXKey CTXKey = "disable_xyzabc_linking"
// ZebPayLinkingKeyCTXKey - context key for the build time of code
ZebPayLinkingKeyCTXKey CTXKey = "zebpay_linking_key"
// DisableZebPayLinkingCTXKey - context key for the build time of code
DisableZebPayLinkingCTXKey CTXKey = "disable_zebpay_linking"
// GeminiClientCTXKey - context key for the build time of code
GeminiClientCTXKey CTXKey = "gemini_client"
// GeminiBrowserClientIDCTXKey - context key for the gemini browser client id
Expand Down
2 changes: 2 additions & 0 deletions libs/custodian/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type PayoutStatus struct {
Uphold string `json:"uphold" valid:"in(off|processing|complete)"`
Gemini string `json:"gemini" valid:"in(off|processing|complete)"`
Bitflyer string `json:"bitflyer" valid:"in(off|processing|complete)"`
Zebpay string `json:"zebpay" valid:"in(off|processing|complete)"`
Date string `json:"payoutDate" valid:"-"`
}

Expand Down Expand Up @@ -139,6 +140,7 @@ type Regions struct {
Uphold GeoAllowBlockMap `json:"uphold" valid:"-"`
Gemini GeoAllowBlockMap `json:"gemini" valid:"-"`
Bitflyer GeoAllowBlockMap `json:"bitflyer" valid:"-"`
Zebpay GeoAllowBlockMap `json:"zebpay" valid:"-"`
}

// HandleErrors - handle any errors in input
Expand Down
1 change: 1 addition & 0 deletions libs/custodian/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (tx Transaction) BitflyerTransferID() string {
inputs := []string{
tx.SettlementID,
tx.WalletProviderID,
tx.Destination,
}
key := strings.Join(inputs, "_")
bytes := sha256.Sum256([]byte(key))
Expand Down
56 changes: 28 additions & 28 deletions main/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ require (
require (
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.11.0 // indirect
cloud.google.com/go/kms v1.6.0 // indirect
cloud.google.com/go/monitoring v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go v67.0.0+incompatible // indirect
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/kms v1.9.0 // indirect
cloud.google.com/go/monitoring v1.12.0 // indirect
github.com/Azure/azure-sdk-for-go v67.2.0+incompatible // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.28 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.21 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.11 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
Expand All @@ -39,7 +39,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1831 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.62.146 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
Expand Down Expand Up @@ -73,11 +73,10 @@ require (
github.com/circonus-labs/circonusllhist v0.1.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.14.0 // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-chi/cors v1.2.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
Expand All @@ -102,21 +101,21 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.3.1 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.5 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/aead/v2 v2.0.4 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.8 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/aead/v2 v2.0.7-1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/alicloudkms/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.0 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2 v2.0.7 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.7 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.8 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.7 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.7 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.5 // indirect
github.com/hashicorp/go-plugin v1.4.8 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/awsutil v0.1.6 // indirect
Expand All @@ -130,9 +129,9 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hashicorp/hcp-sdk-go v0.23.0 // indirect
github.com/hashicorp/vault v1.12.7 // indirect
github.com/hashicorp/vault/api v1.8.1 // indirect
github.com/hashicorp/vault/sdk v0.6.1-0.20230427140652-b4b396ffc14f // indirect
github.com/hashicorp/vault v1.13.5 // indirect
github.com/hashicorp/vault/api v1.9.0 // indirect
github.com/hashicorp/vault/sdk v0.8.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
Expand All @@ -144,12 +143,12 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/linkedin/goavro v2.1.0+incompatible // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/cli v1.1.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -163,6 +162,7 @@ require (
github.com/natefinch/atomic v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/oracle/oci-go-sdk/v60 v60.0.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
Expand Down Expand Up @@ -192,7 +192,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/square/go-jose v2.6.0+incompatible // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/stripe/stripe-go/v72 v72.122.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/superp00t/niceware v0.0.0-20170614015008-16cb30c384b5 // indirect
Expand All @@ -205,17 +205,17 @@ require (
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.29.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/macaroon.v2 v2.1.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
Expand Down
Loading

0 comments on commit 5fd9b51

Please sign in to comment.