Skip to content

Commit

Permalink
refactor!: v2.0 updates (#209)
Browse files Browse the repository at this point in the history
docs: adds code comments for functions, types, and properties
fix: only send Digest challenge when realm is known
feat: adds apf package
feat: adds proxy support to client

BREAKING CHANGE: rename module to github.com/open-amt-cloud-toolkit/go-wsman-messages/v2
BREAKING CHANGE: returns structured parsed responses from amt
BREAKING CHANGE: moves amt, cim, ips into their own packages under wsman
BREAKING CHANGE: refactors parameters for wsman.NewMessages into struct called client.Parameters
BREAKING CHANGE: most types have been refactored to represent handle requests and responses
with amt. refer to https://pkg.go.dev/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 for a
complete list of updated types
BREAKING CHANGE: adds option to enable logging of wsman messages

Co-authored-by: zaidusmani26 <[email protected]>
Co-authored-by: Mike <[email protected]>
Co-authored-by: joko-sastriawan <[email protected]>
  • Loading branch information
4 people authored Feb 5, 2024
1 parent 8c7829f commit 579cec5
Show file tree
Hide file tree
Showing 614 changed files with 38,982 additions and 9,344 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ on:
types:
- created
push:
branches: [ main ]
branches: [ main, v2.0 ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [ main, v2.0 ]
schedule:
- cron: '26 23 * * 0'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ name: Go CI

on:
push:
branches: [main]
branches: [ main, v2.0]
pull_request:
branches: [main]
branches: [ main, v2.0]
workflow_dispatch:
permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.exe
**/*.xml
coverage

!**/wsmantesting/responses/**/*.xml
Empty file removed CHANGELOG.md
Empty file.
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
module github.com/open-amt-cloud-toolkit/go-wsman-messages
module github.com/open-amt-cloud-toolkit/go-wsman-messages/v2

go 1.20

require github.com/stretchr/testify v1.8.4
require (
github.com/google/uuid v1.4.0
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
require golang.org/x/sys v0.13.0 // indirect

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gorilla/websocket v1.5.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3
gopkg.in/yaml.v3 v3.0.1 // indirect
golang.org/x/net v0.17.0 // indirect
)
9 changes: 8 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand All @@ -9,8 +13,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
16 changes: 5 additions & 11 deletions internal/message/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@ package message
import (
"fmt"

"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client"
)

type Base struct {
WSManMessageCreator *WSManMessageCreator
className string
client wsman.WSManClient
}

func NewBase(wsmanMessageCreator *WSManMessageCreator, className string) Base {
return Base{
WSManMessageCreator: wsmanMessageCreator,
className: className,
}
}

func NewBaseWithClient(wsmanMessageCreator *WSManMessageCreator, className string, client wsman.WSManClient) Base {
func NewBaseWithClient(wsmanMessageCreator *WSManMessageCreator, className string, client client.WSMan) Base {
return Base{
WSManMessageCreator: wsmanMessageCreator,
className: className,
client: client,
}
}

// Enumerates the instances of this class
// Enumerate returns an enumeration context which is used in a subsequent Pull call
func (b *Base) Enumerate() string {
header := b.WSManMessageCreator.CreateHeader(BaseActionsEnumerate, b.className, nil, "", "")

Expand All @@ -45,7 +39,7 @@ func (b *Base) Get(selector *Selector) string {
return b.WSManMessageCreator.CreateXML(header, GetBody)
}

// Pulls instances of this class, following an Enumerate operation
// Pull returns the instances of this class. An enumeration context provided by the Enumerate call is used as input.
func (b *Base) Pull(enumerationContext string) string {
header := b.WSManMessageCreator.CreateHeader(BaseActionsPull, b.className, nil, "", "")
body := createCommonBodyPull(enumerationContext, 0, 0)
Expand Down Expand Up @@ -88,7 +82,7 @@ func (b *Base) RequestStateChange(actionName string, requestedState int) string
return b.WSManMessageCreator.CreateXML(header, body)
}

func (b *Base) Execute(message *wsman.Message) error {
func (b *Base) Execute(message *client.Message) error {
if b.client != nil {
xmlResponse, err := b.client.Post(message.XMLInput)
message.XMLOutput = string(xmlResponse)
Expand Down
5 changes: 5 additions & 0 deletions internal/message/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ const (
DeleteBody = "<Body></Body>"
EnumerateBody = "<Body><Enumerate xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" /></Body>"
GetBody = "<Body></Body>"
AMTSchema = "http://intel.com/wbem/wscim/1/amt-schema/1/"
CIMSchema = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
IPSSchema = "http://intel.com/wbem/wscim/1/ips-schema/1/"
XMLBodySpace = "http://www.w3.org/2003/05/soap-envelope"
XMLPullResponseSpace = "http://schemas.xmlsoap.org/ws/2004/09/enumeration"
)
38 changes: 38 additions & 0 deletions internal/message/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ package message

import (
"encoding/xml"

"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client"
)

type Base struct {
WSManMessageCreator *WSManMessageCreator
className string
client client.WSMan
}

type Header struct {
XMLName xml.Name `xml:"Header"`
To string `xml:"To"`
Expand All @@ -22,3 +30,33 @@ type Action struct {
MustUnderstand string `xml:"mustUnderstand,attr"`
Value string `xml:",chardata"`
}

type SelectorSet struct {
XMLName xml.Name `xml:"SelectorSet"`
Selector Selector
}

type Selector struct {
XMLName xml.Name `xml:"Selector,omitempty"`
Name string `xml:"Name,attr"`
Value string `xml:",chardata"`
}
type Selector_OUTPUT struct {
XMLName xml.Name `xml:"Selector,omitempty"`
Name string `xml:"Name,attr"`
Value string `xml:",chardata"`
}

type ReturnValue struct {
XMLName xml.Name `xml:"RequestStateChange_OUTPUT,omitempty"`
ReturnValue int `xml:"ReturnValue,omitempty"`
ReturnValueStr string `xml:"ReturnValueStr,omitempty"`
}
type WSManMessageCreator struct {
MessageID int
XmlCommonPrefix string
XmlCommonEnd string
AnonymousAddress string
DefaultTimeout string
ResourceURIBase string
}
48 changes: 0 additions & 48 deletions internal/message/wsman.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@ import (
"strings"
)

type Selector struct {
XMLName xml.Name `xml:"w:Selector,omitempty"`
Name string `xml:"Name,attr"`
Value string `xml:",chardata"`
}
type Selector_OUTPUT struct {
XMLName xml.Name `xml:"Selector,omitempty"`
Name string `xml:"Name,attr"`
Value string `xml:",chardata"`
}

type ReturnValue struct {
ReturnValue int
ReturnValueStr string
}
type WSManMessageCreator struct {
MessageID int
XmlCommonPrefix string
XmlCommonEnd string
AnonymousAddress string
DefaultTimeout string
ResourceURIBase string
}

func NewWSManMessageCreator(resourceUriBase string) *WSManMessageCreator {
return &WSManMessageCreator{
MessageID: 0,
Expand Down Expand Up @@ -118,30 +94,6 @@ func (w *WSManMessageCreator) createSelector(selectorSet Selector) string {
return fmt.Sprintf(`<w:SelectorSet><w:Selector Name="%s">%s</w:Selector></w:SelectorSet>`, selectorSet.Name, selectorSet.Value)
}
return ""

// result := "<w:SelectorSet>"
// for propName, propValue := range v {
// propValueMap := propValue.(map[string]interface{})
// result += fmt.Sprintf(`<w:Selector Name="%s">`, propName)
// if refParams, ok := propValueMap["ReferenceParameters"].(map[string]interface{}); ok {
// address := propValueMap["Address"].(string)
// resourceURI := refParams["ResourceURI"].(string)
// selectorSet := refParams["SelectorSet"].(map[string]interface{})
// selectorArray := selectorSet["Selector"].(map[string]interface{})
// result += "<a:EndpointReference>"
// result += fmt.Sprintf(`<a:Address>%s</a:Address><a:ReferenceParameters><w:ResourceURI>%s</w:ResourceURI><w:SelectorSet>`, address, resourceURI)

// if name, ok := selectorArray["$.Name"].(string); ok {
// value := selectorArray["_"].(string)
// result += fmt.Sprintf(`<w:Selector Name="%s">%s</w:Selector>`, name, value)
// }
// result += "</w:SelectorSet></a:ReferenceParameters></a:EndpointReference>"
// }
// result += "</w:Selector>"
// }
// result += "</w:SelectorSet>"
// return result

}

// createSelectorObjectForBody creates an object for the body using the given selector.
Expand Down
48 changes: 0 additions & 48 deletions pkg/amt/actions/constants.go

This file was deleted.

Loading

0 comments on commit 579cec5

Please sign in to comment.