Fixing issues with workspace_key_prefix

This commit is contained in:
rv-jmaggio 2017-12-15 17:50:36 -05:00
parent 03ddb9134a
commit 0889c118a8
1 changed files with 13 additions and 3 deletions

View File

@ -39,9 +39,13 @@ func (b *Backend) States() ([]string, error) {
// extract the env name from the S3 key
func (b *Backend) keyEnv(key string) string {
// we have 3 parts, the prefix, the env name, and the key name
parts := strings.SplitN(key, "/", 3)
if len(parts) < 3 {
if b.workspaceKeyPrefix == "" {
parts := strings.Split(key, "/")
return parts[0]
}
parts := strings.SplitAfter(key, b.workspaceKeyPrefix)
if len(parts) < 2 {
// no env here
return ""
}
@ -51,6 +55,12 @@ func (b *Backend) keyEnv(key string) string {
return ""
}
parts = strings.Split(parts[1], "/")
if len(parts) < 3 {
return ""
}
// not our key, so don't include it in our listing
if parts[2] != b.keyName {
return ""