Skip to content

Commit

Permalink
feat(amt): adds execute support for remote
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidusmani26 committed Oct 30, 2023
1 parent 339572b commit cf52443
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 99 deletions.
60 changes: 30 additions & 30 deletions pkg/amt/remoteaccess/policyappliestomps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
const AMT_RemoteAccessPolicyAppliesToMPS = "AMT_RemoteAccessPolicyAppliesToMPS"

type (
Response struct {
ResponseApplies struct {
*wsman.Message
XMLName xml.Name `xml:"Envelope"`
Header message.Header `xml:"Header"`
Body Body `xml:"Body"`
XMLName xml.Name `xml:"Envelope"`
Header message.Header `xml:"Header"`
BodyApplies BodyApplies `xml:"Body"`
}
Body struct {
BodyApplies struct {
XMLName xml.Name `xml:"Body"`
PolicyApplies PolicyApplies `xml:"AMT_RemoteAccessPolicyAppliesToMPS"`

Expand Down Expand Up @@ -86,8 +86,8 @@ type PolicyAppliesToMPS struct {
client wsman.WSManClient
}

func (w *Response) JSON() string {
jsonOutput, err := json.Marshal(w.Body)
func (w *ResponseApplies) JSON() string {
jsonOutput, err := json.Marshal(w.BodyApplies)
if err != nil {
return ""
}
Expand All @@ -108,8 +108,8 @@ func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessage
}

// Get retrieves the representation of the instance
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Response, err error) {
response = Response{
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response ResponseApplies, err error) {
response = ResponseApplies{
Message: &wsman.Message{
XMLInput: RemoteAccessPolicyAppliesToMPS.base.Get(nil),
},
Expand All @@ -129,8 +129,8 @@ func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Respons
}

// Enumerates the instances of this class
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response Response, err error) {
response = Response{
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response ResponseApplies, err error) {
response = ResponseApplies{
Message: &wsman.Message{
XMLInput: RemoteAccessPolicyAppliesToMPS.base.Enumerate(),
},
Expand All @@ -151,22 +151,22 @@ func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response R
}

// Pulls instances of this class, following an Enumerate operation
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string {
return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext)
}

// Put will change properties of the selected instance
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Put(remoteAccessPolicyAppliesToMPS *RemoteAccessPolicyAppliesToMPS) string {
return RemoteAccessPolicyAppliesToMPS.base.Put(remoteAccessPolicyAppliesToMPS, false, nil)
}

// Delete removes a the specified instance
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Delete(handle string) string {
selector := message.Selector{Name: "Name", Value: handle}
return RemoteAccessPolicyAppliesToMPS.base.Delete(selector)
}

// Creates a new instance of this class
func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Create(remoteAccessPolicyAppliesToMPS RemoteAccessPolicyAppliesToMPS) string {
return RemoteAccessPolicyAppliesToMPS.base.Create(remoteAccessPolicyAppliesToMPS, nil)
}
// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string {
// return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext)
// }

// // Put will change properties of the selected instance
// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Put(remoteAccessPolicyAppliesToMPS *RemoteAccessPolicyAppliesToMPS) string {
// return RemoteAccessPolicyAppliesToMPS.base.Put(remoteAccessPolicyAppliesToMPS, false, nil)
// }

// // Delete removes a the specified instance
// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Delete(handle string) string {
// selector := message.Selector{Name: "Name", Value: handle}
// return RemoteAccessPolicyAppliesToMPS.base.Delete(selector)
// }

// // Creates a new instance of this class
// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Create(remoteAccessPolicyAppliesToMPS RemoteAccessPolicyAppliesToMPS) string {
// return RemoteAccessPolicyAppliesToMPS.base.Create(remoteAccessPolicyAppliesToMPS, nil)
// }
22 changes: 6 additions & 16 deletions pkg/amt/remoteaccess/policyappliestomps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"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/cim/models"
//"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting"
)
Expand All @@ -30,8 +28,6 @@ const (
GetBodyApply = `<g:AMT_AuthorizationService><g:CreationClassName>AMT_AuthorizationService</g:CreationClassName><g:ElementName>Intel(r) AMT Authorization Service</g:ElementName><g:Name>Intel(r) AMT Alarm Clock Service</g:Name><g:SystemCreationClassName>CIM_ComputerSystem</g:SystemCreationClassName><g:SystemName>ManagedSystem</g:SystemName></g:AMT_AuthorizationService>`
)

//var currentMessageApply = ""

func (c *MockClientApply) Post(msg string) ([]byte, error) {
// read an xml file from disk:
xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyappliestomps/" + strings.ToLower(currentMessage) + ".xml")
Expand All @@ -56,12 +52,7 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) {
messageID := 0
resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/"
wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase)
// client := wsmantesting.MockClient{
// PackageUnderTest: "amt/general",
// }
client := MockClientApply{}
//client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true)

elementUnderTest := NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator, &client)
t.Run("amt_* Tests", func(t *testing.T) {
tests := []struct {
Expand All @@ -70,7 +61,7 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) {
action string
body string
extraHeader string
responseFunc func() (Response, error)
responseFunc func() (ResponseApplies, error)
expectedResponse interface{}
}{
//GETS
Expand All @@ -80,11 +71,11 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) {
wsmantesting.GET,
"",
"",
func() (Response, error) {
func() (ResponseApplies, error) {
currentMessage = "Get"
return elementUnderTest.Get()
},
Body{
BodyApplies{
XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"},
PolicyApplies: PolicyApplies{
CreationClassName: "",
Expand All @@ -101,11 +92,11 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) {
wsmantesting.ENUMERATE,
wsmantesting.ENUMERATE_BODY,
"",
func() (Response, error) {
func() (ResponseApplies, error) {
currentMessage = "Enumerate"
return elementUnderTest.Enumerate()
},
Body{
BodyApplies{
XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"},
EnumerateResponse: common.EnumerateResponse{
EnumerationContext: "CE000000-0000-0000-0000-000000000000",
Expand Down Expand Up @@ -154,10 +145,9 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) {
expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
messageID++
response, err := test.responseFunc()
//println(response.XMLOutput)
assert.NoError(t, err)
assert.Equal(t, expectedXMLInput, response.XMLInput)
assert.Equal(t, test.expectedResponse, response.Body)
assert.Equal(t, test.expectedResponse, response.BodyApplies)
})
}
})
Expand Down
29 changes: 14 additions & 15 deletions pkg/amt/remoteaccess/policyrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/xml"

"github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message"
//"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"
)
Expand Down Expand Up @@ -127,17 +126,17 @@ func (RemoteAccessPolicyRule PolicyRule) Enumerate() (response ResponseRule, err
}

// Pulls instances of this class, following an Enumerate operation
func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string {
return RemoteAccessPolicyRule.base.Pull(enumerationContext)
}

// Put will change properties of the selected instance
func (RemoteAccessPolicyRule PolicyRule) Put(remoteAccessPolicyRule RemoteAccessPolicyRule) string {
return RemoteAccessPolicyRule.base.Put(remoteAccessPolicyRule, false, nil)
}

// Delete removes a the specified instance
func (RemoteAccessPolicyRule PolicyRule) Delete(handle string) string {
selector := message.Selector{Name: "PolicyRuleName", Value: handle}
return RemoteAccessPolicyRule.base.Delete(selector)
}
// func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string {
// return RemoteAccessPolicyRule.base.Pull(enumerationContext)
// }

// // Put will change properties of the selected instance
// func (RemoteAccessPolicyRule PolicyRule) Put(remoteAccessPolicyRule RemoteAccessPolicyRule) string {
// return RemoteAccessPolicyRule.base.Put(remoteAccessPolicyRule, false, nil)
// }

// // Delete removes a the specified instance
// func (RemoteAccessPolicyRule PolicyRule) Delete(handle string) string {
// selector := message.Selector{Name: "PolicyRuleName", Value: handle}
// return RemoteAccessPolicyRule.base.Delete(selector)
// }
10 changes: 0 additions & 10 deletions pkg/amt/remoteaccess/policyrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (

"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/cim/models"
//"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting"
)

Expand All @@ -29,8 +27,6 @@ const (
GetBodyPolicy = `<g:AMT_AuthorizationService><g:CreationClassName>AMT_RemoteAccessPolicyRule</g:CreationClassName><g:ElementName>Intel(r) AMT Remote Access Policy Rule</g:ElementName><g:Name>Intel(r) AMT Remote Access Policy Rule</g:Name><g:SystemCreationClassName>CIM_ComputerSystem</g:SystemCreationClassName><g:SystemName>ManagedSystem</g:SystemName></g:AMT_RemoteAccessPolicyRule>`
)

//var currentMessage = ""

func (c *MockClientPolicy) Post(msg string) ([]byte, error) {
// read an xml file from disk:
xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyrule/" + strings.ToLower(currentMessage) + ".xml")
Expand All @@ -55,12 +51,7 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) {
messageID := 0
resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/"
wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase)
// client := wsmantesting.MockClient{
// PackageUnderTest: "amt/general",
// }
clientPolicy := MockClientPolicy{}
//client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true)

elementUnderTest := NewPolicyRuleWithClient(wsmanMessageCreator, &clientPolicy)

t.Run("amt_* Tests", func(t *testing.T) {
Expand Down Expand Up @@ -129,7 +120,6 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) {
expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
messageID++
response, err := test.responseFunc()
//println(response.XMLOutput)
assert.NoError(t, err)
assert.Equal(t, expectedXMLInput, response.XMLInput)
assert.Equal(t, test.expectedResponse, response.BodyRule)
Expand Down
27 changes: 12 additions & 15 deletions pkg/amt/remoteaccess/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
package remoteaccess

import (
//"fmt"

"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/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_RemoteAccessService = "AMT_RemoteAccessService"

type (
ResponseStomps struct {
Response struct {
*wsman.Message
XMLName xml.Name `xml:"Envelope"`
Header message.Header `xml:"Header"`
BodyStomps BodyStomps `xml:"Body"`
Body Body `xml:"Body"`
}
BodyStomps struct {
Body struct {
XMLName xml.Name `xml:"Body"`
RemoteAccess RemoteAccess `xml:"AMT_RemoteAccessService"`

Expand Down Expand Up @@ -69,8 +66,8 @@ const (
UsernamePasswordAuthentication MPServerAuthMethod = 2
)

func (w *ResponseStomps) JSONStomps() string {
jsonOutput, err := json.Marshal(w.BodyStomps)
func (w *Response) JSONStomps() string {
jsonOutput, err := json.Marshal(w.Body)
if err != nil {
return ""
}
Expand All @@ -91,8 +88,8 @@ func NewRemoteAccessServiceWithClient(wsmanMessageCreator *message.WSManMessageC
}

// Get retrieves the representation of the instance
func (RemoteAccessService Service) Get() (response ResponseStomps, err error) {
response = ResponseStomps{
func (RemoteAccessService Service) Get() (response Response, err error) {
response = Response{
Message: &wsman.Message{
XMLInput: RemoteAccessService.base.Get(nil),
},
Expand All @@ -112,8 +109,8 @@ func (RemoteAccessService Service) Get() (response ResponseStomps, err error) {
}

// Enumerates the instances of this class
func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err error) {
response = ResponseStomps{
func (RemoteAccessService Service) Enumerate() (response Response, err error) {
response = Response{
Message: &wsman.Message{
XMLInput: RemoteAccessService.base.Enumerate(),
},
Expand All @@ -134,9 +131,9 @@ func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err err
}

// Pulls instances of this class, following an Enumerate operation
func (RemoteAccessService Service) Pull(enumerationContext string) string {
return RemoteAccessService.base.Pull(enumerationContext)
}
// func (RemoteAccessService Service) Pull(enumerationContext string) string {
// return RemoteAccessService.base.Pull(enumerationContext)
// }

/*func (r Service) AddMPS(mpServer MPServer) string {
header := r.base.WSManMessageCreator.CreateHeader(string(actions.AddMps), AMT_RemoteAccessService, nil, "", "")
Expand Down
19 changes: 6 additions & 13 deletions pkg/amt/remoteaccess/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"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/cim/models"
//"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting"
)
Expand Down Expand Up @@ -57,19 +55,15 @@ func TestAMT_RemoteAccessService(t *testing.T) {
messageID := 0
resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/"
wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase)
/*client := wsmantesting.MockClient{
PackageUnderTest: "amt/remoteaccess",
}*/
client := MockClient{}
//client := wsman.NewServiceWithClient("http://localhost:16992/wsman", "admin", "Intel123!", true)
elementUnderTest := NewRemoteAccessServiceWithClient(wsmanMessageCreator, &client)
t.Run("amt_* Tests", func(t *testing.T) {
tests := []struct {
name string
method string
action string
body string
responseFunc func() (ResponseStomps, error)
responseFunc func() (Response, error)
expectedResponse interface{}
}{
//GETS
Expand All @@ -78,11 +72,11 @@ func TestAMT_RemoteAccessService(t *testing.T) {
"AMT_RemoteAccessService",
wsmantesting.GET,
"",
func() (ResponseStomps, error) {
func() (Response, error) {
currentMessage = "Get"
return elementUnderTest.Get()
},
BodyStomps{
Body{
XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"},
RemoteAccess: RemoteAccess{
CreationClassName: "AMT_RemoteAccessService",
Expand All @@ -99,11 +93,11 @@ func TestAMT_RemoteAccessService(t *testing.T) {
"AMT_RemoteAccessService",
wsmantesting.ENUMERATE,
wsmantesting.ENUMERATE_BODY,
func() (ResponseStomps, error) {
func() (Response, error) {
currentMessage = "Enumerate"
return elementUnderTest.Enumerate()
},
BodyStomps{
Body{
XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"},
EnumerateResponse: common.EnumerateResponse{
EnumerationContext: "D3000000-0000-0000-0000-000000000000",
Expand Down Expand Up @@ -143,10 +137,9 @@ func TestAMT_RemoteAccessService(t *testing.T) {
expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
messageID++
response, err := test.responseFunc()
//println(response.XMLOutput)
assert.NoError(t, err)
assert.Equal(t, expectedXMLInput, response.XMLInput)
assert.Equal(t, test.expectedResponse, response.BodyStomps)
assert.Equal(t, test.expectedResponse, response.Body)
})
}
})
Expand Down

0 comments on commit cf52443

Please sign in to comment.