mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add In Support For Builder in E2E (#12343)
* fix it up * add gaz * add changes in * finally runs * fix it * add progress * add capella support * save progress * remove debug logs * cleanup * remove log * fix flag * remove unused lock * gaz * change * fix * lint * james review --------- Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
gethRPC "github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/prysmaticlabs/prysm/v4/network/authorization"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Endpoint is an endpoint with authorization data.
|
||||
@@ -53,6 +59,46 @@ func (d *AuthorizationData) ToHeaderValue() (string, error) {
|
||||
return "", errors.New("could not create HTTP header for unknown authorization method")
|
||||
}
|
||||
|
||||
// HttpEndpoint extracts an httputils.Endpoint from the provider parameter.
|
||||
func HttpEndpoint(eth1Provider string) Endpoint {
|
||||
endpoint := Endpoint{
|
||||
Url: "",
|
||||
Auth: AuthorizationData{
|
||||
Method: authorization.None,
|
||||
Value: "",
|
||||
}}
|
||||
|
||||
authValues := strings.Split(eth1Provider, ",")
|
||||
endpoint.Url = strings.TrimSpace(authValues[0])
|
||||
if len(authValues) > 2 {
|
||||
log.Errorf(
|
||||
"ETH1 endpoint string can contain one comma for specifying the authorization header to access the provider."+
|
||||
" String contains too many commas: %d. Skipping authorization.", len(authValues)-1)
|
||||
} else if len(authValues) == 2 {
|
||||
switch Method(strings.TrimSpace(authValues[1])) {
|
||||
case authorization.Basic:
|
||||
basicAuthValues := strings.Split(strings.TrimSpace(authValues[1]), " ")
|
||||
if len(basicAuthValues) != 2 {
|
||||
log.Errorf("Basic Authentication has incorrect format. Skipping authorization.")
|
||||
} else {
|
||||
endpoint.Auth.Method = authorization.Basic
|
||||
endpoint.Auth.Value = base64.StdEncoding.EncodeToString([]byte(basicAuthValues[1]))
|
||||
}
|
||||
case authorization.Bearer:
|
||||
bearerAuthValues := strings.Split(strings.TrimSpace(authValues[1]), " ")
|
||||
if len(bearerAuthValues) != 2 {
|
||||
log.Errorf("Bearer Authentication has incorrect format. Skipping authorization.")
|
||||
} else {
|
||||
endpoint.Auth.Method = authorization.Bearer
|
||||
endpoint.Auth.Value = bearerAuthValues[1]
|
||||
}
|
||||
case authorization.None:
|
||||
log.Errorf("Authorization has incorrect format or authorization type is not supported.")
|
||||
}
|
||||
}
|
||||
return endpoint
|
||||
}
|
||||
|
||||
// Method returns the authorizationmethod.AuthorizationMethod corresponding with the parameter value.
|
||||
func Method(auth string) authorization.AuthorizationMethod {
|
||||
if strings.HasPrefix(strings.ToLower(auth), "basic") {
|
||||
@@ -76,3 +122,27 @@ func NewHttpClientWithSecret(secret string) *http.Client {
|
||||
Transport: authTransport,
|
||||
}
|
||||
}
|
||||
|
||||
func NewExecutionRPCClient(ctx context.Context, endpoint Endpoint) (*gethRPC.Client, error) {
|
||||
// Need to handle ipc and http
|
||||
var client *gethRPC.Client
|
||||
u, err := url.Parse(endpoint.Url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch u.Scheme {
|
||||
case "http", "https":
|
||||
client, err = gethRPC.DialOptions(ctx, endpoint.Url, gethRPC.WithHTTPClient(endpoint.HttpClient()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "", "ipc":
|
||||
client, err = gethRPC.DialIPC(ctx, endpoint.Url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("no known transport for URL scheme %q", u.Scheme)
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user