1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00
This commit is contained in:
Adriano
2019-07-08 15:32:33 -07:00
parent 598b706613
commit 4b99fa18b3
22 changed files with 148 additions and 46 deletions

View File

@@ -7,19 +7,23 @@ import (
"cloud.google.com/go/storage"
)
// GCSDestination represents the Google Cloud Storage destination
type GCSDestination struct {
gcsBucket string
gcsPrefix string
}
// NewGCSDestination is the constructor for a new Google Cloud Storage destination
func NewGCSDestination(gcsBucket string, gcsPrefix string) *GCSDestination {
return &GCSDestination{gcsBucket, gcsPrefix}
}
// Path returns a the GCS path for a file within this GCS Destination
func (gcsd *GCSDestination) Path(fileName string) string {
return fmt.Sprintf("gcs://%s/%s%s", gcsd.gcsBucket, gcsd.gcsPrefix, fileName)
}
// Upload uploads contents to a new file in GCS
func (gcsd *GCSDestination) Upload(fileContents []byte, fileName string) error {
ctx := context.Background()
client, err := storage.NewClient(ctx)

View File

@@ -1,5 +1,7 @@
package publish
// Destination represents actions which all destination types
// must implement in order to be used by SOPS
type Destination interface {
Upload(fileContents []byte, fileName string) error
Path(fileName string) string

View File

@@ -9,19 +9,23 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
)
// S3Destination is the AWS S3 implementation of the Destination interface
type S3Destination struct {
s3Bucket string
s3Prefix string
}
// NewS3Destination is the constructor for a new S3 Destination
func NewS3Destination(s3Bucket string, s3Prefix string) *S3Destination {
return &S3Destination{s3Bucket, s3Prefix}
}
// Path returns the S3 path of a file in an S3 Destination (bucket)
func (s3d *S3Destination) Path(fileName string) string {
return fmt.Sprintf("s3://%s/%s%s", s3d.s3Bucket, s3d.s3Prefix, fileName)
}
// Upload uploads contents to a new file in an S3 Destination (bucket)
func (s3d *S3Destination) Upload(fileContents []byte, fileName string) error {
sess := session.Must(session.NewSession())
svc := s3.New(sess)