Skip to content

Commit

Permalink
Merge pull request #2162 from OffchainLabs/beacon-auth-header
Browse files Browse the repository at this point in the history
Add option for beacon auth header
  • Loading branch information
PlasmaPower authored Feb 28, 2024
2 parents 3777f92 + d5a66c3 commit b6ef4d0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions util/headerreader/blob_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
)

type BlobClient struct {
ec arbutil.L1Interface
beaconUrl *url.URL
httpClient *http.Client
ec arbutil.L1Interface
beaconUrl *url.URL
httpClient *http.Client
authorization string

// Filled in in Initialize()
genesisTime uint64
Expand All @@ -41,16 +42,19 @@ type BlobClient struct {
type BlobClientConfig struct {
BeaconUrl string `koanf:"beacon-url"`
BlobDirectory string `koanf:"blob-directory"`
Authorization string `koanf:"authorization"`
}

var DefaultBlobClientConfig = BlobClientConfig{
BeaconUrl: "",
BlobDirectory: "",
Authorization: "",
}

func BlobClientAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".beacon-url", DefaultBlobClientConfig.BeaconUrl, "Beacon Chain RPC URL to use for fetching blobs (normally on port 3500)")
f.String(prefix+".blob-directory", DefaultBlobClientConfig.BlobDirectory, "Full path of the directory to save fetched blobs")
f.String(prefix+".authorization", DefaultBlobClientConfig.Authorization, "Value to send with the HTTP Authorization: header for Beacon REST requests, must include both scheme and scheme parameters")
}

func NewBlobClient(config BlobClientConfig, ec arbutil.L1Interface) (*BlobClient, error) {
Expand All @@ -72,6 +76,7 @@ func NewBlobClient(config BlobClientConfig, ec arbutil.L1Interface) (*BlobClient
return &BlobClient{
ec: ec,
beaconUrl: beaconUrl,
authorization: config.Authorization,
httpClient: &http.Client{},
blobDirectory: config.BlobDirectory,
}, nil
Expand All @@ -95,6 +100,10 @@ func beaconRequest[T interface{}](b *BlobClient, ctx context.Context, beaconPath
return empty, err
}

if b.authorization != "" {
req.Header.Set("Authorization", b.authorization)
}

resp, err := b.httpClient.Do(req)
if err != nil {
return empty, err
Expand Down

0 comments on commit b6ef4d0

Please sign in to comment.