2019-05-27 08:52:04 -04:00
|
|
|
//go:generate enumer -transform snake -trimprefix ExecutionPolicy -type ExecutionPolicy
|
|
|
|
|
2019-05-23 08:10:41 -04:00
|
|
|
package powershell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2020-04-07 04:32:58 -04:00
|
|
|
"strconv"
|
2019-05-23 08:10:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExecutionPolicy setting to run the command(s).
|
|
|
|
// For the powershell provider the default has historically been to bypass.
|
|
|
|
type ExecutionPolicy int
|
|
|
|
|
|
|
|
const (
|
2019-05-23 11:05:37 -04:00
|
|
|
ExecutionPolicyBypass ExecutionPolicy = iota
|
|
|
|
ExecutionPolicyAllsigned
|
|
|
|
ExecutionPolicyDefault
|
|
|
|
ExecutionPolicyRemotesigned
|
|
|
|
ExecutionPolicyRestricted
|
|
|
|
ExecutionPolicyUndefined
|
|
|
|
ExecutionPolicyUnrestricted
|
|
|
|
ExecutionPolicyNone // not set
|
2019-05-23 08:10:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func StringToExecutionPolicyHook(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) {
|
|
|
|
if f != reflect.String || t != reflect.Int {
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
raw := data.(string)
|
2020-04-07 04:32:58 -04:00
|
|
|
// It's possible that the thing being read is not supposed to be an
|
|
|
|
// execution policy; if the string provided is actally an int, just return
|
|
|
|
// the int.
|
|
|
|
i, err := strconv.Atoi(raw)
|
|
|
|
if err == nil {
|
|
|
|
return i, nil
|
|
|
|
}
|
|
|
|
// If it can't just be cast to an int, try to parse string into an
|
|
|
|
// execution policy.
|
2019-05-23 08:10:41 -04:00
|
|
|
return ExecutionPolicyString(raw)
|
|
|
|
}
|