Skip to content

Commit

Permalink
auth overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
friofry committed Dec 4, 2024
1 parent af2e372 commit 8195c81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
46 changes: 8 additions & 38 deletions api/default_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package api

import (
"fmt"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/params/networkhelper"
"github.com/status-im/status-go/protocol/requests"
)

Expand Down Expand Up @@ -260,47 +259,18 @@ var mainnetGanacheTokenOverrides = params.TokenOverride{
}

func setRPCs(networks []params.Network, request *requests.WalletSecretsConfig) []params.Network {

var networksWithRPC []params.Network

const (
infura = "infura.io/"
grove = "grove.city/"
)

appendToken := func(url string) string {
if strings.Contains(url, infura) && request.InfuraToken != "" {
return url + request.InfuraToken
} else if strings.Contains(url, grove) && request.PoktToken != "" {
return url + request.PoktToken
}
return url
authTokens := map[string]string{
"infura.io": request.InfuraToken,
"grove.city": request.PoktToken,
}

for _, n := range networks {
var updatedProviders []params.RpcProvider
for _, provider := range n.RpcProviders {
updatedProvider := provider
updatedProvider.URL = appendToken(provider.URL)
// Handle Ganache URL override
if request.GanacheURL != "" {
updatedProvider.URL = request.GanacheURL
}
updatedProviders = append(updatedProviders, updatedProvider)
}

// Apply token overrides for Ganache networks
if request.GanacheURL != "" && n.ChainID == mainnetChainID {
n.TokenOverrides = []params.TokenOverride{
mainnetGanacheTokenOverrides,
}
}
updatedNetworks := networkhelper.OverrideDirectProvidersAuth(networks, authTokens)

n.RpcProviders = updatedProviders
networksWithRPC = append(networksWithRPC, n)
if request.GanacheURL != "" {
updatedNetworks = networkhelper.OverrideGanacheToken(updatedNetworks, request.GanacheURL, mainnetChainID, mainnetGanacheTokenOverrides)
}

return networksWithRPC
return networks
}

func BuildDefaultNetworks(walletSecretsConfig *requests.WalletSecretsConfig) []params.Network {
Expand Down
6 changes: 2 additions & 4 deletions node/get_status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,12 @@ func (n *StatusNode) setupRPCClient() (err error) {
// Proxy AuthConfigs should be passed not in wallet secrets config on login
// but some other way, as it's not wallet specific and should not be passed with login request
// but currently there is no other way to pass it
networks, err := networkhelper.UpdateEmbeddedProxyProviders(
// (maybe move to default_networks.go)
networks := networkhelper.OverrideEmbeddedProxyProviders(
n.config.Networks,
n.config.WalletConfig.StatusProxyEnabled,
n.config.WalletConfig.StatusProxyBlockchainUser,
n.config.WalletConfig.StatusProxyBlockchainPassword)
if err != nil {
return
}

config := rpc.ClientConfig{
Client: gethNodeClient,
Expand Down
5 changes: 2 additions & 3 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestGetClientsUsingCache(t *testing.T) {
Type: params.EmbeddedProxyProviderType,
AuthType: params.BasicAuth,
AuthLogin: "incorrectUser",
AuthPassword: "incorrectPwd", // will be replaced by correct values by UpdateEmbeddedProxyProviders
AuthPassword: "incorrectPwd", // will be replaced by correct values by OverrideEmbeddedProxyProviders
Enabled: true,
})
}
Expand All @@ -171,8 +171,7 @@ func TestGetClientsUsingCache(t *testing.T) {
},
}

networks, err := networkhelper.UpdateEmbeddedProxyProviders(networks, true, user, password)
require.NoError(t, err)
networks = networkhelper.OverrideEmbeddedProxyProviders(networks, true, user, password)

config := ClientConfig{
Client: nil,
Expand Down

0 comments on commit 8195c81

Please sign in to comment.