diff --git a/pkg/amt/redirection/service.go b/pkg/amt/redirection/service.go index bd46326e..55efb2c5 100644 --- a/pkg/amt/redirection/service.go +++ b/pkg/amt/redirection/service.go @@ -6,10 +6,38 @@ package redirection import ( + "encoding/json" + "encoding/xml" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/amt/actions" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) +type ( + Response struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + Body Body `xml:"Body"` + } + Body struct { + XMLName xml.Name `xml:"Body"` + Redirection Redirection `xml:"AMT_RedirectionService"` + + EnumerateResponse common.EnumerateResponse + } + Redirection struct { + CreationClassName string + ElementName string + EnabledState int + ListenerEnabled bool + Name string + SystemCreationClassName string + SystemName string + } +) type RedirectionResponse struct { AMT_RedirectionService RedirectionService } @@ -58,7 +86,16 @@ const ( ) type Service struct { - base message.Base + base message.Base + client wsman.WSManClient +} + +func (w *Response) JSON() string { + jsonOutput, err := json.Marshal(w.Body) + if err != nil { + return "" + } + return string(jsonOutput) } func NewRedirectionService(wsmanMessageCreator *message.WSManMessageCreator) Service { @@ -67,14 +104,57 @@ func NewRedirectionService(wsmanMessageCreator *message.WSManMessageCreator) Ser } } +func NewRedirectionServiceWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) Service { + return Service{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RedirectionService, client), + client: client, + } +} + // Get retrieves the representation of the instance -func (RedirectionService Service) Get() string { - return RedirectionService.base.Get(nil) +func (s Service) Get() (response Response, err error) { + + response = Response{ + Message: &wsman.Message{ + XMLInput: s.base.Get(nil), + }, + } + + // send the message to AMT + err = s.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } // Enumerates the instances of this class -func (RedirectionService Service) Enumerate() string { - return RedirectionService.base.Enumerate() +func (s Service) Enumerate() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: s.base.Enumerate(), + }, + } + // send the message to AMT + err = s.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } // Pulls instances of this class, following an Enumerate operation diff --git a/pkg/amt/redirection/service_test.go b/pkg/amt/redirection/service_test.go index 66515879..7de81ca7 100644 --- a/pkg/amt/redirection/service_test.go +++ b/pkg/amt/redirection/service_test.go @@ -6,45 +6,126 @@ package redirection import ( + "encoding/xml" + "fmt" + "io" + "os" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) +type MockClient struct { +} + +const ( + EnvelopeResponse = `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous0` + GetBody = `AMT_RedirectionServiceIntel(r) AMT Redirection ServiceIntel(r) AMT Redirection ServiceCIM_ComputerSystemManagedSystem + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse + uuid:00000000-8086-8086-8086-000000000322 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RedirectionService + + + + D3000000-0000-0000-0000-000000000000 + + + \ No newline at end of file diff --git a/pkg/wsmantesting/responses/amt/redirection/get.xml b/pkg/wsmantesting/responses/amt/redirection/get.xml index f4f9e942..84624c09 100644 --- a/pkg/wsmantesting/responses/amt/redirection/get.xml +++ b/pkg/wsmantesting/responses/amt/redirection/get.xml @@ -1,4 +1,4 @@ - +