This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #98 from seomoz/amit/ROGER-1238
Generating basic auth file from the nginx permissions file
- Loading branch information
Showing
2 changed files
with
15 additions
and
16 deletions.
There are no files selected for viewing
28 changes: 13 additions & 15 deletions
28
ansible/roles/generate-permission-files/files/generate_nginx_basic_auth_file.py
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,32 +1,30 @@ | ||
#!/usr/bin/python | ||
|
||
from __future__ import print_function | ||
import json | ||
import sys | ||
import htpasswd | ||
import yaml | ||
import os | ||
|
||
def generate_http_basic_auth_file(permissions_file, output_file): | ||
if not permissions_file: | ||
return | ||
permissions = None | ||
permissions = "" | ||
with open(permissions_file) as data_file: | ||
permissions = json.load(data_file) | ||
permissions = yaml.load(data_file) | ||
|
||
if os.path.exists(output_file): | ||
os.remove(output_file) | ||
htpasswd_file = open(output_file, "w") | ||
htpasswd_file.close() | ||
with htpasswd.Basic(output_file) as htpasswd_file: | ||
for permission in permissions["users"]: | ||
username = permission["user"] | ||
password = permission["password"] | ||
print username | ||
print password | ||
htpasswd_file.add(username, password) | ||
|
||
for username in permissions.keys(): | ||
if not username.endswith("_team"): | ||
htpasswd_file.add(username, username) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 3: | ||
sys.exit("Usage: %s <permissions_file> <output_file>" % sys.argv[0]) | ||
permissions_file = sys.argv[1] | ||
output_file = sys.argv[2] | ||
generate_http_basic_auth_file(permissions_file, output_file) | ||
if len(sys.argv) < 3: | ||
sys.exit("Usage: %s <permissions_file> <output_file>" % sys.argv[0]) | ||
permissions_file = sys.argv[1] | ||
output_file = sys.argv[2] | ||
generate_http_basic_auth_file(permissions_file, output_file) |
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