command

package
v1.48.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 1 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 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`

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 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/)

func Sudo

func Sudo() *CommandAsDifferentUser

Sudo will call commands with `sudo`. Similar to NewCommandAsRoot

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