From d5a66c332dfda2cdc38776481e6a75006b046dee Mon Sep 17 00:00:00 2001 From: Tristan Wilson Date: Tue, 27 Feb 2024 16:44:00 -0800 Subject: [PATCH] Add option for beacon auth header --- util/headerreader/blob_client.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/util/headerreader/blob_client.go b/util/headerreader/blob_client.go index a86fcc21b1..93d6c903a2 100644 --- a/util/headerreader/blob_client.go +++ b/util/headerreader/blob_client.go @@ -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 @@ -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) { @@ -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 @@ -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