Skip to content

Commit 8309dd2

Browse files
authored
Merge pull request #40 from Dewberry/enhancement-return-reader
Enhancement Return Reader
2 parents 9368b22 + 4e55fca commit 8309dd2

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

.example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PG_LOG_CHECKPOINTS='off'
1717
S3_MOCK=0 ## Options: [0, 1] corresponds to [no S3 Mock, s3 Mock]. This integer value configures the initialization mode in docker-compose.
1818
#### Optional:
1919

20+
INIT_AUTH= ##set to zero if you do not want to initialize auth (used when s3api is a package in a non auth app)
21+
2022
## MINIO
2123
MINIO_S3_ENDPOINT='http://minio:9000'
2224
MINIO_S3_REGION='s3-region-string'

auth/auth.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ func getPublicKeys() ([]PublicKey, error) {
5353
}
5454

5555
func init() {
56+
initAuth := os.Getenv("INIT_AUTH")
57+
if initAuth == "0" {
58+
log.Println("Skipping authentication initialization")
59+
return // Skip initialization if the environment variable is explicitly set to 0
60+
}
61+
5662
var err error
5763
publicKeys, err = getPublicKeys()
5864
if err != nil {
59-
panic(err)
65+
panic(fmt.Sprintf("Failed to initialize authentication: %v", err))
6066
}
6167
}
6268

@@ -130,7 +136,11 @@ func overlap(s1 []string, s2 []string) bool {
130136

131137
func Authorize(handler echo.HandlerFunc, allowedRoles ...string) echo.HandlerFunc {
132138
return func(c echo.Context) error {
139+
initAuth := os.Getenv("INIT_AUTH")
133140

141+
if initAuth == "0" {
142+
return handler(c)
143+
}
134144
headers := c.Request().Header
135145

136146
authHead := headers.Get("Authorization")

blobstore/object_content.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
log "github.com/sirupsen/logrus"
1414
)
1515

16-
func (s3Ctrl *S3Controller) FetchObjectContent(bucket string, key string) ([]byte, error) {
16+
func (s3Ctrl *S3Controller) FetchObjectContent(bucket string, key string) (io.ReadCloser, error) {
1717
keyExist, err := s3Ctrl.KeyExists(bucket, key)
1818
if err != nil {
1919
return nil, err
@@ -30,12 +30,7 @@ func (s3Ctrl *S3Controller) FetchObjectContent(bucket string, key string) ([]byt
3030
return nil, err
3131
}
3232

33-
body, err := io.ReadAll(output.Body)
34-
if err != nil {
35-
return nil, err
36-
}
37-
38-
return body, nil
33+
return output.Body, nil
3934
}
4035

4136
func (bh *BlobHandler) HandleObjectContents(c echo.Context) error {
@@ -54,7 +49,7 @@ func (bh *BlobHandler) HandleObjectContents(c echo.Context) error {
5449
return c.JSON(http.StatusUnprocessableEntity, errMsg.Error())
5550
}
5651

57-
body, err := s3Ctrl.FetchObjectContent(bucket, key)
52+
outPutBody, err := s3Ctrl.FetchObjectContent(bucket, key)
5853
if err != nil {
5954
log.Error("HandleObjectContents: " + err.Error())
6055
if strings.Contains(err.Error(), "object") {
@@ -63,7 +58,10 @@ func (bh *BlobHandler) HandleObjectContents(c echo.Context) error {
6358
return c.JSON(http.StatusInternalServerError, err.Error())
6459
}
6560
}
66-
61+
body, err := io.ReadAll(outPutBody)
62+
if err != nil {
63+
return c.JSON(http.StatusInternalServerError, err.Error())
64+
}
6765
log.Info("HandleObjectContents: Successfully fetched object data for key:", key)
6866
//TODO: add contentType
6967
return c.Blob(http.StatusOK, "", body)

0 commit comments

Comments
 (0)