Skip to content

Commit 54bd8d9

Browse files
committed
make it possible to load password inventory from external file
1 parent 02ced9b commit 54bd8d9

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte
3232
* Sign generated generated and javascript files used in encrypted pages to make it more tamper proof
3333
* ~~Add check for latin1 encoding in passwords, as it pycryptodome's implementation of PBKDF2 requires it~~
3434
* ~~find an equivalent way to define multiple passwords in the password inventory as global password~~
35-
* make it possible to define passwords in external yaml file(s)
35+
* ~~make it possible to define passwords in external yaml file(s)~~
3636
* ...to be defined
3737

3838
# Table of Contents
@@ -143,6 +143,28 @@ The plugin will generate one secret key for each level which is used to encrypt
143143

144144
It is good practice to assign the same level to all pages within a navigation branch (INSERT EXAMPLE HERE).
145145

146+
#### Password inventory in external file
147+
148+
You can define password levels in an external yaml file and use it with `password_file`.
149+
150+
```yaml
151+
plugins:
152+
- encryptcontent:
153+
password_file: 'passwords.yml'
154+
```
155+
156+
passwords.yml:
157+
```yaml
158+
classified: 'password1'
159+
confidential:
160+
- 'password2'
161+
- 'password3'
162+
secret:
163+
user4: 'password4'
164+
user5: 'password5'
165+
```
166+
167+
146168
#### Global password(s) in inventory
147169

148170
You can add the special level `_global`, which will be applied globally on all sites like this:

encryptcontent/plugin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import json
77
import math
8+
import yaml
89
from pathlib import Path
910
from os.path import exists
1011
from jinja2 import Template
@@ -376,8 +377,16 @@ def on_config(self, config, **kwargs):
376377
self.setup['password_keystore'] = {}
377378
self.setup['obfuscate_keystore'] = {}
378379
self.setup['level_keystore'] = {}
379-
380-
if 'password_inventory' in self.config:
380+
381+
if self.config['password_file']:
382+
if self.config['password_inventory']:
383+
print(self.config['password_inventory'])
384+
logger.error("Please define either 'password_file' or 'password_inventory' in mkdocs.yml and not both.")
385+
os._exit(1)
386+
with open(self.config['password_file'], 'r') as stream:
387+
self.config['password_inventory'] = yaml.safe_load(stream)
388+
389+
if self.config['password_inventory']:
381390
for level in self.config['password_inventory'].keys():
382391
new_entry = {}
383392
new_entry['key'] = get_random_bytes(32)

0 commit comments

Comments
 (0)