Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/python/example_approval_plugin.py
1532 views
1
import sudo
2
3
from datetime import datetime
4
5
6
class BusinessHoursApprovalPlugin(sudo.Plugin):
7
def check(self, command_info: tuple, run_argv: tuple,
8
run_env: tuple) -> int:
9
error_msg = ""
10
now = datetime.now()
11
if now.weekday() >= 5:
12
error_msg = "That is not allowed on the weekend!"
13
if now.hour < 8 or now.hour > 17:
14
error_msg = "That is not allowed outside the business hours!"
15
16
if error_msg:
17
sudo.log_info(error_msg)
18
raise sudo.PluginReject(error_msg)
19
20