Documentation ¶
Overview ¶
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- func AddGroup(ctx context.Context, groupName string) error
- func AddUser(ctx context.Context, username, fullname, password string) error
- func AssociateUserToGroup(ctx context.Context, username, groupName string) error
- func BootTime() (bootime time.Time, err error)
- func ConvertError(err error) error
- func ConvertUserGroupError(err error) error
- func DefineSudoCommand(args ...string)
- func DefineUser(ctx context.Context, user *user.User, password string) (err error)
- func DeleteUser(ctx context.Context, user *user.User) (err error)
- func DissociateUserFromGroup(ctx context.Context, username, groupName string) error
- func HasGroup(groupName string) (found bool, err error)
- func HasUser(username string) (found bool, err error)
- func Hostname() (string, error)
- func IsAdmin(username string) (admin bool, err error)
- func IsCurrentUserAnAdmin() (admin bool, err error)
- func IsUserAdmin(user *user.User) (admin bool, err error)
- func IsWindows() bool
- func LineSeparator() string
- func NodeName() (nodename string, err error)
- func PlatformInformation() (information string, err error)
- func RemoveGroup(ctx context.Context, groupName string) error
- func RemoveUser(ctx context.Context, username string) error
- func RemoveWithPrivileges(ctx context.Context, path string) (err error)
- func SystemInformation() (information string, err error)
- func Uname() (string, error)
- func UnixLineSeparator() string
- func UpTime() (uptime time.Duration, err error)
- func WithPrivileges(cmd *command.CommandAsDifferentUser) (cmdWithPrivileges *command.CommandAsDifferentUser)
- type RAM
- type VirtualMemory
Constants ¶
const ( RootGroup = "root" SudoersGroup = "sudo" )
Variables ¶
This section is empty.
Functions ¶
func AssociateUserToGroup ¶ added in v1.44.0
AssociateUserToGroup adds a user to a group.
func ConvertError ¶ added in v1.18.0
ConvertError converts a platform error into a commonerrors
func ConvertUserGroupError ¶ added in v1.44.0
ConvertUserGroupError converts errors related to users in common errors.
func DefineSudoCommand ¶ added in v1.44.0
func DefineSudoCommand(args ...string)
DefineSudoCommand defines the command to run to be `root` or a user with enough privileges (superuser). e.g.
- args="sudo" to run commands as `root`
- args="su", "tom" if `tom` has enough privileges to run the command
func DefineUser ¶ added in v1.44.0
DefineUser adds a new user to the platform
func DeleteUser ¶ added in v1.44.0
DeleteUser removes a user from the platform when the user is specified using a `user.User` structure.
func DissociateUserFromGroup ¶ added in v1.44.1
DissociateUserFromGroup removes a user from a group.
func IsCurrentUserAnAdmin ¶ added in v1.49.0
IsCurrentUserAnAdmin states whether the current user is a superuser or not.
func IsUserAdmin ¶ added in v1.49.0
IsUserAdmin states whether the user is a superuser or not. Similar to IsAdmin but may use more checks.
func PlatformInformation ¶
PlatformInformation returns the platform information (equivalent to uname -s).
func RemoveGroup ¶ added in v1.44.0
RemoveGroup removes a group from the platform
func RemoveUser ¶ added in v1.44.0
RemoveUser removes a user from the platform when only the username is known.
func RemoveWithPrivileges ¶ added in v1.50.0
RemoveWithPrivileges removes a directory even if it is not owned by user (equivalent to sudo rm -rf). It expects the current user to be a superuser.
func SystemInformation ¶
SystemInformation returns the system information (equivalent to uname -a)
func UnixLineSeparator ¶ added in v1.1.0
func UnixLineSeparator() string
UnixLineSeparator returns the line separator on Unix platform.
func WithPrivileges ¶ added in v1.49.0
func WithPrivileges(cmd *command.CommandAsDifferentUser) (cmdWithPrivileges *command.CommandAsDifferentUser)
WithPrivileges redefines a command so that it is run with elevated privileges. For instance, on Linux, if the current user has enough privileges, the command will be run as is. Otherwise, `sudo` will be used if defined as the sudo (See `DefineSudoCommand`). Similar scenario will happen on Windows, although the elevated command is defined using `DefineSudoCommand`.
Types ¶
type RAM ¶
type RAM interface { // GetTotal returns total amount of RAM on this system GetTotal() uint64 // GetAvailable returns RAM available for programs to allocate GetAvailable() uint64 // GetUsed returns RAM used by programs GetUsed() uint64 // GetUsedPercent returns Percentage of RAM used by programs GetUsedPercent() float64 // GetFree returns kernel's notion of free memory GetFree() uint64 }
type VirtualMemory ¶
type VirtualMemory struct { Total uint64 Available uint64 Used uint64 UsedPercent float64 Free uint64 }
func (*VirtualMemory) GetAvailable ¶
func (m *VirtualMemory) GetAvailable() uint64
func (*VirtualMemory) GetFree ¶
func (m *VirtualMemory) GetFree() uint64
func (*VirtualMemory) GetTotal ¶
func (m *VirtualMemory) GetTotal() uint64
func (*VirtualMemory) GetUsed ¶
func (m *VirtualMemory) GetUsed() uint64
func (*VirtualMemory) GetUsedPercent ¶
func (m *VirtualMemory) GetUsedPercent() float64