This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
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 #357 from mumoshu/fix-s3-inconsistent-object-prefix
Fix the inconsistent S3 object prefix issue
- Loading branch information
Showing
9 changed files
with
260 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cfnstack | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
type S3URI interface { | ||
Bucket() string | ||
PathComponents() []string | ||
} | ||
|
||
type s3URIImpl struct { | ||
bucket string | ||
directory string | ||
} | ||
|
||
func (u s3URIImpl) Bucket() string { | ||
return u.bucket | ||
} | ||
|
||
func (u s3URIImpl) PathComponents() []string { | ||
if u.directory != "" { | ||
return []string{ | ||
u.directory, | ||
} | ||
} | ||
return []string{} | ||
} | ||
|
||
func S3URIFromString(s3URI string) (S3URI, error) { | ||
re := regexp.MustCompile("s3://(?P<bucket>[^/]+)/(?P<directory>.+[^/])/*$") | ||
matches := re.FindStringSubmatch(s3URI) | ||
var bucket string | ||
var directory string | ||
if len(matches) == 3 { | ||
bucket = matches[1] | ||
directory = matches[2] | ||
} else { | ||
re := regexp.MustCompile("s3://(?P<bucket>[^/]+)/*$") | ||
matches := re.FindStringSubmatch(s3URI) | ||
|
||
if len(matches) == 2 { | ||
bucket = matches[1] | ||
} else { | ||
return nil, fmt.Errorf("failed to parse s3 uri(=%s): The valid uri pattern for it is s3://mybucket/mydir or s3://mybucket", s3URI) | ||
} | ||
} | ||
return s3URIImpl{ | ||
bucket: bucket, | ||
directory: directory, | ||
}, nil | ||
} |
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
Oops, something went wrong.