Python

Loads dynamic users by calling a local Python script.

When Python is used as the source, the on-disk group cache is written in JSON format.

The following variables are defined when the script is executed:

  • __file__

    Absolute path of the script file

    Added in version 1.11.0.

When configured as a map, the following keys are supported:

  • script

    required, type: file path

    Path to the Python script.

    Three global functions should be defined in this script, like this:

    def fetch_users():
        # required, takes no argument, returns the JSON string
        return "[]"
    
    def report_ok():
        # optional, takes no argument
        pass
    
    def report_err(errmsg):
        # optional, takes one positional argument, which is the error message string
        pass
    
  • fetch_timeout

    optional, type: humanize duration

    Timeout for running the fetch function.

    It is not recommended to set this value greater than refresh_interval in group config.

    default: 30s

  • report_timeout

    optional, type: humanize duration

    Timeout for running the report functions.

    It is not recommended to set this value greater than refresh_interval in group config.

    default: 15s

Example

source:
  type: python
  script: fetch_users.py
  fetch_timeout: 10s
  report_timeout: 5s