This changeset performs the following: - Updates `masterzen/winrm` vendor to include change from (https://github.com/masterzen/winrm/pull/73). - Removes `masterzen/xmlpath` dependency, as it is licensed under the LGPL license. - Updates `dylanmei/winrmtest` vendor to include change from (https://github.com/dylanmei/winrmtest/pull/4). - Updates `packer-community/winrmcp` vendor to include the removal of the `masterzen/winrm/winrm` sub-class as a result of the `winrm` CLI tool being removed from the `masterzen/winrm` repository. - Updates nested dependencies as a result of the above vendor changes. - Refactors `parallels/driver_9` to use `goxpath` instead of `xmlpath`, as `xmlpath` is licensed under LGPL. - Adds a basic unit test for the refactor work in `parallels/driver_9` to confirm functionality. This should completely remove any LGPL licensed dependencies inside of the Packer project. ``` $ make test /home/jake/src/go/src/github.com/hashicorp/packer/scripts/gofmtcheck.sh $(find . -not -path "./vendor/*" -name "*.go") ==> Checking that code complies with gofmt requirements... Check passed. ok github.com/hashicorp/packer 0.044s ok github.com/hashicorp/packer/builder/alicloud/ecs 0.055s ok github.com/hashicorp/packer/builder/amazon/chroot 0.040s ok github.com/hashicorp/packer/builder/amazon/common 0.021s ok github.com/hashicorp/packer/builder/amazon/ebs 0.016s ok github.com/hashicorp/packer/builder/amazon/ebssurrogate 0.015s ok github.com/hashicorp/packer/builder/amazon/ebsvolume 0.014s ok github.com/hashicorp/packer/builder/amazon/instance 0.058s ok github.com/hashicorp/packer/builder/azure/arm 2.833s ok github.com/hashicorp/packer/builder/azure/common 0.018s ? github.com/hashicorp/packer/builder/azure/common/constants [no test files] ? github.com/hashicorp/packer/builder/azure/common/lin [no test files] ? github.com/hashicorp/packer/builder/azure/common/logutil [no test files] ok github.com/hashicorp/packer/builder/azure/common/template 0.038s ok github.com/hashicorp/packer/builder/azure/pkcs12 0.120s ok github.com/hashicorp/packer/builder/azure/pkcs12/rc2 0.020s ok github.com/hashicorp/packer/builder/cloudstack 0.038s ok github.com/hashicorp/packer/builder/digitalocean 0.015s ok github.com/hashicorp/packer/builder/docker 0.028s ok github.com/hashicorp/packer/builder/file 0.029s ok github.com/hashicorp/packer/builder/googlecompute 3.162s ok github.com/hashicorp/packer/builder/hyperv/common 0.006s ok github.com/hashicorp/packer/builder/hyperv/iso 0.042s ok github.com/hashicorp/packer/builder/null 0.018s ok github.com/hashicorp/packer/builder/oneandone 0.022s ok github.com/hashicorp/packer/builder/openstack 0.052s ok github.com/hashicorp/packer/builder/parallels/common 2.549s ok github.com/hashicorp/packer/builder/parallels/iso 0.050s ok github.com/hashicorp/packer/builder/parallels/pvm 0.033s ok github.com/hashicorp/packer/builder/profitbricks 0.023s ok github.com/hashicorp/packer/builder/qemu 0.039s ok github.com/hashicorp/packer/builder/triton 0.018s ok github.com/hashicorp/packer/builder/virtualbox/common 5.533s ok github.com/hashicorp/packer/builder/virtualbox/iso 0.044s ok github.com/hashicorp/packer/builder/virtualbox/ovf 0.012s ok github.com/hashicorp/packer/builder/vmware/common 5.325s ok github.com/hashicorp/packer/builder/vmware/iso 0.076s ok github.com/hashicorp/packer/builder/vmware/vmx 0.010s ok github.com/hashicorp/packer/command 0.062s ok github.com/hashicorp/packer/common 0.053s ok github.com/hashicorp/packer/common/json 0.003s [no tests to run] ok github.com/hashicorp/packer/common/powershell 0.015s ? github.com/hashicorp/packer/common/powershell/hyperv [no test files] ? github.com/hashicorp/packer/common/ssh [no test files] ok github.com/hashicorp/packer/common/uuid 0.010s ok github.com/hashicorp/packer/communicator/none 0.008s ok github.com/hashicorp/packer/communicator/ssh 0.068s ok github.com/hashicorp/packer/communicator/winrm 0.046s ok github.com/hashicorp/packer/fix 0.005s ok github.com/hashicorp/packer/helper/builder/testing 0.007s ok github.com/hashicorp/packer/helper/communicator 0.013s ok github.com/hashicorp/packer/helper/config 0.004s ? github.com/hashicorp/packer/helper/enumflag [no test files] ok github.com/hashicorp/packer/helper/flag-kv 0.009s ok github.com/hashicorp/packer/helper/flag-slice 0.006s ok github.com/hashicorp/packer/packer 0.219s ok github.com/hashicorp/packer/packer/plugin 0.233s ok github.com/hashicorp/packer/packer/rpc 0.141s ok github.com/hashicorp/packer/plugin/example 0.008s [no tests to run] ? github.com/hashicorp/packer/post-processor/alicloud-import [no test files] ? github.com/hashicorp/packer/post-processor/amazon-import [no test files] ok github.com/hashicorp/packer/post-processor/artifice 0.003s [no tests to run] ok github.com/hashicorp/packer/post-processor/atlas 0.018s ok github.com/hashicorp/packer/post-processor/checksum 0.015s ok github.com/hashicorp/packer/post-processor/compress 0.047s ok github.com/hashicorp/packer/post-processor/docker-import 0.012s ok github.com/hashicorp/packer/post-processor/docker-push 0.012s ok github.com/hashicorp/packer/post-processor/docker-save 0.008s ok github.com/hashicorp/packer/post-processor/docker-tag 0.008s ok github.com/hashicorp/packer/post-processor/googlecompute-export 0.015s [no tests to run] ? github.com/hashicorp/packer/post-processor/manifest [no test files] ok github.com/hashicorp/packer/post-processor/shell-local 0.028s ok github.com/hashicorp/packer/post-processor/vagrant 0.030s ok github.com/hashicorp/packer/post-processor/vagrant-cloud 0.028s ok github.com/hashicorp/packer/post-processor/vsphere 0.014s ok github.com/hashicorp/packer/provisioner 0.011s ok github.com/hashicorp/packer/provisioner/ansible 0.140s ok github.com/hashicorp/packer/provisioner/ansible-local 0.056s ok github.com/hashicorp/packer/provisioner/chef-client 0.050s ok github.com/hashicorp/packer/provisioner/chef-solo 0.061s ok github.com/hashicorp/packer/provisioner/converge 0.018s ok github.com/hashicorp/packer/provisioner/file 0.015s ok github.com/hashicorp/packer/provisioner/powershell 0.168s ok github.com/hashicorp/packer/provisioner/puppet-masterless 0.008s ok github.com/hashicorp/packer/provisioner/puppet-server 0.031s ok github.com/hashicorp/packer/provisioner/salt-masterless 0.010s ok github.com/hashicorp/packer/provisioner/shell 0.010s ok github.com/hashicorp/packer/provisioner/shell-local 0.037s ok github.com/hashicorp/packer/provisioner/windows-restart 0.180s ok github.com/hashicorp/packer/provisioner/windows-shell 0.159s ? github.com/hashicorp/packer/scripts [no test files] ok github.com/hashicorp/packer/template 0.008s ok github.com/hashicorp/packer/template/interpolate 0.004s ? github.com/hashicorp/packer/version [no test files] ```
296 lines
5.9 KiB
Go
296 lines
5.9 KiB
Go
package xpath
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"strconv"
|
|
)
|
|
|
|
// The XPath number operator function list.
|
|
|
|
// valueType is a return value type.
|
|
type valueType int
|
|
|
|
const (
|
|
booleanType valueType = iota
|
|
numberType
|
|
stringType
|
|
nodeSetType
|
|
)
|
|
|
|
func getValueType(i interface{}) valueType {
|
|
v := reflect.ValueOf(i)
|
|
switch v.Kind() {
|
|
case reflect.Float64:
|
|
return numberType
|
|
case reflect.String:
|
|
return stringType
|
|
case reflect.Bool:
|
|
return booleanType
|
|
default:
|
|
if _, ok := i.(query); ok {
|
|
return nodeSetType
|
|
}
|
|
}
|
|
panic(fmt.Errorf("xpath unknown value type: %v", v.Kind()))
|
|
}
|
|
|
|
type logical func(iterator, string, interface{}, interface{}) bool
|
|
|
|
var logicalFuncs = [][]logical{
|
|
{cmpBooleanBoolean, nil, nil, nil},
|
|
{nil, cmpNumericNumeric, cmpNumericString, cmpNumericNodeSet},
|
|
{nil, cmpStringNumeric, cmpStringString, cmpStringNodeSet},
|
|
{nil, cmpNodeSetNumeric, cmpNodeSetString, cmpNodeSetNodeSet},
|
|
}
|
|
|
|
// number vs number
|
|
func cmpNumberNumberF(op string, a, b float64) bool {
|
|
switch op {
|
|
case "=":
|
|
return a == b
|
|
case ">":
|
|
return a > b
|
|
case "<":
|
|
return a < b
|
|
case ">=":
|
|
return a >= b
|
|
case "<=":
|
|
return a <= b
|
|
case "!=":
|
|
return a != b
|
|
}
|
|
return false
|
|
}
|
|
|
|
// string vs string
|
|
func cmpStringStringF(op string, a, b string) bool {
|
|
switch op {
|
|
case "=":
|
|
return a == b
|
|
case ">":
|
|
return a > b
|
|
case "<":
|
|
return a < b
|
|
case ">=":
|
|
return a >= b
|
|
case "<=":
|
|
return a <= b
|
|
case "!=":
|
|
return a != b
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpBooleanBooleanF(op string, a, b bool) bool {
|
|
switch op {
|
|
case "or":
|
|
return a || b
|
|
case "and":
|
|
return a && b
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpNumericNumeric(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(float64)
|
|
b := n.(float64)
|
|
return cmpNumberNumberF(op, a, b)
|
|
}
|
|
|
|
func cmpNumericString(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(float64)
|
|
b := n.(string)
|
|
num, err := strconv.ParseFloat(b, 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return cmpNumberNumberF(op, a, num)
|
|
}
|
|
|
|
func cmpNumericNodeSet(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(float64)
|
|
b := n.(query)
|
|
|
|
for {
|
|
node := b.Select(t)
|
|
if node == nil {
|
|
break
|
|
}
|
|
num, err := strconv.ParseFloat(node.Value(), 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if cmpNumberNumberF(op, a, num) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpNodeSetNumeric(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(query)
|
|
b := n.(float64)
|
|
for {
|
|
node := a.Select(t)
|
|
if node == nil {
|
|
break
|
|
}
|
|
num, err := strconv.ParseFloat(node.Value(), 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if cmpNumberNumberF(op, num, b) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpNodeSetString(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(query)
|
|
b := n.(string)
|
|
for {
|
|
node := a.Select(t)
|
|
if node == nil {
|
|
break
|
|
}
|
|
if cmpStringStringF(op, b, node.Value()) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpNodeSetNodeSet(t iterator, op string, m, n interface{}) bool {
|
|
return false
|
|
}
|
|
|
|
func cmpStringNumeric(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(string)
|
|
b := n.(float64)
|
|
num, err := strconv.ParseFloat(a, 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return cmpNumberNumberF(op, b, num)
|
|
}
|
|
|
|
func cmpStringString(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(string)
|
|
b := n.(string)
|
|
return cmpStringStringF(op, a, b)
|
|
}
|
|
|
|
func cmpStringNodeSet(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(string)
|
|
b := n.(query)
|
|
for {
|
|
node := b.Select(t)
|
|
if node == nil {
|
|
break
|
|
}
|
|
if cmpStringStringF(op, a, node.Value()) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func cmpBooleanBoolean(t iterator, op string, m, n interface{}) bool {
|
|
a := m.(bool)
|
|
b := n.(bool)
|
|
return cmpBooleanBooleanF(op, a, b)
|
|
}
|
|
|
|
// eqFunc is an `=` operator.
|
|
func eqFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, "=", m, n)
|
|
}
|
|
|
|
// gtFunc is an `>` operator.
|
|
func gtFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, ">", m, n)
|
|
}
|
|
|
|
// geFunc is an `>=` operator.
|
|
func geFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, ">=", m, n)
|
|
}
|
|
|
|
// ltFunc is an `<` operator.
|
|
func ltFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, "<", m, n)
|
|
}
|
|
|
|
// leFunc is an `<=` operator.
|
|
func leFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, "<=", m, n)
|
|
}
|
|
|
|
// neFunc is an `!=` operator.
|
|
func neFunc(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, "!=", m, n)
|
|
}
|
|
|
|
// orFunc is an `or` operator.
|
|
var orFunc = func(t iterator, m, n interface{}) interface{} {
|
|
t1 := getValueType(m)
|
|
t2 := getValueType(n)
|
|
return logicalFuncs[t1][t2](t, "or", m, n)
|
|
}
|
|
|
|
func numericExpr(m, n interface{}, cb func(float64, float64) float64) float64 {
|
|
typ := reflect.TypeOf(float64(0))
|
|
a := reflect.ValueOf(m).Convert(typ)
|
|
b := reflect.ValueOf(n).Convert(typ)
|
|
return cb(a.Float(), b.Float())
|
|
}
|
|
|
|
// plusFunc is an `+` operator.
|
|
var plusFunc = func(m, n interface{}) interface{} {
|
|
return numericExpr(m, n, func(a, b float64) float64 {
|
|
return a + b
|
|
})
|
|
}
|
|
|
|
// minusFunc is an `-` operator.
|
|
var minusFunc = func(m, n interface{}) interface{} {
|
|
return numericExpr(m, n, func(a, b float64) float64 {
|
|
return a - b
|
|
})
|
|
}
|
|
|
|
// mulFunc is an `*` operator.
|
|
var mulFunc = func(m, n interface{}) interface{} {
|
|
return numericExpr(m, n, func(a, b float64) float64 {
|
|
return a * b
|
|
})
|
|
}
|
|
|
|
// divFunc is an `DIV` operator.
|
|
var divFunc = func(m, n interface{}) interface{} {
|
|
return numericExpr(m, n, func(a, b float64) float64 {
|
|
return a / b
|
|
})
|
|
}
|
|
|
|
// modFunc is an 'MOD' operator.
|
|
var modFunc = func(m, n interface{}) interface{} {
|
|
return numericExpr(m, n, func(a, b float64) float64 {
|
|
return float64(int(a) % int(b))
|
|
})
|
|
}
|