Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Google storage endpoints without http/s #179

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}

Comment on lines +60 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine. if it's always going to be https://storage.googleapis.com, maybe trim the protocol instead of doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So right now it requires to be submitted without https for minio/client (i.e.: --s3.endpoint=storage.googleapis.com).

Another solution would be ensuring that the protocol is present before using url.Parse() and keep s3utils.IsGoogleEndpoint. In minio, they use a helper method for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When/why do you ever need the full protocol url? And why does minio not allow it (I’ve noticed this also and found it annoying). I’m just curious at this point, but I’ll approve this, sounds fine for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's just needed for url.Parse() here. I think it may depend on each client implementation, but seems minio-go client don't handle if the endpoint has the protocol on it.

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")
}
Loading