Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
go-lint: new line before return
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Nov 2, 2022
1 parent 478ad0d commit 84eb235
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func checkS3Bucket(config S3Config) error {
aerr.Code() != s3.ErrCodeBucketAlreadyExists {
return errors.Errorf("Unexpected issue while creating bucket: %v", err)
}

return nil
}

return errors.New("Verifying bucket failed, check S3 configuration")
}

Expand Down
2 changes: 2 additions & 0 deletions bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ func setupFakeS3() (err error) {

if err != nil {
log.Error("Unexpected error while setting up fake s3")

return err
}

return err
}

Expand Down
2 changes: 2 additions & 0 deletions healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (h *HealthCheck) httpsGetCheck(url string, timeout time.Duration) healthche
return http.ErrUseLastResponse
},
}

return func() error {
resp, e := client.Get(url)
if e != nil {
Expand All @@ -70,6 +71,7 @@ func (h *HealthCheck) httpsGetCheck(url string, timeout time.Duration) healthche
if resp.StatusCode != 200 {
return fmt.Errorf("returned status %d", resp.StatusCode)
}

return nil
}
}
2 changes: 2 additions & 0 deletions messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (m *AMQPMessenger) SendMessage(message Event) error {
return fmt.Errorf("failed delivery of delivery tag: %d", confirmed.DeliveryTag)
}
log.Debugf("confirmed delivery with delivery tag: %d", confirmed.DeliveryTag)

return nil

}
Expand All @@ -135,5 +136,6 @@ func buildMqURI(mqHost, mqPort, mqUser, mqPassword, mqVhost string, ssl bool) st
} else {
brokerURI = "amqp://" + mqUser + ":" + mqPassword + "@" + mqHost + ":" + mqPort + mqVhost
}

return brokerURI
}
19 changes: 19 additions & 0 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (p *Proxy) allowedResponse(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Debugf("Request not authenticated (%v)", err)
p.notAuthorized(w, r)

return
}

Expand All @@ -105,6 +106,7 @@ func (p *Proxy) allowedResponse(w http.ResponseWriter, r *http.Request) {
log.Debug("internal server error")
log.Debug(err)
p.internalServerError(w, r)

return
}

Expand Down Expand Up @@ -166,11 +168,13 @@ func (p *Proxy) forwardToBackend(r *http.Request) (*http.Response, error) {
if err != nil {
log.Debug("error when redirecting the request")
log.Debug(err)

return nil, err
}
nr.Header = r.Header
contentLength, _ := strconv.ParseInt(r.Header.Get("content-length"), 10, 64)
nr.ContentLength = contentLength

return p.client.Do(nr)
}

Expand Down Expand Up @@ -223,6 +227,7 @@ func (p *Proxy) resignHeader(r *http.Request, accessKey string, secretKey string
host := strings.SplitN(backendURL, "//", 2)
r.Host = host[1]
}

return s3signer.SignV4(*r, accessKey, secretKey, "", p.s3.region)
}

Expand All @@ -233,40 +238,50 @@ func (p *Proxy) detectRequestType(r *http.Request) S3RequestType {
case http.MethodGet:
if strings.HasSuffix(r.URL.String(), "/") {
log.Debug("detect Get")

return Get
} else if strings.Contains(r.URL.String(), "?acl") {
log.Debug("detect Policy")

return Policy
} else {
log.Debug("detect List")

return List
}
case http.MethodDelete:
if strings.HasSuffix(r.URL.String(), "/") {
log.Debug("detect RemoveBucket")

return RemoveBucket
} else if strings.Contains(r.URL.String(), "uploadId") {
log.Debug("detect AbortMultipart")

return AbortMultipart
} else {
// Do we allow deletion of files?
log.Debug("detect Delete")

return Delete
}
case http.MethodPut:
if strings.HasSuffix(r.URL.String(), "/") {
log.Debug("detect MakeBucket")

return MakeBucket
} else if strings.Contains(r.URL.String(), "?policy") {
log.Debug("detect Policy")

return Policy
} else {
// Should decide if we will handle copy here or through authentication
log.Debug("detect Put")

return Put
}
default:
log.Debug("detect Other")

return Other
}
}
Expand Down Expand Up @@ -294,6 +309,7 @@ func (p *Proxy) CreateMessageFromRequest(r *http.Request, claims jwt.MapClaims)
checksum.Type = "sha256"
event.Checksum = []interface{}{checksum}
log.Info("user ", event.Username, " with pilot ", claims["pilot"], " uploaded file ", event.Filepath, " with checksum ", checksum.Value, " at ", time.Now())

