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 blank port for minio client to work with S3 #2996

Merged
merged 1 commit into from
Feb 8, 2020
Merged
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
Allow blank port for minio client to work with S3
Background
---
As of current, supplying a minioServiceHost of `s3.amazonaws.com` with
any port incurs an error.

Per the results of:

```
testBucket := func(hostPort string) error {
	client, _ := minio.New(hostPort, accessKey, secretKey, false)
	_, err := client.BucketExists(bucket)
	return err
}

for _, endpoint := range []string{
	"s3.amazonaws.com:443",
	"s3.amazonaws.com:80",
	"s3.amazonaws.com:",
	"s3.amazonaws.com",
} {
	fmt.Printf("Endpoint: %s, Error: %v\n", endpoint, testBucket(endpoint))
}
```

```
Endpoint: s3.amazonaws.com:443, Error: Get http://s3.amazonaws.com:443/kflow-test/?location=: net/http: HTTP/1.x transport connection broken: malformed HTTP response "\x15\x00\x00\x00\x02\x01\x00"
Endpoint: s3.amazonaws.com:80, Error: Head http://s3.amazonaws.com/kflow-test/: 301 response missing Location header
Endpoint: s3.amazonaws.com:, Error: Head http://s3.amazonaws.com/kflow-test/: 301 response missing Location header
Endpoint: s3.amazonaws.com, Error: <nil>
```

Only the connection without a port specified works.

This change allows passing a blank port to support this.
  • Loading branch information
paiyar committed Feb 6, 2020
commit edaadd827acc689af13bf3c42598fc1e282d32a7
12 changes: 11 additions & 1 deletion backend/src/apiserver/client/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func CreateMinioClient(minioServiceHost string, minioServicePort string,
accessKey string, secretKey string) (*minio.Client, error) {
minioClient, err := minio.New(fmt.Sprintf("%s:%s", minioServiceHost, minioServicePort),
minioClient, err := minio.New(joinHostPort(minioServiceHost, minioServicePort),
accessKey, secretKey, false /* Secure connection */)
if err != nil {
return nil, errors.Wrapf(err, "Error while creating minio client: %+v", err)
Expand Down Expand Up @@ -54,3 +54,13 @@ func CreateMinioClientOrFatal(minioServiceHost string, minioServicePort string,
}
return minioClient
}

// joinHostPort combines host and port into a network address of the form "host:port".
//
// An empty port value results in "host" instead of "host:" (which net.JoinHostPort would return)
func joinHostPort(host, port string) string {
if port == "" {
return host
}
return fmt.Sprintf("%s:%s", host, port)
}