kopia lustrzana https://github.com/bugout-dev/moonstream
Fixed internal crawlers access bug, small config fixes
rodzic
62d786a8a6
commit
de609da7cd
|
@ -1,17 +1,47 @@
|
|||
# Node Balancer application
|
||||
|
||||
# Installation
|
||||
## Installation and configuration
|
||||
|
||||
- Prepare environment variables
|
||||
- Prepare environment variables, according with `sample.env`.
|
||||
- Build application
|
||||
|
||||
```bash
|
||||
go build -o nodebalancer .
|
||||
```
|
||||
|
||||
# Work with nodebalancer
|
||||
- Generate configuration
|
||||
|
||||
## add-access
|
||||
```bash
|
||||
nodebalancer generate-config
|
||||
```
|
||||
|
||||
- Modify configuration. Tags should NOT repeat blockchain, as it is specified in `blockchain` key. Example of configuration:
|
||||
|
||||
```bash
|
||||
[
|
||||
{
|
||||
"blockchain": "ethereum",
|
||||
"endpoint": "http://127.0.0.1:8545",
|
||||
"tags": ["local"]
|
||||
},
|
||||
{
|
||||
"blockchain": "ethereum",
|
||||
"endpoint": "http://127.0.0.1:9585",
|
||||
"tags": ["local"]
|
||||
},
|
||||
{
|
||||
"blockchain": "ethereum",
|
||||
"endpoint": "https://cool-name.quiknode.pro/y0urn0de1den1f1cat0r/",
|
||||
"tags": ["external"]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
So if with request will be specified tag `local` will be returned node with corresponding tag.
|
||||
|
||||
## Work with nodebalancer
|
||||
|
||||
### add-access
|
||||
|
||||
Add new access for user:
|
||||
|
||||
|
@ -25,7 +55,7 @@ nodebalancer add-access \
|
|||
--blockchain--access true
|
||||
```
|
||||
|
||||
## delete-access
|
||||
### delete-access
|
||||
|
||||
Delete user access:
|
||||
|
||||
|
@ -37,7 +67,7 @@ nodebalancer delete-access \
|
|||
|
||||
If `access-id` not specified, all user accesses will be deleted.
|
||||
|
||||
## users
|
||||
### users
|
||||
|
||||
```bash
|
||||
nodebalancer users | jq .
|
||||
|
@ -67,7 +97,7 @@ This command will return a list of bugout resources of registered users to acces
|
|||
|
||||
`extended_methods` - boolean which allow you to call not whitelisted method to blockchain node, by default for new user this is equal to `false`
|
||||
|
||||
## server
|
||||
### server
|
||||
|
||||
```bash
|
||||
nodebalancer server -host 0.0.0.0 -port 8544 -healthcheck
|
||||
|
@ -76,17 +106,17 @@ nodebalancer server -host 0.0.0.0 -port 8544 -healthcheck
|
|||
Flag `--healthcheck` will execute background process to ping-pong available nodes to keep their status and current block number.
|
||||
Flag `--debug` will extend output of each request to server and healthchecks summary.
|
||||
|
||||
# Work with node
|
||||
## Work with node
|
||||
|
||||
Common request to fetch block number
|
||||
|
||||
```bash
|
||||
curl --request GET 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_id>&data_source=<blockchain/database>' \
|
||||
curl --request POST 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_id>&data_source=<blockchain/database>' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"jsonrpc":"2.0",
|
||||
"method":"eth_getBlockByNumber",
|
||||
"params":["0xb71b64", false],
|
||||
"params":["latest", false],
|
||||
"id":1
|
||||
}'
|
||||
```
|
||||
|
|
|
@ -167,7 +167,7 @@ func (s *StateCLI) populateCLI() {
|
|||
// Common flag pointers
|
||||
for _, fs := range []*flag.FlagSet{s.addAccessCmd, s.generateConfigCmd, s.deleteAccessCmd, s.serverCmd, s.usersCmd, s.versionCmd} {
|
||||
fs.BoolVar(&s.helpFlag, "help", false, "Show help message")
|
||||
fs.StringVar(&s.configPathFlag, "config", "", "Path to configuration file (default: ~/.nodebalancer/config.txt)")
|
||||
fs.StringVar(&s.configPathFlag, "config", "", "Path to configuration file (default: ~/.nodebalancer/config.json)")
|
||||
}
|
||||
|
||||
// Add, delete and list user access subcommand flag pointers
|
||||
|
|
|
@ -18,7 +18,6 @@ var (
|
|||
nodeConfigs []NodeConfig
|
||||
|
||||
// Bugout and application configuration
|
||||
BUGOUT_AUTH_URL = os.Getenv("BUGOUT_AUTH_URL")
|
||||
BUGOUT_AUTH_CALL_TIMEOUT = time.Second * 5
|
||||
NB_APPLICATION_ID = os.Getenv("NB_APPLICATION_ID")
|
||||
NB_CONTROLLER_TOKEN = os.Getenv("NB_CONTROLLER_TOKEN")
|
||||
|
@ -60,8 +59,9 @@ func CheckEnvVarSet() {
|
|||
|
||||
// Nodes configuration
|
||||
type NodeConfig struct {
|
||||
Blockchain string `json:"blockchain"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
Blockchain string `json:"blockchain"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
func LoadConfig(configPath string) error {
|
||||
|
@ -108,7 +108,7 @@ func GetConfigPath(providedPath string) (*ConfigPlacement, error) {
|
|||
return nil, fmt.Errorf("Unable to find user home directory, %v", err)
|
||||
}
|
||||
configDirPath = fmt.Sprintf("%s/.nodebalancer", homeDir)
|
||||
configPath = fmt.Sprintf("%s/config.txt", configDirPath)
|
||||
configPath = fmt.Sprintf("%s/config.json", configDirPath)
|
||||
} else {
|
||||
configPath = strings.TrimSuffix(providedPath, "/")
|
||||
configDirPath = filepath.Dir(configPath)
|
||||
|
@ -144,7 +144,7 @@ func GenerateDefaultConfig(config *ConfigPlacement) error {
|
|||
|
||||
if !config.ConfigExists {
|
||||
tempConfig := []NodeConfig{
|
||||
{Blockchain: "ethereum", Endpoint: "http://127.0.0.1:8545"},
|
||||
{Blockchain: "ethereum", Endpoint: "http://127.0.0.1:8545", Tags: []string{"local"}},
|
||||
}
|
||||
tempConfigJson, err := json.Marshal(tempConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
// "encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -130,32 +130,23 @@ func Server() {
|
|||
os.Exit(1)
|
||||
}
|
||||
if len(resources.Resources) != 1 {
|
||||
fmt.Printf("User with provided access identifier has wrong number of resources, err: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
resource_data, err := json.Marshal(resources.Resources[0].ResourceData)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to encode resource data interface to json, err: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var clientAccess ClientResourceData
|
||||
err = json.Unmarshal(resource_data, &clientAccess)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to decode resource data json to structure, err: %v\n", err)
|
||||
os.Exit(1)
|
||||
log.Println("There are no access IDs for users in resources")
|
||||
} else {
|
||||
log.Println("Found user access IDs in resources")
|
||||
}
|
||||
|
||||
// Set internal crawlers access to bypass requests from internal services
|
||||
// without fetching data from authn Brood server
|
||||
internalCrawlersUserID := uuid.New().String()
|
||||
internalCrawlersAccess = ClientResourceData{
|
||||
UserID: clientAccess.UserID,
|
||||
AccessID: clientAccess.AccessID,
|
||||
Name: clientAccess.Name,
|
||||
Description: clientAccess.Description,
|
||||
BlockchainAccess: clientAccess.BlockchainAccess,
|
||||
ExtendedMethods: clientAccess.ExtendedMethods,
|
||||
UserID: internalCrawlersUserID,
|
||||
AccessID: NB_CONTROLLER_ACCESS_ID,
|
||||
Name: "InternalCrawlersAccess",
|
||||
Description: "Access for internal crawlers.",
|
||||
BlockchainAccess: true,
|
||||
ExtendedMethods: true,
|
||||
}
|
||||
log.Printf(
|
||||
"Internal crawlers access set, resource id: %s, blockchain access: %t, extended methods: %t",
|
||||
resources.Resources[0].Id, clientAccess.BlockchainAccess, clientAccess.ExtendedMethods,
|
||||
)
|
||||
log.Printf("Internal crawlers access set with user ID: %s", internalCrawlersUserID)
|
||||
|
||||
err = InitDatabaseClient()
|
||||
if err != nil {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package main
|
||||
|
||||
var NB_VERSION = "0.2.1"
|
||||
var NB_VERSION = "0.2.2"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Required environment variables for load balancer
|
||||
export BUGOUT_AUTH_URL="https://auth.bugout.dev"
|
||||
export BUGOUT_BROOD_URL="https://auth.bugout.dev"
|
||||
export NB_APPLICATION_ID="<application_id_to_controll_access>"
|
||||
export NB_CONTROLLER_TOKEN="<token_of_controller_user>"
|
||||
export NB_CONTROLLER_ACCESS_ID="<controller_access_id_for_internal_crawlers>"
|
||||
|
|
Ładowanie…
Reference in New Issue