Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit 317404c

Browse files
brooksmtownsendChrisRx
authored andcommitted
Implement default s3 path when only bucket provided for etcd snapshots (#37)
* Implement default s3 path when only bucket provided for etcd snapshots * Test default snapshot path and explicit snapshot path
1 parent ab4e55b commit 317404c

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/snapshot/snapshot.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ func ParseSnapshotBackupURL(s string) (*URL, error) {
7070
Path: filepath.Join(u.Host, u.Path),
7171
}, nil
7272
case "s3":
73+
if u.Path == "" {
74+
u.Path = "etcd.snapshot"
75+
}
7376
return &URL{
7477
Type: S3Type,
7578
Bucket: u.Host,
76-
Path: u.Path,
79+
Path: strings.TrimPrefix(u.Path, "/"),
7780
}, nil
7881
case "http", "https":
7982
if strings.Contains(u.Host, "digitaloceanspaces") {

pkg/snapshot/snapshot_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ func TestParseSnapshotBackupURL(t *testing.T) {
4343
{
4444
name: "s3",
4545
url: "s3://abc",
46-
expected: &URL{Type: S3Type, Bucket: "abc"},
46+
expected: &URL{Type: S3Type, Bucket: "abc", Path: "etcd.snapshot"},
47+
},
48+
{
49+
name: "s3",
50+
url: "s3://abc/snapshot.gz",
51+
expected: &URL{Type: S3Type, Bucket: "abc", Path: "snapshot.gz"},
52+
},
53+
{
54+
name: "s3",
55+
url: "s3://abc/backupdir/snapshot.gz",
56+
expected: &URL{Type: S3Type, Bucket: "abc", Path: "backupdir/snapshot.gz"},
4757
},
4858
{
4959
name: "spaces",

0 commit comments

Comments
 (0)