-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
storage/minio: Add options to disable signature and multipart for Minio Client #21780
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
Closed
stevefan1999-personal
wants to merge
12
commits into
go-gitea:main
from
stevefan1999-personal:patch-minio-signature
Closed
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2fbf9b2
storage, minio: add options to disable signature and multipart
stevefan1999-personal d61714c
storage/minio: save pointer to conifg
stevefan1999-personal c71fa9b
storage/minio: put the disable signature and multipart in considerati…
stevefan1999-personal 866f567
storage/minio: add workaround for unspecified size in Save when multi…
stevefan1999-personal e3e96e7
storage/minio: adapt to linter advice
stevefan1999-personal f88da91
storage/minio: fix extra line reported from linter
stevefan1999-personal 918c998
Merge branch 'go-gitea:main' into patch-minio-signature
stevefan1999-personal c960eb4
Merge branch 'main' into patch-minio-signature
stevefan1999-personal d84b1ee
Update modules/storage/minio.go
techknowlogick 570abd2
Merge branch 'main' into patch-minio-signature
stevefan1999-personal 635e997
Update minio.go
stevefan1999-personal bf1162d
Merge branch 'main' into patch-minio-signature
stevefan1999-personal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
package storage | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"crypto/tls" | ||
"io" | ||
|
@@ -45,14 +46,17 @@ const MinioStorageType Type = "minio" | |
|
||
// MinioStorageConfig represents the configuration for a minio storage | ||
type MinioStorageConfig struct { | ||
|
||
Endpoint string `ini:"MINIO_ENDPOINT"` | ||
AccessKeyID string `ini:"MINIO_ACCESS_KEY_ID"` | ||
SecretAccessKey string `ini:"MINIO_SECRET_ACCESS_KEY"` | ||
Bucket string `ini:"MINIO_BUCKET"` | ||
Location string `ini:"MINIO_LOCATION"` | ||
BasePath string `ini:"MINIO_BASE_PATH"` | ||
UseSSL bool `ini:"MINIO_USE_SSL"` | ||
InsecureSkipVerify bool `ini:"MINIO_INSECURE_SKIP_VERIFY"` | ||
InsecureSkipVerify bool `ini:"MINIO_INSECURE_SKIP_VERIFY"` | ||
DisableSignature bool `ini:"MINIO_DISABLE_SIGNATURE"` | ||
DisableMultipart bool `ini:"MINIO_DISABLE_MULTIPART"` | ||
} | ||
|
||
// MinioStorage returns a minio bucket storage | ||
|
@@ -61,6 +65,7 @@ type MinioStorage struct { | |
client *minio.Client | ||
bucket string | ||
basePath string | ||
config *MinioStorageConfig | ||
} | ||
|
||
func convertMinioErr(err error) error { | ||
|
@@ -117,6 +122,7 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error | |
client: minioClient, | ||
bucket: config.Bucket, | ||
basePath: config.BasePath, | ||
config: &config, | ||
}, nil | ||
} | ||
|
||
|
@@ -136,13 +142,35 @@ func (m *MinioStorage) Open(path string) (Object, error) { | |
|
||
// Save save a file to minio | ||
func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error) { | ||
disableSignature, disableMultipart := false, false | ||
if m.config != nil { | ||
disableSignature, disableMultipart = m.config.DisableSignature, m.config.DisableMultipart | ||
} | ||
|
||
if disableMultipart && size < 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So how to handle when size == 0? |
||
// Attempts to read everything from the source into memory. This can take a big toll on memory, and it can become a potential DoS source | ||
// but since we have disabled multipart upload this mean we can't really stream write anymore... | ||
// well, unless we have a better way to estimate the stream size, this would be a workaround | ||
|
||
buf := &bytes.Buffer{} | ||
n, err := io.Copy(buf, r) | ||
if err != nil { | ||
// I guess this would likely be EOF or OOM...? | ||
return -1, err | ||
} | ||
|
||
// Since we read all the data from the source, it might not be usable again, | ||
// so we should swap the reader location to our memory buffer | ||
r, size = buf, n | ||
} | ||
|
||
uploadInfo, err := m.client.PutObject( | ||
m.ctx, | ||
m.bucket, | ||
m.buildMinioPath(path), | ||
r, | ||
size, | ||
minio.PutObjectOptions{ContentType: "application/octet-stream"}, | ||
minio.PutObjectOptions{ContentType: "application/octet-stream", DisableContentSha256: disableSignature, DisableMultipart: disableMultipart}, | ||
) | ||
if err != nil { | ||
return 0, convertMinioErr(err) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.