return event, nil
}

Expand Down Expand Up @@ -327,9 +343,11 @@ func (p *Proxy) requestInfo(fullPath string) (string, int64, error) {
log.Debug("error when listing objects")
log.Debug(err)
}

return "", 0, err
}
fmt.Println(strings.ReplaceAll(*result.Contents[0].ETag, "\"", ""))

return fmt.Sprintf("%x", sha256.Sum256([]byte(strings.ReplaceAll(*result.Contents[0].ETag, "\"", "")))), *result.Contents[0].Size, nil

}
Expand Down Expand Up @@ -364,5 +382,6 @@ func (p *Proxy) newSession() (*session.Session, error) {
return nil, err
}
}

return mySession, nil
}
4 changes: 4 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (f *FakeServer) Close() {
func (f *FakeServer) PingedAndRestore() bool {
ret := f.pinged
f.pinged = false

return ret
}

Expand All @@ -60,14 +61,17 @@ func NewMockMessenger() *MockMessenger {

func (m *MockMessenger) SendMessage(event Event) error {
m.lastEvent = &event

return nil
}

func (m *MockMessenger) CheckAndRestore() bool {
if m.lastEvent == nil {

return false
}
m.lastEvent = nil

return true
}

Expand Down
9 changes: 9 additions & 0 deletions userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (u *ValidateFromFile) Authenticate(r *http.Request) error {
}
} else {
log.Debugf("No credentials in Authorization header (%s)", auth)

return fmt.Errorf("authorization header had no credentials")
}
//nolint:nestif
Expand All @@ -89,6 +90,7 @@ func (u *ValidateFromFile) Authenticate(r *http.Request) error {

signature := re.FindStringSubmatch(auth)
if signature == nil || len(signature) < 2 {

return fmt.Errorf("signature not found in Authorization header (%s)", auth)
}

Expand Down Expand Up @@ -122,8 +124,10 @@ func (u *ValidateFromFile) Authenticate(r *http.Request) error {
}
} else {
log.Debugf("Found no secret for user %s", curAccessKey)

return fmt.Errorf("no secret for user %s found", curAccessKey)
}

return nil
}

Expand All @@ -149,11 +153,13 @@ func (u *ValidateFromFile) secretFromID(id string) (string, error) {
}
if record[0] == id {
log.Debugf("Returning secret for id %s", id)

return record[1], nil
}
}

log.Debugf("No secret found for id %s in %s", id, u.filename)

return "", fmt.Errorf("cannot find id %s in %s", id, u.filename)
}

Expand Down Expand Up @@ -253,11 +259,13 @@ func (u *ValidateFromToken) getjwtkey(jwtpubkeypath string) error {

u.pubkeys[nameMatch[1]] = keyData
}

return nil
})
if err != nil {
return fmt.Errorf("failed to get public key files (%v)", err)
}

return nil
}

Expand Down Expand Up @@ -311,5 +319,6 @@ func (u *ValidateFromToken) getjwtpubkey(jwtpubkeyurl string) error {
)
u.pubkeys[key] = keyData
log.Debugf("Registered public key for %s", key)

return nil
}

0 comments on commit 84eb235

Please sign in to comment.