Skip to content

Commit

Permalink
Use new XML parsing lib #24
Browse files Browse the repository at this point in the history
  • Loading branch information
iann0036 committed Mar 27, 2021
1 parent 35df6bd commit 5a892e2
Show file tree
Hide file tree
Showing 40 changed files with 5,309 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129
github.com/clbanning/mxj/v2 v2.3.2
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e
github.com/mitchellh/go-homedir v1.1.0
golang.org/dl v0.0.0-20210204224843-1557c60ec592 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129 h1:gfAMKE626QEuKG3si0pdTRcr/YEbBoxY+3GOH3gWvl4=
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/clbanning/mxj/v2 v2.3.2 h1:DSkU65zfrBHtrggxd54X9pK1z/Lw2OwSW5D8p+x1toE=
github.com/clbanning/mxj/v2 v2.3.2/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e h1:/cwV7t2xezilMljIftb7WlFtzGANRCnoOhPjtl2ifcs=
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
Expand Down
19 changes: 12 additions & 7 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"embed"
"encoding/json"
"encoding/pem"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
Expand All @@ -24,6 +23,7 @@ import (
"strings"
"time"

mxj "github.com/clbanning/mxj/v2"
"github.com/elazarl/goproxy"
"github.com/mitchellh/go-homedir"
)
Expand Down Expand Up @@ -473,8 +473,8 @@ func handleAWSRequest(req *http.Request, body []byte, respCode int) {

flatten(true, params, bodyJSON, "")
} else {
var bodyXML interface{}
err := xml.Unmarshal(body, &bodyXML)
mxjXML, err := mxj.NewMapXml(body)
bodyXML := map[string]interface{}(mxjXML)
if err != nil {
return
}
Expand All @@ -497,12 +497,17 @@ func handleAWSRequest(req *http.Request, body []byte, respCode int) {
var selectedActionCandidate ActionCandidate
ActionCandidateLoop:
for _, actionCandidate := range actionCandidates {
RequiredParamLoop:
for _, requiredParam := range actionCandidate.Operation.Input.Required { // check input requirements
if _, ok := actionCandidate.Params[requiredParam]; ok {
continue
for k := range actionCandidate.Params {
if k == requiredParam || k[:len(requiredParam)+2] == requiredParam+"[]" || k[:len(requiredParam)+1] == requiredParam+"." { // equals, or is array, or is map
continue RequiredParamLoop
}
}
if _, ok := actionCandidate.URIParams[requiredParam]; ok {
continue
for k := range actionCandidate.URIParams {
if k == requiredParam || k[:len(requiredParam)+2] == requiredParam+"[]" || k[:len(requiredParam)+1] == requiredParam+"." { // equals, or is array, or is map
continue RequiredParamLoop
}
}
continue ActionCandidateLoop // requirements not met
}
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/clbanning/mxj/v2/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions vendor/github.com/clbanning/mxj/v2/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions vendor/github.com/clbanning/mxj/v2/anyxml.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions vendor/github.com/clbanning/mxj/v2/atomFeedString.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5a892e2

Please sign in to comment.