downloader: default webseed token for e2 (#8512)

This commit is contained in:
Alex Sharov 2023-10-19 08:17:49 +07:00 committed by GitHub
parent 684ca4c030
commit f998e18219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 20 deletions

View File

@ -3,7 +3,6 @@ package downloader
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/base64"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -201,25 +200,15 @@ func (d *WebSeeds) callHttpProvider(ctx context.Context, webSeedProviderUrl *url
return response, nil return response, nil
} }
func (d *WebSeeds) callS3Provider(ctx context.Context, token string) (snaptype.WebSeedsFromProvider, error) { func (d *WebSeeds) callS3Provider(ctx context.Context, token string) (snaptype.WebSeedsFromProvider, error) {
var bucketName = "erigon-v3-snapshots-" + d.chainName + "-webseed" //v1:bucketName:accID:accessKeyID:accessKeySecret
//v1:base64(accID:accessKeyID:accessKeySecret)
l := strings.Split(token, ":") l := strings.Split(token, ":")
if len(l) != 2 { if len(l) != 5 {
return nil, fmt.Errorf("token has invalid format, exepcing 'v1:tokenInBase64'") return nil, fmt.Errorf("token has invalid format, exepcing 'v1:tokenInBase64'")
} }
version, tokenInBase64 := strings.TrimSpace(l[0]), strings.TrimSpace(l[1]) version, bucketName, accountId, accessKeyId, accessKeySecret := strings.TrimSpace(l[0]), strings.TrimSpace(l[1]), strings.TrimSpace(l[2]), strings.TrimSpace(l[3]), strings.TrimSpace(l[4])
if version != "v1" { if version != "v1" {
return nil, fmt.Errorf("not supported version: %s", version) return nil, fmt.Errorf("not supported version: %s", version)
} }
rawDecodedText, err := base64.StdEncoding.DecodeString(tokenInBase64)
if err != nil {
return nil, err
}
l = strings.Split(string(rawDecodedText), ":")
accountId, accessKeyId, accessKeySecret := strings.TrimSpace(l[0]), strings.TrimSpace(l[1]), strings.TrimSpace(l[2])
if len(l) != 3 {
return nil, fmt.Errorf("token has invalid format, exepcing 'accountId:accessKeyId:accessKeySecret'")
}
var fileName = "webseeds.toml" var fileName = "webseeds.toml"
r2Resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { r2Resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {

View File

@ -4,7 +4,7 @@ go 1.20
require ( require (
github.com/erigontech/mdbx-go v0.27.19 github.com/erigontech/mdbx-go v0.27.19
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084 github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484
github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0 github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0
github.com/ledgerwatch/log/v3 v3.9.0 github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.0 github.com/ledgerwatch/secp256k1 v1.0.0

View File

@ -280,8 +280,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084 h1:5FFMJ67en/bG3w335e3KW4fcqX65k6Xel6DsoAH7Mho= github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484 h1:dig1Uxshg/uDpvtpEicP5bLpvhCwIJMdHLMISrgfxuI=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0 h1:7z6cyoCKP6qxtKSO74eAY6XiHWKaOi+melvPeMCXLl8= github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0 h1:7z6cyoCKP6qxtKSO74eAY6XiHWKaOi+melvPeMCXLl8=
github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc= github.com/ledgerwatch/interfaces v0.0.0-20231011121315-f58b806039f0/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk= github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=

2
go.mod
View File

@ -189,7 +189,7 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084 // indirect github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect

4
go.sum
View File

@ -539,8 +539,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084 h1:5FFMJ67en/bG3w335e3KW4fcqX65k6Xel6DsoAH7Mho= github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484 h1:dig1Uxshg/uDpvtpEicP5bLpvhCwIJMdHLMISrgfxuI=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018041646-a68ea6e20084/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231018092740-2cf0f5394484/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk= github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE= github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ= github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=