Skip to content

Commit

Permalink
Add ECR special hostname handling #68
Browse files Browse the repository at this point in the history
  • Loading branch information
iann0036 committed Nov 3, 2023
1 parent 0317518 commit 05937b1
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions iamlivecore/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ type AzureTemplate struct {
}

type AzureTemplateResource struct {
Name string `json:"name"`
Type string `json:"type"`
Name string `json:"name"`
Type string `json:"type"`
Properties interface{} `json:"properties"`
}

Expand All @@ -249,26 +249,26 @@ type GCPAPIListFile struct {
}

type GCPAPIListItem struct {
Name string `json:"name"`
Name string `json:"name"`
Version string `json:"version"`
}

type GCPServiceDefinition struct {
RootURL string `json:"rootUrl"`
BasePath string `json:"basePath"`
RootURL string `json:"rootUrl"`
BasePath string `json:"basePath"`
RootDomain string
Resources map[string]GCPResourceDefinition `json:"resources"`
Resources map[string]GCPResourceDefinition `json:"resources"`
}

type GCPResourceDefinition struct {
Methods map[string]GCPMethodDefinition `json:"methods"`
Methods map[string]GCPMethodDefinition `json:"methods"`
Resources map[string]GCPResourceDefinition `json:"resources"`
}

type GCPMethodDefinition struct {
FlatPath string `json:"flatPath"`
FlatPath string `json:"flatPath"`
HTTPMethod string `json:"httpMethod"`
ID string `json:"id"`
ID string `json:"id"`
}

func readServiceFiles() {
Expand Down Expand Up @@ -421,6 +421,8 @@ func handleAWSRequest(req *http.Request, body []byte, respCode int) {
if len(hostSplit) > 5 {
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-5], ".") // "bucket.name".s3.dualstack.us-east-1.amazonaws.com
}
} else if endpointPrefix == "ecr" { // api.ecr.us-east-1.amazonaws.com
endpointPrefix = "api.ecr"
} else {
endpointUriPrefix = strings.Join(hostSplit[:len(hostSplit)-4], ".") // "bucket.name".s3.us-east-1.amazonaws.com
}
Expand Down Expand Up @@ -736,9 +738,9 @@ func handleAzureRequest(req *http.Request, body []byte, respCode int) {

azureCallLog = append(azureCallLog, AzureEntry{
HTTPMethod: req.Method,
Path: req.URL.Path,
Path: req.URL.Path,
Parameters: req.URL.Query(),
Body: body,
Body: body,
})

// Handle AzureRM deployments (inline only)
Expand Down Expand Up @@ -784,8 +786,8 @@ func handleAzureRequest(req *http.Request, body []byte, respCode int) {

azureCallLog = append(azureCallLog, AzureEntry{
HTTPMethod: "PUT",
Path: pathName,
Body: resourceJSON,
Path: pathName,
Body: resourceJSON,
})

continue ResourceLoop
Expand All @@ -795,7 +797,7 @@ func handleAzureRequest(req *http.Request, body []byte, respCode int) {
}
}
}

handleLoggedCall()
}

Expand All @@ -809,12 +811,12 @@ func gcpProcessResource(req *http.Request, gcpResource GCPResourceDefinition, ba

for _, gcpMethod := range gcpResource.Methods {
if req.Method == gcpMethod.HTTPMethod {
pathtemplate := "/" + strings.ReplaceAll(strings.ReplaceAll(basePath + gcpMethod.FlatPath, "{", ":"), "}", "")
pathtemplate := "/" + strings.ReplaceAll(strings.ReplaceAll(basePath+gcpMethod.FlatPath, "{", ":"), "}", "")
if pathtemplate[0:2] == "//" {
pathtemplate = pathtemplate[1:]
}
pathmatch := urlpath.New(pathtemplate)

_, ok := pathmatch.Match(req.URL.Path)
if ok {
return gcpMethod.ID
Expand Down

0 comments on commit 05937b1

Please sign in to comment.