Skip to content

Commit 02ced9b

Browse files
committed
allow definition of a _global level that is applied to all pages
1 parent dbe3893 commit 02ced9b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte
3131
* ~~Save the generated random keys instead of passwords to session( or local) storage~~
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~~
34-
* find an equivalent way to define multiple passwords in the password inventory as global password
34+
* ~~find an equivalent way to define multiple passwords in the password inventory as global password~~
3535
* make it possible to define passwords in external yaml file(s)
3636
* ...to be defined
3737

@@ -143,6 +143,25 @@ 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+
#### Global password(s) in inventory
147+
148+
You can add the special level `_global`, which will be applied globally on all sites like this:
149+
150+
```yam
151+
plugins:
152+
- encryptcontent:
153+
password_inventory:
154+
_global: 'either define one password'
155+
_global:
156+
- 'or define'
157+
- 'multiple passwords'
158+
_global:
159+
user1: 'or use user'
160+
user2: 'and password pairs'
161+
```
162+
163+
> **NOTE** Add the meta tag `level:` (without a value) to pages which should be excluded from global password level.
164+
> Also note that it is always possible to set the page to a different level than the global one with the `level` meta tag.
146165

147166
### Secret from environment
148167

encryptcontent/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ def on_page_markdown(self, markdown, page, config, **kwargs):
507507

508508
# Set global password as default password for each page
509509
encryptcontent['password'] = self.config['global_password']
510+
# level '_global' will be set as global level
511+
if '_global' in self.setup['level_keystore']:
512+
encryptcontent['level'] = '_global'
510513

511514
if 'password' in page.meta.keys():
512515
# If global_password is set, but you don't want to encrypt content
@@ -524,7 +527,9 @@ def on_page_markdown(self, markdown, page, config, **kwargs):
524527
del page.meta['obfuscate']
525528

526529
if 'level' in page.meta.keys():
527-
encryptcontent['level'] = str(page.meta.get('level'))
530+
# If '_global' level is set, but you don't want to encrypt content
531+
page_level = str(page.meta.get('level'))
532+
encryptcontent['level'] = None if page_level == '' else page_level
528533
del page.meta['level']
529534

530535
# Custom per-page strings

0 commit comments

Comments
 (0)