-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from target/S3Redundancy
Optional Redundancy logging to remote S3 location
- Loading branch information
Showing
12 changed files
with
406 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package tosss3 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
) | ||
|
||
func tossS3Delete(AccessKey string, AccessSecret string, myBucket string, filename string, region string, endpoint string) { | ||
|
||
// Create a Session with a custom creds | ||
var awsConfig = &aws.Config{ | ||
Region: aws.String(region), | ||
Endpoint: aws.String(endpoint), | ||
Credentials: credentials.NewStaticCredentials(string(AccessKey), string(AccessSecret), ""), | ||
} | ||
|
||
// The session the S3 Uploader will use | ||
sess := session.Must(session.NewSession(awsConfig)) | ||
|
||
// Create S3 service client | ||
svc := s3.New(sess) | ||
|
||
// Delete log from S3 now that it's been read | ||
_, err := svc.DeleteObject(&s3.DeleteObjectInput{Bucket: aws.String(string(myBucket)), Key: aws.String(filename)}) | ||
if err != nil { | ||
log.Printf("Unable to delete object %q from bucket %q, %v", filename, myBucket, err) | ||
} | ||
|
||
err = svc.WaitUntilObjectNotExists(&s3.HeadObjectInput{ | ||
Bucket: aws.String(string(myBucket)), | ||
Key: aws.String(filename), | ||
}) | ||
if err != nil { | ||
log.Printf("Failed to delete file from S3, %v", err) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package tosss3 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
) | ||
|
||
func DownloadFromS3(AccessKey string, AccessSecret string, myBucket string, filename string, region string, endpoint string) []byte { | ||
|
||
// Create a Session with a custom creds | ||
var awsConfig = &aws.Config{ | ||
Region: aws.String(region), | ||
Endpoint: aws.String(endpoint), | ||
Credentials: credentials.NewStaticCredentials(string(AccessKey), string(AccessSecret), ""), | ||
} | ||
|
||
// The session the S3 Uploader will use | ||
sess := session.Must(session.NewSession(awsConfig)) | ||
|
||
// Create downloader in order to retrieve log files (Should hopefully only be one) | ||
downloader := s3manager.NewDownloader(sess) | ||
|
||
// Prune out old logs before downloading to reduce time to catch up | ||
tossS3PruneLogs(AccessKey, AccessSecret, myBucket, region, endpoint) | ||
|
||
buff := &aws.WriteAtBuffer{} | ||
|
||
// Iterate through buckets, download to buffer | ||
logFileFromS3, err := downloader.Download(buff, &s3.GetObjectInput{ | ||
Bucket: aws.String(string(myBucket)), | ||
Key: aws.String(filename), | ||
}) | ||
if err != nil { | ||
log.Printf("failed to download file, %v", err) | ||
} | ||
log.Printf("Persistance log downloaded from S3, %d bytes\n", logFileFromS3) | ||
|
||
tossS3Delete(AccessKey, AccessSecret, myBucket, filename, region, endpoint) | ||
|
||
return buff.Bytes() | ||
} |
Oops, something went wrong.