diff --git a/pkg/amt/setupandconfiguration/service.go b/pkg/amt/setupandconfiguration/service.go
index 4f7b94df..4aaeb95d 100644
--- a/pkg/amt/setupandconfiguration/service.go
+++ b/pkg/amt/setupandconfiguration/service.go
@@ -6,16 +6,46 @@
package setupandconfiguration
import (
+ "encoding/json"
"encoding/xml"
- "fmt"
"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/cim/models"
+ "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common"
+ "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman"
)
const AMT_SetupAndConfigurationService = "AMT_SetupAndConfigurationService"
+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"`
+ Setup Setup `xml:"AMT_SetupAndConfigurationService"`
+
+ EnumerateResponse common.EnumerateResponse
+ }
+
+ Setup struct {
+ CreationClassName string
+ ElementName string
+ EnabledState int
+ Name string
+ PasswordModel int
+ ProvisioningMode int
+ ProvisioningServerOTP string
+ ProvisioningState int
+ RequestedState int
+ SystemCreationClassName string
+ SystemName string
+ ZeroTouchConfigurationEnabled bool
+ }
+)
type UnprovisionResponse struct {
XMLName xml.Name `xml:"Envelope"`
Header message.Header `xml:"Header"`
@@ -48,56 +78,109 @@ type SetupAndConfigurationService struct {
ZeroTouchConfigurationEnabled string
}
}
+
+func (w *Response) JSON() string {
+ jsonOutput, err := json.Marshal(w.Body)
+ if err != nil {
+ return ""
+ }
+ return string(jsonOutput)
+}
+
type Service struct {
- base message.Base
+ base message.Base
+ client wsman.WSManClient
}
func NewSetupAndConfigurationService(wsmanMessageCreator *message.WSManMessageCreator) Service {
return Service{
- base: message.NewBase(wsmanMessageCreator, AMT_SetupAndConfigurationService),
+ base: message.NewBase(wsmanMessageCreator, AMT_SetupAndConfigurationService),
+ client: nil,
}
}
-func (s Service) Get() string {
- return s.base.Get(nil)
-}
-// Enumerates the instances of this class
-func (s Service) Enumerate() string {
- return s.base.Enumerate()
+func NewSetupAndConfigurationServiceWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) Service {
+ return Service{
+ base: message.NewBaseWithClient(wsmanMessageCreator, AMT_SetupAndConfigurationService, client),
+ client: client,
+ }
}
+func (s Service) Get() (response Response, err error) {
+ response = Response{
+ Message: &wsman.Message{
+ XMLInput: s.base.Get(nil),
+ },
+ }
-// Pulls instances of this class, following an Enumerate operation
-func (s Service) Pull(enumerationContext string) string {
- return s.base.Pull(enumerationContext)
-}
+ // send the message to AMT
+ err = s.base.Execute(response.Message)
+ if err != nil {
+ return
+ }
-// Put will change properties of the selected instance
-func (s Service) Put(setupAndConfigurationService SetupAndConfigurationService) string {
- return s.base.Put(setupAndConfigurationService, false, nil)
-}
-func (s Service) CommitChanges() string {
- header := s.base.WSManMessageCreator.CreateHeader(string(actions.CommitChanges), AMT_SetupAndConfigurationService, nil, "", "")
- body := s.base.WSManMessageCreator.CreateBody("CommitChanges_INPUT", AMT_SetupAndConfigurationService, nil)
- return s.base.WSManMessageCreator.CreateXML(header, body)
-}
+ // put the xml response into the go struct
+ err = xml.Unmarshal([]byte(response.XMLOutput), &response)
+ if err != nil {
+ return
+ }
-func (s Service) GetUuid() string {
- header := s.base.WSManMessageCreator.CreateHeader(string(actions.GetUuid), AMT_SetupAndConfigurationService, nil, "", "")
- body := s.base.WSManMessageCreator.CreateBody("GetUuid_INPUT", AMT_SetupAndConfigurationService, nil)
- return s.base.WSManMessageCreator.CreateXML(header, body)
+ return
}
-func (s Service) SetMEBXPassword(password string) string {
- header := s.base.WSManMessageCreator.CreateHeader(string(actions.SetMEBxPassword), AMT_SetupAndConfigurationService, nil, "", "")
- body := fmt.Sprintf(`
%s`, s.base.WSManMessageCreator.ResourceURIBase, AMT_SetupAndConfigurationService, password)
- return s.base.WSManMessageCreator.CreateXML(header, body)
-}
+// Enumerates the instances of this class
+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
+ }
-func (s Service) Unprovision(provisioningMode int) string {
- if provisioningMode == 0 {
- provisioningMode = 1
+ // put the xml response into the go struct
+ err = xml.Unmarshal([]byte(response.XMLOutput), &response)
+ if err != nil {
+ return
}
- header := s.base.WSManMessageCreator.CreateHeader(string(actions.Unprovision), AMT_SetupAndConfigurationService, nil, "", "")
- body := fmt.Sprintf(`%d`, s.base.WSManMessageCreator.ResourceURIBase, AMT_SetupAndConfigurationService, provisioningMode)
- return s.base.WSManMessageCreator.CreateXML(header, body)
+
+ return
}
+
+// Pulls instances of this class, following an Enumerate operation
+// func (s Service) Pull(enumerationContext string) string {
+// return s.base.Pull(enumerationContext)
+// }
+
+// // Put will change properties of the selected instance
+// func (s Service) Put(setupAndConfigurationService SetupAndConfigurationService) string {
+// return s.base.Put(setupAndConfigurationService, false, nil)
+// }
+// func (s Service) CommitChanges() string {
+// header := s.base.WSManMessageCreator.CreateHeader(string(actions.CommitChanges), AMT_SetupAndConfigurationService, nil, "", "")
+// body := s.base.WSManMessageCreator.CreateBody("CommitChanges_INPUT", AMT_SetupAndConfigurationService, nil)
+// return s.base.WSManMessageCreator.CreateXML(header, body)
+// }
+
+// func (s Service) GetUuid() string {
+// header := s.base.WSManMessageCreator.CreateHeader(string(actions.GetUuid), AMT_SetupAndConfigurationService, nil, "", "")
+// body := s.base.WSManMessageCreator.CreateBody("GetUuid_INPUT", AMT_SetupAndConfigurationService, nil)
+// return s.base.WSManMessageCreator.CreateXML(header, body)
+// }
+
+// func (s Service) SetMEBXPassword(password string) string {
+// header := s.base.WSManMessageCreator.CreateHeader(string(actions.SetMEBxPassword), AMT_SetupAndConfigurationService, nil, "", "")
+// body := fmt.Sprintf(`%s`, s.base.WSManMessageCreator.ResourceURIBase, AMT_SetupAndConfigurationService, password)
+// return s.base.WSManMessageCreator.CreateXML(header, body)
+// }
+
+// func (s Service) Unprovision(provisioningMode int) string {
+// if provisioningMode == 0 {
+// provisioningMode = 1
+// }
+// header := s.base.WSManMessageCreator.CreateHeader(string(actions.Unprovision), AMT_SetupAndConfigurationService, nil, "", "")
+// body := fmt.Sprintf(`%d`, s.base.WSManMessageCreator.ResourceURIBase, AMT_SetupAndConfigurationService, provisioningMode)
+// return s.base.WSManMessageCreator.CreateXML(header, body)
+// }
diff --git a/pkg/amt/setupandconfiguration/service_test.go b/pkg/amt/setupandconfiguration/service_test.go
index b9b4f6c4..db117f5e 100644
--- a/pkg/amt/setupandconfiguration/service_test.go
+++ b/pkg/amt/setupandconfiguration/service_test.go
@@ -6,49 +6,126 @@
package setupandconfiguration
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/amt/actions"
+ "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common"
"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`, elementUnderTest.CommitChanges},
- {"should create a valid AMT_SetupAndConfigurationService GetUuid wsman message", "AMT_SetupAndConfigurationService", string(actions.GetUuid), ``, elementUnderTest.GetUuid},
- {"should create a valid AMT_SetupAndConfigurationService SetMEBxPassword wsman message", "AMT_SetupAndConfigurationService", string(actions.SetMEBxPassword), `P@ssw0rd`, func() string { return elementUnderTest.SetMEBXPassword("P@ssw0rd") }},
- {"should create a valid AMT_SetupAndConfigurationService Unprovision wsman message", "AMT_SetupAndConfigurationService", string(actions.Unprovision), `1`, func() string { return elementUnderTest.Unprovision(1) }},
+ // {"should create a valid AMT_SetupAndConfigurationService Pull wsman message", "AMT_SetupAndConfigurationService", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }},
+ // {"should create a valid AMT_SetupAndConfigurationService CommitChanges wsman message", "AMT_SetupAndConfigurationService", string(actions.CommitChanges), ``, elementUnderTest.CommitChanges},
+ // {"should create a valid AMT_SetupAndConfigurationService GetUuid wsman message", "AMT_SetupAndConfigurationService", string(actions.GetUuid), ``, elementUnderTest.GetUuid},
+ // {"should create a valid AMT_SetupAndConfigurationService SetMEBxPassword wsman message", "AMT_SetupAndConfigurationService", string(actions.SetMEBxPassword), `P@ssw0rd`, func() string { return elementUnderTest.SetMEBXPassword("P@ssw0rd") }},
+ // {"should create a valid AMT_SetupAndConfigurationService Unprovision wsman message", "AMT_SetupAndConfigurationService", string(actions.Unprovision), `1`, func() string { return elementUnderTest.Unprovision(1) }},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
+ expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
messageID++
- response := test.responseFunc()
- if response != correctResponse {
- assert.Equal(t, correctResponse, response)
- }
+ response, err := test.responseFunc()
+ assert.NoError(t, err)
+ assert.Equal(t, expectedXMLInput, response.XMLInput)
+ assert.Equal(t, test.expectedResponse, response.Body)
})
}
})
diff --git a/pkg/wsmantesting/responses/amt/setupandconfiguration/enumerate.xml b/pkg/wsmantesting/responses/amt/setupandconfiguration/enumerate.xml
new file mode 100644
index 00000000..31474917
--- /dev/null
+++ b/pkg/wsmantesting/responses/amt/setupandconfiguration/enumerate.xml
@@ -0,0 +1,22 @@
+
+
+
+ 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_SetupAndConfigurationService
+
+
+
+ D3000000-0000-0000-0000-000000000000
+
+
+
\ No newline at end of file
diff --git a/pkg/wsmantesting/responses/amt/setupandconfiguration/get.xml b/pkg/wsmantesting/responses/amt/setupandconfiguration/get.xml
new file mode 100644
index 00000000..5fa723a1
--- /dev/null
+++ b/pkg/wsmantesting/responses/amt/setupandconfiguration/get.xml
@@ -0,0 +1,34 @@
+
+
+
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
+ 0
+ http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse
+ uuid:00000000-8086-8086-8086-000000000332
+ http://intel.com/wbem/wscim/1/amt-schema/1/AMT_SetupAndConfigurationService
+
+
+
+ AMT_SetupAndConfigurationService
+ Intel(r) AMT Setup and Configuration Service
+ 5
+ Intel(r) AMT Setup and Configuration Service
+ 1
+ 1
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
+ 2
+ 12
+ CIM_ComputerSystem
+ Intel(r) AMT
+ true
+
+
+
\ No newline at end of file