Skip to content

Commit 4581c2c

Browse files
committed
Fix for s3:CreateBucket not being detected #81
1 parent b444dec commit 4581c2c

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

iamlivecore/proxy.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,26 @@ func handleAWSRequest(req *http.Request, body []byte, respCode int) {
435435

436436
if hostSplit[len(hostSplit)-1] == "com" && hostSplit[len(hostSplit)-2] == "amazonaws" {
437437
endpointPrefix := hostSplit[len(hostSplit)-3] // "s3".amazonaws.com
438-
if len(hostSplit) > 3 {
439-
endpointPrefix = hostSplit[len(hostSplit)-4] // "s3".us-east-1.amazonaws.com
440-
}
441-
if len(hostSplit) > 4 {
442-
if endpointPrefix == "dualstack" {
443-
endpointPrefix = hostSplit[len(hostSplit)-5] // "s3".dualstack.us-east-1.amazonaws.com
444-
if len(hostSplit) > 5 {
445-
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-5], ".") // "bucket.name".s3.dualstack.us-east-1.amazonaws.com
438+
if endpointPrefix == "s3" && len(hostSplit) > 3 {
439+
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-3], ".") // "bucket.name".s3.amazonaws.com
440+
} else {
441+
if len(hostSplit) > 3 {
442+
endpointPrefix = hostSplit[len(hostSplit)-4] // "s3".us-east-1.amazonaws.com
443+
}
444+
if len(hostSplit) > 4 {
445+
if endpointPrefix == "dualstack" {
446+
endpointPrefix = hostSplit[len(hostSplit)-5] // "s3".dualstack.us-east-1.amazonaws.com
447+
if len(hostSplit) > 5 {
448+
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-5], ".") // "bucket.name".s3.dualstack.us-east-1.amazonaws.com
449+
}
450+
} else if endpointPrefix == "ecr" { // api.ecr.us-east-1.amazonaws.com
451+
endpointPrefix = "api.ecr"
452+
} else {
453+
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-4], ".") // "bucket.name".s3.us-east-1.amazonaws.com
446454
}
447-
} else if endpointPrefix == "ecr" { // api.ecr.us-east-1.amazonaws.com
448-
endpointPrefix = "api.ecr"
449-
} else {
450-
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-4], ".") // "bucket.name".s3.us-east-1.amazonaws.com
451455
}
452-
453456
}
457+
454458
for _, serviceDefinition := range serviceDefinitions {
455459
if serviceDefinition.Metadata.EndpointPrefix == endpointPrefix { // TODO: Ensure latest version
456460
serviceDef = serviceDefinition
@@ -855,7 +859,7 @@ func gcpProcessResource(req *http.Request, gcpResource GCPResourceDefinition, ba
855859

856860
for _, gcpMethod := range gcpResource.Methods {
857861
if req.Method == gcpMethod.HTTPMethod {
858-
pathtemplate := generateMethodTemplate(basePath+gcpMethod.FlatPath)
862+
pathtemplate := generateMethodTemplate(basePath + gcpMethod.FlatPath)
859863

860864
r, err := regexp.Compile(pathtemplate)
861865
if err == nil && r.MatchString(req.URL.Path) {

0 commit comments

Comments
 (0)