Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #98 from seomoz/amit/ROGER-1238
Browse files Browse the repository at this point in the history
Generating basic auth file from the nginx permissions file
  • Loading branch information
amitbose327 authored Aug 10, 2016
2 parents f2000f4 + ea550b6 commit 103adad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
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)
3 changes: 2 additions & 1 deletion ansible/roles/generate-permission-files/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
- htpasswd
- gspread
- oauth2client
- PyYAML
delegate_to: 127.0.0.1
run_once: yes
tags:
Expand Down Expand Up @@ -119,7 +120,7 @@
- name: Generate nginx basic auth file if generate_basic_auth_file is set && it requires permissions file locally
when: auth_permissions_gspreadsheets is defined and not(auth_permissions_gspreadsheets | trim == '') and
generate_basic_auth_file is defined and generate_basic_auth_file|bool
shell: "{{ creds_dir }}/venv/bin/python {{ role_path }}/files/generate_nginx_basic_auth_file.py {{ creds_dir }}/permissions.json {{ creds_dir }}/{{nginx_basic_auth_file_name}}"
shell: "{{ creds_dir }}/venv/bin/python {{ role_path }}/files/generate_nginx_basic_auth_file.py {{ nginx_auth_permissions_local_path }} {{ creds_dir }}/{{ nginx_basic_auth_file_name }}"
delegate_to: 127.0.0.1
always_run: yes # run during check mode
run_once: yes
Expand Down

0 comments on commit 103adad

Please sign in to comment.