sudo

package
v2.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sudo provides support for various methods of running commands with elevated privileges.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSudo is returned when no supported sudo method is found.
	ErrNoSudo = errors.New("no supported sudo method found")
	// DefaultProvider is the default sudo repository.
	DefaultProvider = sync.OnceValue(func() *Provider {
		provider := NewProvider()
		RegisterWindowsNoop(provider)
		RegisterUID0Noop(provider)
		RegisterSudo(provider)
		RegisterDoas(provider)
		return provider
	})
)

Functions

func Doas

func Doas(cmd string) string

Doas is a DecorateFunc that will wrap the given command in a doas call.

func Noop

func Noop(cmd string) string

Noop is a DecorateFunc that will return the given command unmodified.

func RegisterDoas

func RegisterDoas(repository *Provider)

RegisterDoas registers a doas DecorateFunc with the given repository.

func RegisterSudo

func RegisterSudo(repository *Provider)

RegisterSudo registers a sudo DecorateFunc with the given repository.

func RegisterUID0Noop

func RegisterUID0Noop(repository *Provider)

RegisterUID0Noop registers a noop DecorateFunc with the given repository which can be used when the user is root.

func RegisterWindowsNoop

func RegisterWindowsNoop(repository *Provider)

RegisterWindowsNoop registers a noop DecorateFunc with the given repository if the user is root.

func Sudo

func Sudo(cmd string) string

Sudo is a DecorateFunc that will wrap the given command in a sudo call.

Types

type Factory

type Factory = plumbing.Factory[cmd.Runner, cmd.Runner]

Factory is a factory for sudo runners.

type Provider

type Provider = plumbing.Provider[cmd.Runner, cmd.Runner]

Provider is a repository for sudo runner factories.

func NewProvider

func NewProvider() *Provider

NewProvider returns a new sudo repository.

type Service

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

Service provides a unified interface to interact with different package managers. It ensures that a suitable package manager is lazily initialized and made available for package operations. It supports operations like installation, removal, and updating of packages via the PackageManager interface.

func NewSudoService

func NewSudoService(provider SudoProvider, runner cmd.Runner) *Service

NewSudoService creates a new instance of SudoService with the provided SudoProvider and runner.

func (*Service) GetSudoRunner

func (p *Service) GetSudoRunner() (cmd.Runner, error)

GetSudoRunner returns an cmd.Runner with a sudo decorator or an error if the decorator could not be initialized.

func (*Service) SudoRunner

func (p *Service) SudoRunner() cmd.Runner

SudoRunner returns an cmd.Runner with a sudo decorator. If the runner initialization failed, an error runner is returned which will return the initialization error on every operation that is attempted on it.

type SudoProvider

type SudoProvider interface {
	Get(runner cmd.Runner) (cmd.Runner, error)
}

SudoProvider returns a new cmd.Runner with elevated privileges based on the given runner.

Jump to

Keyboard shortcuts

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