Skip to content

Commit

Permalink
Support s3 bucket owner pull control (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
venky999 authored Sep 26, 2021
1 parent ed5e0ba commit d249024
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func keyExists(bucket string, key string) (bool, error) {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case "NotFound": // s3.ErrCodeNoSuchKey does not work, aws is missing this error code so we hardwire a string
elog.Println( time.Now().Format(time.RFC3339) + " keyExists got NotFound error for " +key+ " bucket "+bucket + " error : " + err.Error())
return false, nil
default:
elog.Println( time.Now().Format(time.RFC3339) + " keyExists failed for " +key+ " bucket "+bucket + " error : " + err.Error())
Expand Down Expand Up @@ -118,7 +119,7 @@ func copyFile(bucket string, item string, other string) (error){

// Copy the file
_, err := svc.CopyObject(&s3.CopyObjectInput{Bucket: aws.String(other),
CopySource: aws.String(url.PathEscape(source)), Key: aws.String(item)})
CopySource: aws.String(url.PathEscape(source)), Key: aws.String(item), ACL: aws.String("bucket-owner-full-control")})

if err != nil {
elog.Println( time.Now().Format(time.RFC3339) + " Unable to read file " +item+ " from bucket "+bucket+ " to bucket "+other+" error : " + err.Error())
Expand All @@ -132,7 +133,7 @@ func copyFile(bucket string, item string, other string) (error){
return errors.New("Error while waiting for file to copy")
}

info.Println( time.Now().Format(time.RFC3339) + " File "+ item+ "successfully copied from bucket "+bucket+ " to bucket "+other)
info.Println( time.Now().Format(time.RFC3339) + " File "+ item+ " successfully copied from bucket "+bucket+ " to bucket "+other)

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions s3scanfilehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func S3ScanFileHandler(w http.ResponseWriter, r *http.Request) {

err = validateInputData(w,data)
if err != nil {
elog.Println(" validateInputData failed " + err.Error())
return
}

Expand All @@ -153,6 +154,7 @@ func S3ScanFileHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
elog.Println(err)
errorResponse(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}

// send request for scanning
Expand All @@ -169,6 +171,7 @@ func S3ScanFileHandler(w http.ResponseWriter, r *http.Request) {
return
} else {
if response.data.Status == "INFECTED" {
elog.Println("Key " +data.Key+ " from bucket "+data.BucketName+ " is Infected")
err = copyFile(data.BucketName, data.Key, getQurantineFilesBucket(data.QurantineFilesBucket))
if err != nil {
elog.Println(err)
Expand All @@ -182,6 +185,7 @@ func S3ScanFileHandler(w http.ResponseWriter, r *http.Request) {
return
}
} else if response.data.Status == "CLEAN" {
info.Println("Key " +data.Key+ " from bucket "+data.BucketName+ " is Clean")
err = copyFile(data.BucketName, data.Key, getCleanFilesBucket(data.CleanFilesBucket))
if err != nil {
elog.Println(err)
Expand Down

0 comments on commit d249024

Please sign in to comment.