Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amt): adds execute support for authorization #94

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 145 additions & 59 deletions pkg/amt/authorization/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,35 @@
"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"`
AuthorizationOccurrence AuthorizationOccurrence `xml:"AMT_AuthorizationService"`

EnumerateResponse common.EnumerateResponse
}

AuthorizationOccurrence struct {
AllowHttpQopAuthOnly int
CreationClassName string
ElementName string
EnabledState int
Name string
RequestedState int
SystemCreationClassName string
SystemName string
}
)
type AddUserAclEntry struct {
XMLName xml.Name `xml:"h:AddUserAclEntryEx_INPUT"`
H string `xml:"xmlns:h,attr"`
Expand Down Expand Up @@ -67,7 +93,8 @@
)

type AuthorizationService struct {
base message.Base
base message.Base
client wsman.WSManClient
}
type EnumerateUserAclEntries_INPUT struct {
XMLName xml.Name `xml:"h:EnumerateUserAclEntries_INPUT"`
Expand Down Expand Up @@ -112,80 +139,139 @@
// 3) All the methods of 'AMT_AuthorizationService' except for 'Get' are not supported in Remote Connectivity Service provisioning mode
func NewAuthorizationService(wsmanMessageCreator *message.WSManMessageCreator) AuthorizationService {
return AuthorizationService{
base: message.NewBase(wsmanMessageCreator, AMT_AuthorizationService),
base: message.NewBase(wsmanMessageCreator, AMT_AuthorizationService),
client: nil,
}

Check warning on line 144 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L142-L144

Added lines #L142 - L144 were not covered by tests
}
func NewServiceWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) AuthorizationService {
return AuthorizationService{
base: message.NewBaseWithClient(wsmanMessageCreator, AMT_AuthorizationService, client),
client: client,
}
}

// Get retrieves the representation of the instance
func (AuthorizationService AuthorizationService) Get() string {
return AuthorizationService.base.Get(nil)
func (as AuthorizationService) Get() (response Response, err error) {
response = Response{
Message: &wsman.Message{
XMLInput: as.base.Get(nil),
},
}

// send the message to AMT
err = as.base.Execute(response.Message)
if err != nil {
return
}

Check warning on line 165 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L164-L165

Added lines #L164 - L165 were not covered by tests

// put the xml response into the go struct
err = xml.Unmarshal([]byte(response.XMLOutput), &response)
if err != nil {
return
}

Check warning on line 171 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L170-L171

Added lines #L170 - L171 were not covered by tests

return
}

// Enumerates the instances of this class
func (AuthorizationService AuthorizationService) Enumerate() string {
return AuthorizationService.base.Enumerate()
func (as AuthorizationService) Enumerate() (response Response, err error) {
response = Response{
Message: &wsman.Message{
XMLInput: as.base.Enumerate(),
},
}
// send the message to AMT
err = as.base.Execute(response.Message)
if err != nil {
return
}

Check warning on line 187 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L186-L187

Added lines #L186 - L187 were not covered by tests

// put the xml response into the go struct
err = xml.Unmarshal([]byte(response.XMLOutput), &response)
if err != nil {
return
}

Check warning on line 193 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L192-L193

Added lines #L192 - L193 were not covered by tests

return
}

// Pulls instances of this class, following an Enumerate operation
func (AuthorizationService AuthorizationService) Pull(enumerationContext string) string {
return AuthorizationService.base.Pull(enumerationContext)
}
// func (as AuthorizationService) Pull(enumerationContext string) (response Response, err error) {
// response = Response{
// Message: &wsman.Message{
// XMLInput: as.base.Pull(enumerationContext),
// },
// }
// // send the message to AMT
// err = as.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
// }

// EnumerateUserAclEntries enumerates entries in the User Access Control List (ACL).
func (as AuthorizationService) EnumerateUserAclEntries(startIndex int) string {
if startIndex == 0 {
startIndex = 1
}
header := as.base.WSManMessageCreator.CreateHeader(string(actions.EnumerateUserAclEntries), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("EnumerateUserAclEntries_INPUT", AMT_AuthorizationService, &EnumerateUserAclEntries_INPUT{StartIndex: startIndex})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) EnumerateUserAclEntries(startIndex int) string {
// if startIndex == 0 {
// startIndex = 1
// }
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.EnumerateUserAclEntries), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("EnumerateUserAclEntries_INPUT", AMT_AuthorizationService, &EnumerateUserAclEntries_INPUT{StartIndex: startIndex})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) GetAclEnabledState(handle int) string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAclEnabledState), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("GetAclEnabledState_INPUT", AMT_AuthorizationService, &GetAclEnabledState_INPUT{Handle: handle})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) GetAclEnabledState(handle int) string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAclEnabledState), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("GetAclEnabledState_INPUT", AMT_AuthorizationService, &GetAclEnabledState_INPUT{Handle: handle})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) GetAdminAclEntry() string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminAclEntry), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("GetAdminAclEntry_INPUT", AMT_AuthorizationService, nil)
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) GetAdminAclEntry() string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminAclEntry), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("GetAdminAclEntry_INPUT", AMT_AuthorizationService, nil)
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) GetAdminAclEntryStatus() string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminAclEntryStatus), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("GetAdminAclEntryStatus_INPUT", AMT_AuthorizationService, nil)
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) GetAdminAclEntryStatus() string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminAclEntryStatus), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("GetAdminAclEntryStatus_INPUT", AMT_AuthorizationService, nil)
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) GetAdminNetAclEntryStatus() string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminNetAclEntryStatus), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("GetAdminNetAclEntryStatus_INPUT", AMT_AuthorizationService, nil)
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) GetAdminNetAclEntryStatus() string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetAdminNetAclEntryStatus), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("GetAdminNetAclEntryStatus_INPUT", AMT_AuthorizationService, nil)
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

// GetUserAclEntryEx reads a user entry from the Intel(R) AMT device.
func (as AuthorizationService) GetUserAclEntryEx(handle int) string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetUserAclEntryEx), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("GetUserAclEntryEx_INPUT", AMT_AuthorizationService, &GetUserAclEntryEx_INPUT{Handle: handle})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// // GetUserAclEntryEx reads a user entry from the Intel(R) AMT device.
// func (as AuthorizationService) GetUserAclEntryEx(handle int) string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.GetUserAclEntryEx), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("GetUserAclEntryEx_INPUT", AMT_AuthorizationService, &GetUserAclEntryEx_INPUT{Handle: handle})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) RemoveUserAclEntry(handle int) string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.RemoveUserAclEntry), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("RemoveUserAclEntry_INPUT", AMT_AuthorizationService, &RemoveUserAclEntry_INPUT{Handle: handle})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) RemoveUserAclEntry(handle int) string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.RemoveUserAclEntry), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("RemoveUserAclEntry_INPUT", AMT_AuthorizationService, &RemoveUserAclEntry_INPUT{Handle: handle})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) SetAclEnabledState(handle int, enabled bool) string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.SetAclEnabledState), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("SetAclEnabledState_INPUT", AMT_AuthorizationService, &SetAclEnabledState_INPUT{Handle: handle, Enabled: enabled})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) SetAclEnabledState(handle int, enabled bool) string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.SetAclEnabledState), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("SetAclEnabledState_INPUT", AMT_AuthorizationService, &SetAclEnabledState_INPUT{Handle: handle, Enabled: enabled})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }

func (as AuthorizationService) SetAdminACLEntryEx(username, digestPassword string) string {
header := as.base.WSManMessageCreator.CreateHeader(string(actions.SetAdminAclEntryEx), AMT_AuthorizationService, nil, "", "")
body := as.base.WSManMessageCreator.CreateBody("SetAdminAclEntryEx_INPUT", AMT_AuthorizationService, &SetAdminACLEntryEx_INPUT{Username: username, DigestPassword: digestPassword})
return as.base.WSManMessageCreator.CreateXML(header, body)
}
// func (as AuthorizationService) SetAdminACLEntryEx(username, digestPassword string) string {
// header := as.base.WSManMessageCreator.CreateHeader(string(actions.SetAdminAclEntryEx), AMT_AuthorizationService, nil, "", "")
// body := as.base.WSManMessageCreator.CreateBody("SetAdminAclEntryEx_INPUT", AMT_AuthorizationService, &SetAdminACLEntryEx_INPUT{Username: username, DigestPassword: digestPassword})
// return as.base.WSManMessageCreator.CreateXML(header, body)
// }
Loading
Loading