polkit

package module
v0.0.0-...-ee6a518 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 1 Imported by: 3

README

go-polkit

PolKit client library and CLI for golang.

CLI Installation

$ cd $GOPATH/src/github.com/amenzhinsky/go-polkit
$ go install 

CLI Usage

List all PolKit actions:

$ pkquery -verbose

View particular actions:

$ pkquery -verbose org.freedesktop.udisks2.filesystem-fstab org.freedesktop.udisks2.filesystem-mount

Check access to an action:

$ pkquery -check-access org.freedesktop.udisks2.filesystem-fstab

Check access and allow user to interact by typing his password when PolKit requires it:

$ pkquery -check-access -allow-password org.freedesktop.udisks2.filesystem-fstab

Library Usage

Authorization checking
authority, err := polkit.NewAuthority()
if err != nil {
	panic(err)
}

result, err := authority.CheckAuthorization(
	"org.freedesktop.udisks2.filesystem-fstab",
	nil,
	polkit.CheckAuthorizationAllowUserInteraction, "",
)

if err != nil {
	panic(err)
}

fmt.Printf("Is authorized: %t\n", result.IsAuthorized)
fmt.Printf("Is challenge:  %t\n", result.IsChallenge)
fmt.Printf("Details:       %v\n", result.Details)
Actions Enumerating
authority, err := polkit.NewAuthority()
if err != nil {
	panic(err)
}

actions, err := authority.EnumerateActions("")
if err != nil {
	panic(err)
}

for _, action := range actions {
	fmt.Println(action.ActionID)
}

Documentation

Index

Constants

View Source
const (
	CheckAuthorizationNone uint32 = iota
	CheckAuthorizationAllowUserInteraction
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authority

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

func NewAuthority

func NewAuthority() (*Authority, error)

func (*Authority) CancelCheckAuthorization

func (a *Authority) CancelCheckAuthorization(cancellationID string) error

func (*Authority) CheckAuthorization

func (a *Authority) CheckAuthorization(
	actionID string,
	details map[string]string,
	flags uint32,
	cancellationID string) (*PKAuthorizationResult, error)

func (*Authority) Close

func (a *Authority) Close() error

func (*Authority) EnumerateActions

func (a *Authority) EnumerateActions(locale string) ([]PKActionDescription, error)

type PKActionDescription

type PKActionDescription struct {
	ActionID         string            `dbus:"action_id"`
	Description      string            `dbus:"description"`
	Message          string            `dbus:"message"`
	VendorName       string            `dbus:"vendor_name"`
	VendorURL        string            `dbus:"vendor_url"`
	IconName         string            `dbus:"icon_name"`
	ImplicitAny      uint32            `dbus:"implicit_any"`
	ImplicitInactive uint32            `dbus:"implicit_inactive"`
	ImplicitActive   uint32            `dbus:"implicit_active"`
	Annotations      map[string]string `dbus:"annotations"`
}

type PKAuthorizationResult

type PKAuthorizationResult struct {
	IsAuthorized bool              `dbus:"is_authorized"`
	IsChallenge  bool              `dbus:"is_challenge"`
	Details      map[string]string `dbus:"details"`
}

type PKImplicitAuthorization

type PKImplicitAuthorization uint32
const (
	NotAuthorized PKImplicitAuthorization = iota
	AuthenticationRequired
	AdministratorAuthenticationRequired
	AuthenticationRequiredRetained
	AdministratorAuthenticationRequiredRetained
	Authorized
)

func (PKImplicitAuthorization) String

func (i PKImplicitAuthorization) String() string

type PKSubject

type PKSubject struct {
	Kind    string                  `dbus:"subject_kind"`
	Details map[string]dbus.Variant `dbus:"subject_details"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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