Skip to content

Commit

Permalink
Allow Google storage endpoints without http/s (#179)
Browse files Browse the repository at this point in the history
Fix Google URL check
  • Loading branch information
jcortejoso authored Oct 10, 2024
1 parent 735b2ca commit 1395dfa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
13 changes: 6 additions & 7 deletions store/precomputed_key/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import (
"encoding/hex"
"errors"
"io"
"net/url"
"path"
"strings"
"time"

"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/ethereum/go-ethereum/crypto"
"github.com/minio/minio-go/v7"

"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/s3utils"
)

const (
Expand Down Expand Up @@ -58,13 +57,13 @@ type Store struct {
stats *store.Stats
}

func isGoogleEndpoint(endpoint string) bool {
return strings.Contains(endpoint, "storage.googleapis.com")
}

func NewS3(cfg Config) (*Store, error) {
endpointURL, err := url.Parse(cfg.Endpoint)
if err != nil {
return nil, err
}
putObjectOptions := minio.PutObjectOptions{}
if s3utils.IsGoogleEndpoint(*endpointURL) {
if isGoogleEndpoint(cfg.Endpoint) {
putObjectOptions.DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922
}

Expand Down
31 changes: 31 additions & 0 deletions store/precomputed_key/s3/s3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package s3

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsGoogleEndpoint_StorageGoogleapis(t *testing.T) {
endpoint := "storage.googleapis.com"
result := isGoogleEndpoint(endpoint)
assert.True(t, result, "Expected true for Google Cloud Storage endpoint")
}

func TestIsGoogleEndpoint_HttpsStorageGoogleapis(t *testing.T) {
endpoint := "https://storage.googleapis.com"
result := isGoogleEndpoint(endpoint)
assert.True(t, result, "Expected true for Google Cloud Storage endpoint")
}

func TestIsGoogleEndpoint_False(t *testing.T) {
endpoint := "https://s3.amazonaws.com/my-bucket"
result := isGoogleEndpoint(endpoint)
assert.False(t, result, "Expected false for non-Google endpoint")
}

func TestIsGoogleEndpoint_Empty(t *testing.T) {
endpoint := ""
result := isGoogleEndpoint(endpoint)
assert.False(t, result, "Expected false for empty endpoint")
}

0 comments on commit 1395dfa

Please sign in to comment.