github.com/hashicorp/packer@v1.14.3/provisioner/powershell/execution_policy.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  //go:generate enumer -transform snake -trimprefix ExecutionPolicy -type ExecutionPolicy
     5  
     6  package powershell
     7  
     8  import (
     9  	"reflect"
    10  	"strconv"
    11  )
    12  
    13  // ExecutionPolicy setting to run the command(s).
    14  // For the powershell provider the default has historically been to bypass.
    15  type ExecutionPolicy int
    16  
    17  const (
    18  	ExecutionPolicyBypass ExecutionPolicy = iota
    19  	ExecutionPolicyAllsigned
    20  	ExecutionPolicyDefault
    21  	ExecutionPolicyRemotesigned
    22  	ExecutionPolicyRestricted
    23  	ExecutionPolicyUndefined
    24  	ExecutionPolicyUnrestricted
    25  	ExecutionPolicyNone // not set
    26  )
    27  
    28  func StringToExecutionPolicyHook(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) {
    29  	if f != reflect.String || t != reflect.Int {
    30  		return data, nil
    31  	}
    32  
    33  	raw := data.(string)
    34  	// It's possible that the thing being read is not supposed to be an
    35  	// execution policy; if the string provided is actally an int, just return
    36  	// the int.
    37  	i, err := strconv.Atoi(raw)
    38  	if err == nil {
    39  		return i, nil
    40  	}
    41  	// If it can't just be cast to an int, try to parse string into an
    42  	// execution policy.
    43  	return ExecutionPolicyString(raw)
    44  }