feat(gateway): parse Apollo inventory and launch replies
Verify Data Plane / gateway (push) Successful in 1m58s
Verify Data Plane / gateway (push) Successful in 1m58s
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type apolloLaunchResponse struct {
|
||||
StatusCode string `xml:"status_code,attr"`
|
||||
SessionURL string `xml:"sessionUrl0"`
|
||||
}
|
||||
|
||||
func apolloInventoryContains(data []byte, applicationID string) bool {
|
||||
if len(data) == 0 || len(data) > 64<<10 || applicationID == "" {
|
||||
return false
|
||||
}
|
||||
var document struct {
|
||||
Applications []struct {
|
||||
ID string `xml:"ID"`
|
||||
} `xml:"App"`
|
||||
}
|
||||
if xml.Unmarshal(data, &document) != nil {
|
||||
return false
|
||||
}
|
||||
for _, application := range document.Applications {
|
||||
if strings.TrimSpace(application.ID) == applicationID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func parseApolloLaunchResponse(data []byte) (apolloLaunchResponse, error) {
|
||||
if len(data) == 0 || len(data) > 64<<10 {
|
||||
return apolloLaunchResponse{}, ErrProviderMalformed
|
||||
}
|
||||
var response apolloLaunchResponse
|
||||
if xml.Unmarshal(data, &response) != nil || response.StatusCode != "200" || strings.TrimSpace(response.SessionURL) == "" {
|
||||
return apolloLaunchResponse{}, ErrProviderMalformed
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
Reference in New Issue
Block a user