Skip to content

Commit

Permalink
Merge pull request #239 from netbox-community/develop
Browse files Browse the repository at this point in the history
Release 0.22.0
  • Loading branch information
cimnine authored Feb 8, 2020
2 parents b0b20aa + c5822b9 commit 80f514f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches-ignore:
- release
pull_request:
branches-ignore:
- release

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21.1
0.22.0
3 changes: 1 addition & 2 deletions configuration/ldap_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def import_group_type(group_type_name):
AUTH_LDAP_FIND_GROUP_PERMS = os.environ.get('AUTH_LDAP_FIND_GROUP_PERMS', 'True').lower() == 'true'

# Cache groups for one hour to reduce LDAP traffic
AUTH_LDAP_CACHE_GROUPS = os.environ.get('AUTH_LDAP_CACHE_GROUPS', 'True').lower() == 'true'
AUTH_LDAP_GROUP_CACHE_TIMEOUT = int(os.environ.get('AUTH_LDAP_GROUP_CACHE_TIMEOUT', 3600))
AUTH_LDAP_CACHE_TIMEOUT = int(os.environ.get('AUTH_LDAP_CACHE_TIMEOUT', 3600))

# Populate the Django user from the LDAP directory.
AUTH_LDAP_USER_ATTR_MAP = {
Expand Down
27 changes: 23 additions & 4 deletions initializers/groups.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## To list all permissions, run:
##
## docker-compose run --rm --entrypoint /bin/bash netbox
## $ ./manage.py migrate
## $ ./manage.py shell
## > from django.contrib.auth.models import Permission
## > print('\n'.join([p.codename for p in Permission.objects.all()]))
##
## Permission lists support wildcards. See the examples below.
##
## Examples:

# applications:
# users:
# - technical_user
Expand All @@ -8,9 +20,16 @@
# users:
# - writer
# permissions:
# - add_device
# - change_device
# - delete_device
# - add_virtualmachine
# - change_virtualmachine
# - delete_virtualmachine
# - add_*
# - change_*
# vm_managers:
# permissions:
# - '*_virtualmachine'
# device_managers:
# permissions:
# - '*device*'
# creators:
# permissions:
# - add_*
18 changes: 14 additions & 4 deletions initializers/users.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
## To list all permissions, run:
##
## docker-compose run --rm --entrypoint /bin/bash netbox
## $ ./manage.py migrate
## $ ./manage.py shell
## > from django.contrib.auth.models import Permission
## > print('\n'.join([p.codename for p in Permission.objects.all()]))
##
## Permission lists support wildcards. See the examples below.
##
## Examples:

# technical_user:
# api_token: 0123456789technicaluser789abcdef01234567 # must be looooong!
# reader:
# password: reader
# writer:
# password: writer
# permissions:
# - add_device
# - change_device
# - delete_device
# - add_virtualmachine
# - change_virtualmachine
# - delete_virtualmachine
# - add_*
# - change_*
24 changes: 16 additions & 8 deletions startup_scripts/000_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@
username = username,
password = user_details.get('password', 0) or User.objects.make_random_password)

print("👤 Created user ",username)
print("👤 Created user",username)

if user_details.get('api_token', 0):
Token.objects.create(user=user, key=user_details['api_token'])

user_permissions = user_details.get('permissions', [])
if user_permissions:
user.user_permissions.clear()
for permission_codename in user_details.get('permissions', []):
for permission in Permission.objects.filter(codename=permission_codename):
user.user_permissions.add(permission)
user.save()
yaml_permissions = user_details.get('permissions', [])
if yaml_permissions:
subject = user.user_permissions
subject.clear()
for yaml_permission in yaml_permissions:
if '*' in yaml_permission:
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
permissions = Permission.objects.filter(codename__iregex=permission_filter)
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
else:
permissions = Permission.objects.filter(codename=yaml_permission)
print(" ⚿ Granting permission", yaml_permission)

for permission in permissions:
subject.add(permission)
21 changes: 15 additions & 6 deletions startup_scripts/010_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@
if user:
user.groups.add(group)

group_permissions = group_details.get('permissions', [])
if group_permissions:
group.permissions.clear()
for permission_codename in group_details.get('permissions', []):
for permission in Permission.objects.filter(codename=permission_codename):
group.permissions.add(permission)
yaml_permissions = group_details.get('permissions', [])
if yaml_permissions:
subject = group.permissions
subject.clear()
for yaml_permission in yaml_permissions:
if '*' in yaml_permission:
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
permissions = Permission.objects.filter(codename__iregex=permission_filter)
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
else:
permissions = Permission.objects.filter(codename=yaml_permission)
print(" ⚿ Granting permission", yaml_permission)

for permission in permissions:
subject.add(permission)
14 changes: 7 additions & 7 deletions startup_scripts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
this_dir = dirname(abspath(__file__))

def filename(f):
return f.name
return f.name

with scandir(dirname(abspath(__file__))) as it:
for f in sorted(it, key = filename):
if f.name.startswith('__') or not f.is_file():
continue
print(f"Running {f.path}")
runpy.run_path(f.path)
for f in sorted(it, key = filename):
if f.name.startswith('__') or not f.is_file():
continue

print(f"Running {f.path}")
runpy.run_path(f.path)

0 comments on commit 80f514f

Please sign in to comment.