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 1 commit
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
121 changes: 113 additions & 8 deletions pkg/amt/authorization/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,48 @@
package authorization

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/amt/models"
"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
//PullResponse PullResponse
}
/*PullResponse struct {
Items []Item
}
Item struct {
AuthorizationService AuthorizationService `xml:"AMT_AuthorizationService"`
}*/

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 @@ -43,6 +79,14 @@

type RealmValues int

func (w *Response) JSON() string {
jsonOutput, err := json.Marshal(w.Body)
if err != nil {
return ""
}
return string(jsonOutput)

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

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L82-L87

Added lines #L82 - L87 were not covered by tests
}

const AMT_AuthorizationService = "AMT_AuthorizationService"

const (
Expand All @@ -67,7 +111,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,23 +157,83 @@
// 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 162 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L160-L162

Added lines #L160 - L162 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 184 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L183-L184

Added lines #L183 - L184 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 190 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L189-L190

Added lines #L189 - L190 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 206 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L205-L206

Added lines #L205 - L206 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 212 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L211-L212

Added lines #L211 - L212 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
}

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

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L218-L228

Added lines #L218 - L228 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 234 in pkg/amt/authorization/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L231-L234

Added lines #L231 - L234 were not covered by tests

return

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

View check run for this annotation

Codecov / codecov/patch

pkg/amt/authorization/service.go#L236

Added line #L236 was not covered by tests
}

// EnumerateUserAclEntries enumerates entries in the User Access Control List (ACL).
Expand Down
Loading
Loading