Files
opentf/vendor/github.com/apparentlymart/go-rundeck-api/rundeck/util.go
Paul Hinze 6fe2703665 Vendor all dependencies w/ Godep
* Remove `make updatedeps` from Travis build. We'll follow up with more
   specific plans around dependency updating in subsequent PRs.
 * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to
   filter out `/vendor/` from `./...` where appropriate.
 * Temporarily remove `vet` from the `make test` target until we can
   figure out how to get it to not vet `vendor/`. (Initial
   experimentation failed to yield the proper incantation.)

Everything is pinned to current master, with the exception of:

 * Azure/azure-sdk-for-go which is pinned before the breaking change today
 * aws/aws-sdk-go which is pinned to the most recent tag

The documentation still needs to be updated, which we can do in a follow
up PR. The goal here is to unblock release.
2016-01-29 15:08:48 -06:00

82 lines
1.7 KiB
Go

package rundeck
import (
"encoding/xml"
"fmt"
"sort"
)
func marshalMapToXML(c *map[string]string, e *xml.Encoder, start xml.StartElement, entryName string, keyName string, valueName string) error {
if len(*c) == 0 {
return nil
}
e.EncodeToken(start)
// Sort the keys so we'll have a deterministic result.
keys := []string{}
for k, _ := range *c {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := (*c)[k]
e.EncodeToken(xml.StartElement{
Name: xml.Name{Local: entryName},
Attr: []xml.Attr{
xml.Attr{
Name: xml.Name{Local: keyName},
Value: k,
},
xml.Attr{
Name: xml.Name{Local: valueName},
Value: v,
},
},
})
e.EncodeToken(xml.EndElement{xml.Name{Local: entryName}})
}
e.EncodeToken(xml.EndElement{start.Name})
return nil
}
func unmarshalMapFromXML(c *map[string]string, d *xml.Decoder, start xml.StartElement, entryName string, keyName string, valueName string) error {
result := map[string]string{}
for {
token, err := d.Token()
if token == nil {
err = fmt.Errorf("EOF while decoding job command plugin config")
}
if err != nil {
return err
}
switch t := token.(type) {
default:
continue
case xml.StartElement:
if t.Name.Local != entryName {
return fmt.Errorf("unexpected element %s while looking for config entries", t.Name.Local)
}
var k string
var v string
for _, attr := range t.Attr {
if attr.Name.Local == keyName {
k = attr.Value
} else if attr.Name.Local == valueName {
v = attr.Value
}
}
if k == "" {
return fmt.Errorf("found config entry with empty key")
}
result[k] = v
case xml.EndElement:
if t.Name.Local == start.Name.Local {
*c = result
return nil
}
}
}
}