Skip to content

Commit

Permalink
fix: s3 connection formation (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored Dec 21, 2023
1 parent 49fd05c commit d9eb99c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions connection_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/url"
"os"
"strconv"

"github.com/flanksource/artifacts/internal/fs"
"github.com/google/uuid"
Expand Down Expand Up @@ -38,11 +39,20 @@ func GetFSForConnection(ctx context.Context, c models.Connection) (FilesystemRW,
if c.ID != uuid.Nil {
conn.ConnectionName = c.ID.String()
} else {
conn.Endpoint = c.URL
conn.AccessKey = types.EnvVar{ValueStatic: c.Username}
conn.SecretKey = types.EnvVar{ValueStatic: c.Password}
conn.SessionToken = types.EnvVar{ValueStatic: c.Username}
conn.Bucket = c.Properties["bucket"]
conn.Region = c.Properties["region"]
if val, ok := c.Properties["usePathStyle"]; ok {
if b, err := strconv.ParseBool(val); err == nil {
conn.UsePathStyle = b
}
}
if objectPath, ok := c.Properties["objectPath"]; ok {
conn.ObjectPath = objectPath
}
}

if err := conn.Populate(ctx); err != nil {
Expand All @@ -57,15 +67,15 @@ func GetFSForConnection(ctx context.Context, c models.Connection) (FilesystemRW,
conn.ConnectionName = c.ID.String()
} else {
conn.Credentials = &types.EnvVar{ValueStatic: c.Certificate}
conn.Endpoint = c.Properties["endpoint"]
conn.Bucket = c.Properties["endpoint"]
conn.Endpoint = c.URL
conn.Bucket = c.Properties["bucket"]
}

if err := conn.HydrateConnection(ctx); err != nil {
return nil, err
}

client, err := fs.NewGCSFS(ctx, conn.Bucket, &conn)
client, err := fs.NewGCSFS(ctx, conn.Bucket, conn)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type gcsFS struct {
Bucket string
}

func NewGCSFS(ctx context.Context, bucket string, conn *connection.GCSConnection) (*gcsFS, error) {
func NewGCSFS(ctx context.Context, bucket string, conn connection.GCSConnection) (*gcsFS, error) {
cfg, err := gcpUtil.NewSession(ctx, &conn.GCPConnection)
if err != nil {
return nil, err
Expand Down

0 comments on commit d9eb99c

Please sign in to comment.