mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
context: Add authenticated HTTP credentials (#892)
* gRPC: context overide * exchanges: continue update * exchange: Update context handling *Add setter methods for API credentials *Shift credentials functionality to its own file in exchanges package *Add tests *Refactor function DeployCredentialsToContext for library usage *Add function to process credential metadata from API boundary to internal use context value. *Add OTP rpc handling * exchanges: reverts to old style in GetFeeByType, reverts some code I accidently deleted. Plus things and other. XD * template: update * exchanges: fix linter issues * REMOVE THAT AWESOME NEW LINE! * gct: fix some tests * I cant spell :( * exchanges/gctscript: fix more tests * coinnut: fix tests * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * exchanges/gctcli: stop applying empty credentials * fix linters * exchanges: add test * rpceserver: actually check error for errors * rpcserver: fix up tests * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * exchanges/creds: move tests to corresponding files, add protection and segration for Credentials struct & ptr values * exchanges/creds: allow subaccount to override default credentials via gRPC * exchanges/credentials: don't return nil in GetCredentials * creds: spelling * exchanges: fix glorious NITS! * credentials: Add in test and refactor IsEmpty method. * credentials: change type positioning (glorious) * exchange_template: Fix template changes * DOCS: Refresh * docs: fix spelling * DOCS: fix alignment and add package * DOCS: ALIGN! Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -202,45 +202,43 @@ func shouldLoadExchange(name string) bool {
|
||||
func setExchangeAPIKeys(name string, keys map[string]*config.APICredentialsConfig, base *exchange.Base) bool {
|
||||
lowerExchangeName := strings.ToLower(name)
|
||||
|
||||
if base.API.CredentialsValidator.RequiresKey && keys[lowerExchangeName].Key == "" {
|
||||
keys[lowerExchangeName].Key = config.DefaultAPIKey
|
||||
}
|
||||
if base.API.CredentialsValidator.RequiresSecret && keys[lowerExchangeName].Secret == "" {
|
||||
keys[lowerExchangeName].Secret = config.DefaultAPISecret
|
||||
}
|
||||
if base.API.CredentialsValidator.RequiresPEM && keys[lowerExchangeName].PEMKey == "" {
|
||||
keys[lowerExchangeName].PEMKey = "PEM"
|
||||
}
|
||||
if base.API.CredentialsValidator.RequiresClientID && keys[lowerExchangeName].ClientID == "" {
|
||||
keys[lowerExchangeName].ClientID = config.DefaultAPIClientID
|
||||
}
|
||||
if keys[lowerExchangeName].OTPSecret == "" {
|
||||
keys[lowerExchangeName].OTPSecret = "-" // Ensure OTP is available for use
|
||||
creds, ok := keys[lowerExchangeName]
|
||||
if !ok {
|
||||
log.Printf("%s credentials not found in keys map\n", name)
|
||||
return false
|
||||
}
|
||||
|
||||
base.API.Credentials.Key = keys[lowerExchangeName].Key
|
||||
base.Config.API.Credentials.Key = keys[lowerExchangeName].Key
|
||||
|
||||
base.API.Credentials.Secret = keys[lowerExchangeName].Secret
|
||||
base.Config.API.Credentials.Secret = keys[lowerExchangeName].Secret
|
||||
|
||||
base.API.Credentials.ClientID = keys[lowerExchangeName].ClientID
|
||||
base.Config.API.Credentials.ClientID = keys[lowerExchangeName].ClientID
|
||||
|
||||
if keys[lowerExchangeName].OTPSecret != "-" {
|
||||
base.Config.API.Credentials.OTPSecret = keys[lowerExchangeName].OTPSecret
|
||||
if base.API.CredentialsValidator.RequiresKey && creds.Key == "" {
|
||||
creds.Key = config.DefaultAPIKey
|
||||
}
|
||||
if keys[lowerExchangeName].Subaccount != "" {
|
||||
base.API.Credentials.Subaccount = keys[lowerExchangeName].Subaccount
|
||||
base.Config.API.Credentials.Subaccount = keys[lowerExchangeName].Subaccount
|
||||
if base.API.CredentialsValidator.RequiresSecret && creds.Secret == "" {
|
||||
creds.Secret = config.DefaultAPISecret
|
||||
}
|
||||
if base.API.CredentialsValidator.RequiresPEM && creds.PEMKey == "" {
|
||||
creds.PEMKey = "PEM"
|
||||
}
|
||||
if base.API.CredentialsValidator.RequiresClientID && creds.ClientID == "" {
|
||||
creds.ClientID = config.DefaultAPIClientID
|
||||
}
|
||||
if creds.OTPSecret == "" {
|
||||
creds.OTPSecret = "-" // Ensure OTP is available for use
|
||||
}
|
||||
|
||||
base.SetCredentials(creds.Key, creds.Secret, creds.ClientID, creds.Subaccount, creds.PEMKey, creds.OTPSecret)
|
||||
|
||||
base.Config.API.Credentials.Key = creds.Key
|
||||
base.Config.API.Credentials.Secret = creds.Secret
|
||||
base.Config.API.Credentials.ClientID = creds.ClientID
|
||||
base.Config.API.Credentials.Subaccount = creds.Subaccount
|
||||
base.Config.API.Credentials.PEMKey = creds.PEMKey
|
||||
base.Config.API.Credentials.OTPSecret = creds.OTPSecret
|
||||
|
||||
base.API.AuthenticatedSupport = true
|
||||
base.API.AuthenticatedWebsocketSupport = true
|
||||
base.Config.API.AuthenticatedSupport = true
|
||||
base.Config.API.AuthenticatedWebsocketSupport = true
|
||||
|
||||
return base.ValidateAPICredentials()
|
||||
return base.ValidateAPICredentials(base.GetDefaultCredentials()) == nil
|
||||
}
|
||||
|
||||
func parseOrderSide(orderSide string) order.Side {
|
||||
|
||||
Reference in New Issue
Block a user