Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to specify tunnel type, tunnel medium type en assigned vlan to new radius users #74

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ Gets the current state & configuration of the given device based on its MAC Addr
### `get_radius_users(self)`
Returns a list of all RADIUS users, name, password, 24 digit user id, and 24 digit site id.

### `add_radius_user(self, name, password)`
### `add_radius_user(self, name, password, tunnel_type, tunnel_medium_type, vlan)`
Add a new RADIUS user with this username and password.

- `name` -- the new user's username
- `password` -- the new user's password
- `tunnel_type` -- optional, new user's tunnel type, must be in range 1-13
- `tunnel_medium_type` -- optional, new user's tunnel medium type, must be in range 1-15
- `vlan` -- optional, new user's assigned vlan

### `update_radius_user(self, name, password, id)`
Update a RADIUS user to this new username and password.
Expand Down
24 changes: 23 additions & 1 deletion pyunifi/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,35 @@ def get_radius_users(self):
"""
return self._api_read('rest/account')

def add_radius_user(self, name, password):
def add_radius_user(self, name, password, tunnel_type = None, tunnel_medium_type = None, vlan = None):
"""Add a new user with this username and password
:param name: new user's username
:param password: new user's password
:param tunnel_type: optional, new user's tunnel type,
must be in range 1-13
:param tunnel_medium_type: optional, new user's tunnel medium type,
must be in range 1-15
:param vlan: optional, new user's assigned vlan
:returns: user's name, password, 24 digit user id, and 24 digit site id
"""
tunnel_type_values = [None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
tunnel_medium_type_values = [None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

if (tunnel_type not in tunnel_type_values or tunnel_medium_type not in tunnel_medium_type_values
or (tunnel_type is None and tunnel_medium_type is not None or tunnel_type is not None and tunnel_medium_type is None)):
raise APIError("Invalid tunnel ('{}') or tunnel medium ('{}') type".format(tunnel_type, tunnel_medium_type))

params = {'name': name, 'x_password': password}

if tunnel_type is not None:
params['tunnel_type'] = tunnel_type

if tunnel_medium_type is not None:
params['tunnel_medium_type'] = tunnel_medium_type

if vlan is not None:
params['vlan'] = vlan

return self._api_write('rest/account/', params)

def update_radius_user(self, name, password, user_id):
Expand Down