command

package
v1.62.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsShellForm

func AsShellForm(cmd string, args ...string) string

AsShellForm returns a command in its shell form.

Types

type CommandAsDifferentUser

type CommandAsDifferentUser struct {
	// contains filtered or unexported fields
}

CommandAsDifferentUser helps redefining commands so that they are run as a different user or with more privileges.

func Elevate added in v1.49.0

func Elevate() *CommandAsDifferentUser

Elevate will call commands with [elevate](https://learn.microsoft.com/en-us/previous-versions/technet-magazine/cc162321(v=msdn.10)) assuming the tool is installed on the platform. (For WINDOWS only)

func Gosu

func Gosu(username string) *CommandAsDifferentUser

Gosu is similar to NewCommandInContainerAs.

func Me

Me will run the commands without switching user. It is a no operation wrapper.

func NewCommandAsDifferentUser

func NewCommandAsDifferentUser(switchUserCmd ...string) *CommandAsDifferentUser

NewCommandAsDifferentUser defines a command wrapper which helps redefining commands so that they are run as a different user. e.g.

  • switchUserCmd="sudo" to run commands as `root`
  • switchUserCmd="su", "tom" if `tom` has enough privileges to run the command
  • switchUserCmd="gosu", "tom" if `tom` has enough privileges to run the command in a container and `gosu` is installed

func NewCommandAsRoot

func NewCommandAsRoot() *CommandAsDifferentUser

NewCommandAsRoot will create a command translator which will run command with `sudo` (for Unix Only)

func NewCommandInContainerAs

func NewCommandInContainerAs(username string) *CommandAsDifferentUser

NewCommandInContainerAs will redefine commands to be run in containers as `username`. It will expect [gosu](https://github.com/tianon/gosu) to be installed and the user to have been defined.

func RunAs added in v1.49.0

func RunAs(username string) *CommandAsDifferentUser

RunAs will run commands as the user username using [runas](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc771525%28v=ws.11%29) (For WINDOWS only)

func ShellRunAs added in v1.49.0

func ShellRunAs() *CommandAsDifferentUser

ShellRunAs will call commands with [shellrunas](https://learn.microsoft.com/en-gb/sysinternals/downloads/shellrunas) assuming [SysInternals](https://docs.microsoft.com/en-gb/sysinternals/downloads/sysinternals-suite) is installed on the platform. (For WINDOWS only)

func Su

func Su(username string) *CommandAsDifferentUser

Su will run commands as the user username using [su](https://www.unix.com/man-page/posix/1/su/) (for Unix Only)

func Sudo

func Sudo() *CommandAsDifferentUser

Sudo will call commands with `sudo`. Similar to NewCommandAsRoot (for Unix Only)

func (*CommandAsDifferentUser) Prepend added in v1.49.0

Prepend prepends a command translator to this command translator This can be used to run command as a separate user and with higher privileges e.g. `sudo`. It returns this for use in fluent expressions e.g. Gosu(...).Prepend(Sudo()).RedefineInShellForm(...)

func (*CommandAsDifferentUser) Redefine

func (c *CommandAsDifferentUser) Redefine(cmd string, args ...string) (cmdName string, cmdArgs []string)

Redefine redefines a command so that it will be run as a different user.

func (*CommandAsDifferentUser) RedefineCommand

func (c *CommandAsDifferentUser) RedefineCommand(args ...string) (cmdName string, cmdArgs []string)

RedefineCommand is the same as Redefine but with no separation between the command and its arguments (like the command in Docker)

func (*CommandAsDifferentUser) RedefineInShellForm

func (c *CommandAsDifferentUser) RedefineInShellForm(cmd string, args ...string) string

RedefineInShellForm returns the new command defined in shell form.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL