Skip to content

Commit

Permalink
Merge pull request #195 from mtuska/xmlHeader
Browse files Browse the repository at this point in the history
Add Option to Exclude XML Header for NETCONF Messages
  • Loading branch information
carlmontanari authored Sep 24, 2024
2 parents 7262aad + 8df1fee commit 9baa9c5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
version: v1.61
args: --timeout 5m

- name: install gotestsum
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ output:
uniq-by-line: false

service:
golangci-lint-version: 1.60.x
golangci-lint-version: 1.61.x
2 changes: 1 addition & 1 deletion driver/netconf/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (d *Driver) processServerCapabilities() error {
string(sessionIDMatch[1]), err)
}

d.sessionID = uint64(i)
d.sessionID = uint64(i) //nolint:gosec

return nil
}
Expand Down
1 change: 1 addition & 0 deletions driver/netconf/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type Driver struct {
SelectedVersion string

ForceSelfClosingTags bool
ExcludeHeader bool

serverCapabilities []string
sessionID uint64
Expand Down
10 changes: 8 additions & 2 deletions driver/netconf/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ type serializedInput struct {
framedXML []byte
}

func (m *message) serialize(v string, forceSelfClosingTags bool) (*serializedInput, error) {
func (m *message) serialize(
v string,
forceSelfClosingTags,
excludeHeader bool,
) (*serializedInput, error) {
serialized := &serializedInput{}

msg, err := xml.Marshal(m)
if err != nil {
return nil, err
}

msg = append([]byte(xmlHeader), msg...)
if !excludeHeader {
msg = append([]byte(xmlHeader), msg...)
}

if forceSelfClosingTags {
msg = ForceSelfClosingTags(msg)
Expand Down
2 changes: 1 addition & 1 deletion driver/netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *Driver) sendRPC(
d.Logger.Debug("ForceSelfClosingTags is true, enforcing...")
}

serialized, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags)
serialized, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags, d.ExcludeHeader)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions driver/options/netconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ func WithNetconfForceSelfClosingTags() util.Option {
return nil
}
}

// WithNetconfExcludeHeader excludes the XML header from the NETCONF message.
// This is useful for devices that do not support the XML header.
func WithNetconfExcludeHeader() util.Option {
return func(o interface{}) error {
d, ok := o.(*netconf.Driver)

if !ok {
return util.ErrIgnoredOption
}

d.ExcludeHeader = true

return nil
}
}

0 comments on commit 9baa9c5

Please sign in to comment.