idm

Base module IDM related classes and functions.

exception wmflib.idm.IdmValueError[source]

Bases: WmflibError

Raised by the IDM module value errors.

wmflib.idm.logoutd_args(description: str | None = None, args: List | None = None) Namespace[source]

Logout scripts common CLI for parsing the command line arguments.

When not using the higher level API wmflib.idm.LogoutdBase, a user could just implement their own script still using the same command line arguments processing, of the form:

from wmflib.idm import logoutd_args
args = logoutd_args('Some description')
# write your own script
Parameters:
  • description (str) – the description to use

  • args (list) – A list of arguments to use (used for testing)

Returns:

The parsed argparser Namespace

Return type:

argparse.Namespace

class wmflib.idm.LogoutdBase(args: List | None = None)[source]

Bases: ABC

abstract Base class for a standardized API for logout scripts.

A simple logout.d python script would then be of the form:

from wmflib.idm import LogoutdBase

class MyLogoutd(LogoutdBase):
    """Some description."""

    def logout_user(self, user):
        # logout the given user

    def query_user(self, user):
        # check the login status of a given user

    def list(self):
        # list all active login sessions

logoutd = MyLogoutd()
raise SystemExit(logoutd.run())  # This includes the parsing of command line arguments.

abstract Init function.

Parameters:

args (list) – A list of arguments to use (used for testing)

property user: str

Return either common_name or uid with a preference for common_name.

Returns:

representing the user

Return type:

(str)

abstract logout_user(user: str) int[source]

abstract Log out the specified user.

Parameters:

user (User) – object representing the user

Returns:

0 if the users session was successfully cleared otherwise 1

Return type:

(int)

abstract query_user(user: str) int[source]

abstract Return status of logged in user.

Parameters:

user (User) – object representing the user

Returns:

1 if the user is logged in otherwise 0

Return type:

(int)

abstract list() int[source]

abstract Return data of all logged in users.

Returns:

0 on success non-zero on fail

Return type:

(int)

run() int[source]

Execute the correct action.

Returns:

exit code depends on command

Return type:

(int)