1
0
Fork 0

Move S3 config to aws module

master
Philip O'Toole 1 year ago
parent 18df3cc3ac
commit a9151ec299

@ -12,12 +12,13 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
type uploader interface {
UploadWithContext(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
}
type downloader interface {
DownloadWithContext(ctx aws.Context, w io.WriterAt, input *s3.GetObjectInput, opts ...func(*s3manager.Downloader)) (n int64, err error)
// S3Config is the subconfig for the S3 storage type
type S3Config struct {
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
Region string `json:"region"`
Bucket string `json:"bucket"`
Path string `json:"path"`
}
// S3Client is a client for uploading data to S3.
@ -112,3 +113,11 @@ func (s *S3Client) createSession() (*session.Session, error) {
}
return sess, nil
}
type uploader interface {
UploadWithContext(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
}
type downloader interface {
DownloadWithContext(ctx aws.Context, w io.WriterAt, input *s3.GetObjectInput, opts ...func(*s3manager.Downloader)) (n int64, err error)
}

@ -6,6 +6,8 @@ import (
"io/ioutil"
"os"
"time"
"github.com/rqlite/rqlite/aws"
)
const (
@ -81,17 +83,8 @@ type Config struct {
Sub json.RawMessage `json:"sub"`
}
// S3Config is the subconfig for the S3 storage type
type S3Config struct {
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
Region string `json:"region"`
Bucket string `json:"bucket"`
Path string `json:"path"`
}
// Unmarshal unmarshals the config file and returns the config and subconfig
func Unmarshal(data []byte) (*Config, *S3Config, error) {
func Unmarshal(data []byte) (*Config, *aws.S3Config, error) {
cfg := &Config{}
err := json.Unmarshal(data, cfg)
if err != nil {
@ -102,7 +95,7 @@ func Unmarshal(data []byte) (*Config, *S3Config, error) {
return nil, nil, ErrInvalidVersion
}
s3cfg := &S3Config{}
s3cfg := &aws.S3Config{}
err = json.Unmarshal(cfg.Sub, s3cfg)
if err != nil {
return nil, nil, err

@ -8,6 +8,8 @@ import (
"reflect"
"testing"
"time"
"github.com/rqlite/rqlite/aws"
)
func Test_ReadConfigFile(t *testing.T) {
@ -111,7 +113,7 @@ func TestUnmarshal(t *testing.T) {
name string
input []byte
expectedCfg *Config
expectedS3 *S3Config
expectedS3 *aws.S3Config
expectedErr error
}{
{
@ -137,7 +139,7 @@ func TestUnmarshal(t *testing.T) {
NoCompress: true,
Interval: 24 * Duration(time.Hour),
},
expectedS3: &S3Config{
expectedS3: &aws.S3Config{
AccessKeyID: "test_id",
SecretAccessKey: "test_secret",
Region: "us-west-2",
@ -168,7 +170,7 @@ func TestUnmarshal(t *testing.T) {
NoCompress: false,
Interval: 24 * Duration(time.Hour),
},
expectedS3: &S3Config{
expectedS3: &aws.S3Config{
AccessKeyID: "test_id",
SecretAccessKey: "test_secret",
Region: "us-west-2",

Loading…
Cancel
Save