-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from netbox-community/develop
Release 0.23.0
- Loading branch information
Showing
38 changed files
with
742 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ build* | |
docker-compose.override.yml | ||
.netbox/.git* | ||
.netbox/.travis.yml | ||
.netbox/docs | ||
.netbox/scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.22.0 | ||
0.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,23 @@ | ||
from django.contrib.auth.models import Permission, Group, User | ||
from users.models import Token | ||
|
||
from ruamel.yaml import YAML | ||
from pathlib import Path | ||
import sys | ||
|
||
file = Path('/opt/netbox/initializers/users.yml') | ||
if not file.is_file(): | ||
sys.exit() | ||
from django.contrib.auth.models import Group, User | ||
from startup_script_utils import load_yaml, set_permissions | ||
from users.models import Token | ||
|
||
with file.open('r') as stream: | ||
yaml=YAML(typ='safe') | ||
users = yaml.load(stream) | ||
users = load_yaml('/opt/netbox/initializers/users.yml') | ||
if users is None: | ||
sys.exit() | ||
|
||
if users is not None: | ||
for username, user_details in users.items(): | ||
if not User.objects.filter(username=username): | ||
user = User.objects.create_user( | ||
username = username, | ||
password = user_details.get('password', 0) or User.objects.make_random_password) | ||
for username, user_details in users.items(): | ||
if not User.objects.filter(username=username): | ||
user = User.objects.create_user( | ||
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']) | ||
if user_details.get('api_token', 0): | ||
Token.objects.create(user=user, key=user_details['api_token']) | ||
|
||
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) | ||
yaml_permissions = user_details.get('permissions', []) | ||
set_permissions(user.user_permissions, yaml_permissions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
from django.contrib.auth.models import Permission, Group, User | ||
from ruamel.yaml import YAML | ||
from pathlib import Path | ||
import sys | ||
|
||
file = Path('/opt/netbox/initializers/groups.yml') | ||
if not file.is_file(): | ||
sys.exit() | ||
|
||
with file.open('r') as stream: | ||
yaml=YAML(typ='safe') | ||
groups = yaml.load(stream) | ||
from django.contrib.auth.models import Group, User | ||
from startup_script_utils import load_yaml, set_permissions | ||
|
||
if groups is not None: | ||
for groupname, group_details in groups.items(): | ||
group, created = Group.objects.get_or_create(name=groupname) | ||
groups = load_yaml('/opt/netbox/initializers/groups.yml') | ||
if groups is None: | ||
sys.exit() | ||
|
||
if created: | ||
print("👥 Created group", groupname) | ||
for groupname, group_details in groups.items(): | ||
group, created = Group.objects.get_or_create(name=groupname) | ||
|
||
for username in group_details.get('users', []): | ||
user = User.objects.get(username=username) | ||
if created: | ||
print("👥 Created group", groupname) | ||
|
||
if user: | ||
user.groups.add(group) | ||
for username in group_details.get('users', []): | ||
user = User.objects.get(username=username) | ||
|
||
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) | ||
if user: | ||
user.groups.add(group) | ||
|
||
for permission in permissions: | ||
subject.add(permission) | ||
yaml_permissions = group_details.get('permissions', []) | ||
set_permissions(group.permissions, yaml_permissions) |
Oops, something went wrong.