Avoid using typing annotations so tests run with Python 3.4.
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import sudo
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
class BusinessHoursApprovalPlugin(sudo.Plugin):
|
||||
def check(self, command_info: Tuple[str, ...], run_argv: Tuple[str, ...],
|
||||
run_env: Tuple[str, ...]) -> int:
|
||||
def check(self, command_info: tuple, run_argv: tuple,
|
||||
run_env: tuple) -> int:
|
||||
error_msg = ""
|
||||
now = datetime.now()
|
||||
if now.weekday() >= 5:
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import sudo
|
||||
|
||||
import os
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
VERSION = 1.0
|
||||
@@ -22,7 +21,7 @@ class SudoAuditPlugin(sudo.Plugin):
|
||||
def __del__(self):
|
||||
self._log("-- Finished --")
|
||||
|
||||
def open(self, submit_optind: int, submit_argv: Tuple[str, ...]) -> int:
|
||||
def open(self, submit_optind: int, submit_argv: tuple) -> int:
|
||||
# To cut out the sudo options, use "submit_optind":
|
||||
program_args = submit_argv[submit_optind:]
|
||||
if program_args:
|
||||
|
@@ -1,7 +1,5 @@
|
||||
import sudo
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
class SudoGroupPlugin(sudo.Plugin):
|
||||
"""Example sudo input/output plugin
|
||||
@@ -32,7 +30,7 @@ class SudoGroupPlugin(sudo.Plugin):
|
||||
"""
|
||||
|
||||
# -- Plugin API functions --
|
||||
def query(self, user: str, group: str, user_pwd: Tuple):
|
||||
def query(self, user: str, group: str, user_pwd: tuple):
|
||||
"""Query if user is part of the specified group.
|
||||
|
||||
Beware that user_pwd can be None if user is not present in the password
|
||||
|
@@ -5,7 +5,6 @@ import errno
|
||||
import signal
|
||||
import sys
|
||||
import json
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
VERSION = 1.0
|
||||
@@ -15,9 +14,7 @@ class SudoIOPlugin(sudo.Plugin):
|
||||
"""Example sudo input/output plugin
|
||||
|
||||
Demonstrates how to use the sudo IO plugin API. All functions are added as
|
||||
an example on their syntax, but note that all of them are optional. Also
|
||||
typing annotations are just here for the help on the syntax (requires
|
||||
python >= 3.5).
|
||||
an example on their syntax, but note that all of them are optional.
|
||||
|
||||
On detailed description of the functions refer to sudo_plugin manual (man
|
||||
sudo_plugin).
|
||||
@@ -44,13 +41,13 @@ class SudoIOPlugin(sudo.Plugin):
|
||||
# -- Plugin API functions --
|
||||
|
||||
def __init__(self, version: str,
|
||||
plugin_options: Tuple[str, ...], **kwargs):
|
||||
plugin_options: tuple, **kwargs):
|
||||
"""The constructor of the IO plugin.
|
||||
|
||||
Other variables you can currently use as arguments are:
|
||||
user_env: Tuple[str, ...]
|
||||
settings: Tuple[str, ...]
|
||||
user_info: Tuple[str, ...]
|
||||
user_env: tuple
|
||||
settings: tuple
|
||||
user_info: tuple
|
||||
|
||||
For their detailed description, see the open() call of the C plugin API
|
||||
in the sudo manual ("man sudo").
|
||||
@@ -72,8 +69,8 @@ class SudoIOPlugin(sudo.Plugin):
|
||||
self._log("", "-- Plugin DESTROYED --")
|
||||
self._log_file.close()
|
||||
|
||||
def open(self, argv: Tuple[str, ...],
|
||||
command_info: Tuple[str, ...]) -> int:
|
||||
def open(self, argv: tuple,
|
||||
command_info: tuple) -> int:
|
||||
"""Receives the command the user wishes to run.
|
||||
|
||||
This function works the same as open() call of the C IO plugin API (see
|
||||
|
@@ -6,7 +6,6 @@ import os
|
||||
import pwd
|
||||
import grp
|
||||
import shutil
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
VERSION = 1.0
|
||||
@@ -17,8 +16,7 @@ class SudoPolicyPlugin(sudo.Plugin):
|
||||
|
||||
Demonstrates how to use the sudo policy plugin API. All functions are added
|
||||
as an example on their syntax, but note that most of them are optional
|
||||
(except check_policy). Also typing annotations are just here for the help
|
||||
on the syntax (requires python >= 3.5).
|
||||
(except check_policy).
|
||||
|
||||
On detailed description of the functions refer to sudo_plugin manual (man
|
||||
sudo_plugin).
|
||||
@@ -47,13 +45,13 @@ class SudoPolicyPlugin(sudo.Plugin):
|
||||
|
||||
# -- Plugin API functions --
|
||||
|
||||
def __init__(self, user_env: Tuple[str, ...], settings: Tuple[str, ...],
|
||||
def __init__(self, user_env: tuple, settings: tuple,
|
||||
version: str, **kwargs):
|
||||
"""The constructor matches the C sudo plugin API open() call
|
||||
|
||||
Other variables you can currently use as arguments are:
|
||||
user_info: Tuple[str, ...]
|
||||
plugin_options: Tuple[str, ...]
|
||||
user_info: tuple
|
||||
plugin_options: tuple
|
||||
|
||||
For their detailed description, see the open() call of the C plugin API
|
||||
in the sudo manual ("man sudo").
|
||||
@@ -66,7 +64,7 @@ class SudoPolicyPlugin(sudo.Plugin):
|
||||
self.user_env = sudo.options_as_dict(user_env)
|
||||
self.settings = sudo.options_as_dict(settings)
|
||||
|
||||
def check_policy(self, argv: Tuple[str, ...], env_add: Tuple[str, ...]):
|
||||
def check_policy(self, argv: tuple, env_add: tuple):
|
||||
cmd = argv[0]
|
||||
# Example for a simple reject:
|
||||
if not self._is_command_allowed(cmd):
|
||||
@@ -86,7 +84,7 @@ class SudoPolicyPlugin(sudo.Plugin):
|
||||
|
||||
return (sudo.RC.ACCEPT, command_info_out, argv, user_env_out)
|
||||
|
||||
def init_session(self, user_pwd: Tuple, user_env: Tuple[str, ...]):
|
||||
def init_session(self, user_pwd: tuple, user_env: tuple):
|
||||
"""Perform session setup
|
||||
|
||||
Beware that user_pwd can be None if user is not present in the password
|
||||
@@ -101,7 +99,7 @@ class SudoPolicyPlugin(sudo.Plugin):
|
||||
# If you do not want to change user_env, you can just return (or None):
|
||||
# return sudo.RC.OK
|
||||
|
||||
def list(self, argv: Tuple[str, ...], is_verbose: int, user: str):
|
||||
def list(self, argv: tuple, is_verbose: int, user: str):
|
||||
cmd = argv[0] if argv else None
|
||||
as_user_text = "as user '{}'".format(user) if user else ""
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
Example sudo python plugin will log to /some/not/writable/directory/sudo.log
|
||||
Traceback:
|
||||
File "SRC_DIR/example_io_plugin.py", line 67, in __init__
|
||||
File "SRC_DIR/example_io_plugin.py", line 64, in __init__
|
||||
self._open_log_file(path.join(log_path, "sudo.log"))
|
||||
File "SRC_DIR/example_io_plugin.py", line 140, in _open_log_file
|
||||
File "SRC_DIR/example_io_plugin.py", line 137, in _open_log_file
|
||||
self._log_file = open(log_path, "a")
|
||||
|
||||
|
Reference in New Issue
Block a user