30 lines
979 B
Go
30 lines
979 B
Go
//go:build !windows
|
|
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
func unsupportedElevation(action string) (ElevationResult, error) {
|
|
return ElevationResult{Action: action}, fmt.Errorf("elevated actions are a Windows feature (current OS: %s)", runtime.GOOS)
|
|
}
|
|
|
|
// ExecuteElevatedAction runs a whitelisted action in the current process.
|
|
func ExecuteElevatedAction(_ context.Context, action, _ string) (ElevationResult, error) {
|
|
if _, ok := LookupElevationAction(action); !ok {
|
|
return ElevationResult{Action: action}, fmt.Errorf("unsupported elevation action %q", action)
|
|
}
|
|
return unsupportedElevation(action)
|
|
}
|
|
|
|
// RunElevatedAction starts the elevated helper and waits for its result.
|
|
func RunElevatedAction(_ context.Context, _, action, _ string) (ElevationResult, error) {
|
|
if _, ok := LookupElevationAction(action); !ok {
|
|
return ElevationResult{Action: action}, fmt.Errorf("unsupported elevation action %q", action)
|
|
}
|
|
return unsupportedElevation(action)
|
|
}
|