Skip to content

Commit 68383b8

Browse files
committed
Version 2.2.0
1 parent 8e42305 commit 68383b8

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte
2424
* [Installation](#installation)
2525
* [Usage](#usage)
2626
* [Global password protection](#global-password-protection)
27-
* [Github secret](#github-secret)
27+
* [Secret from environment](#secret-from-environment)
2828
* [Customization](#extra-vars-customization)
2929
* [Features](#features)
3030
* [HighlightJS support](#highlightjs-support) *(default)*
@@ -52,7 +52,7 @@ Install the package from source with pip:
5252
```bash
5353
cd mkdocs-encryptcontent-plugin/
5454
python3 setup.py sdist bdist_wheel
55-
pip3 install dist/mkdocs_encryptcontent_plugin-2.1.0-py3-none-any.whl
55+
pip3 install dist/mkdocs_encryptcontent_plugin-2.2.0-py3-none-any.whl
5656
```
5757

5858
Enable the plugin in your `mkdocs.yml`:
@@ -85,21 +85,25 @@ If a password is defined in an article, it will **ALWAYS** overwrite the global
8585
> **NOTE** Keep in mind that if the `password:` tag exists without value in an article, it will **not be protected** !
8686

8787

88-
### Github secret
88+
### Secret from environment
8989

90-
Instead of specifying a password in the mkdocs.yml file, you can use a Github secret coupled to a CI/CD pipeline. This process is in two steps:
90+
Instead of specifying a password in the mkdocs.yml file, you can use an environment variable to load your secret.
9191

92-
1. First, you need to make an environment variable containing your password accessible at runtime (through any CI/CD pipeline).
92+
This process is in two steps:
9393

94+
1. First, you need to make an environment variable with your global password accessible at runtime (via any CI/CD pipeline or by setting it yourself in your environment).
9495

95-
4. Finally, in the mkdocs.yml file, instead of specifying a global password, simply set the `use_secret` field to the name of your environment variable, e.g. in the case where my secret is stored in the $PASSWORD` variable:
9696

97-
```yaml
97+
2. Then in the mkdocs.yml file, instead of specifying a global password, just set the `use_secret` field with your environment variable name, e.g. in case my secret is stored in the `ENCRYPTCONTENT_PASSWORD` variable:
98+
99+
``` yaml
98100
plugins:
99101
- encryptcontent:
100-
use_secret: 'PASSWORD'
102+
use_secret: 'ENCRYPTCONTENT_PASSWORD'
101103
```
102104

105+
> **NOTE** Keep in mind that if the `use_secret:` configuration is set, it will always be used even if you have also set a global password with the `global_password` variable.
106+
103107

104108
### Extra vars customization
105109

encryptcontent/plugin.py

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ class encryptContentPlugin(BasePlugin):
5757
('title_prefix', config_options.Type(string_types, default=str(SETTINGS['title_prefix']))),
5858
('summary', config_options.Type(string_types, default=str(SETTINGS['summary']))),
5959
('placeholder', config_options.Type(string_types, default=str(SETTINGS['placeholder']))),
60-
('decryption_failure_message',
61-
config_options.Type(string_types, default=str(SETTINGS['decryption_failure_message']))),
62-
('encryption_info_message',
63-
config_options.Type(string_types, default=str(SETTINGS['encryption_info_message']))),
64-
('password_button_text',
65-
config_options.Type(string_types, default=str(SETTINGS['password_button_text']))),
60+
('decryption_failure_message', config_options.Type(string_types, default=str(SETTINGS['decryption_failure_message']))),
61+
('encryption_info_message', config_options.Type(string_types, default=str(SETTINGS['encryption_info_message']))),
62+
('password_button_text', config_options.Type(string_types, default=str(SETTINGS['password_button_text']))),
6663
('global_password', config_options.Type(string_types, default=None)),
6764
('password', config_options.Type(string_types, default=None)),
6865
('arithmatex', config_options.Type(bool, default=True)),
@@ -73,8 +70,7 @@ class encryptContentPlugin(BasePlugin):
7370
('tag_encrypted_page', config_options.Type(bool, default=True)),
7471
('password_button', config_options.Type(bool, default=False)),
7572
('encrypted_something', config_options.Type(dict, default={})),
76-
('search_index',
77-
config_options.Choice(('clear', 'dynamically', 'encrypted'), default='encrypted')),
73+
('search_index', config_options.Choice(('clear', 'dynamically', 'encrypted'), default='encrypted')),
7874
('reload_scripts', config_options.Type(list, default=[])),
7975
('experimental', config_options.Type(bool, default=False)),
8076
# legacy features, doesn't exist anymore
@@ -157,64 +153,56 @@ def on_config(self, config, **kwargs):
157153
if os.environ.get(str(self.config['use_secret'])):
158154
self.config['global_password'] = os.environ.get(str(self.config['use_secret']))
159155
else:
160-
logger.error(('Cannot get global password from environment variable: '),
161-
(f"{str(self.config['use_secret'])}. Abort !"))
156+
logger.error('Cannot get global password from environment variable: {var}. Abort !'.format(
157+
var=str(self.config['use_secret']))
158+
)
162159
os._exit(1)
163160
# Set global password as default password for each page
164161
self.config['password'] = self.config['global_password']
165162
# Check if hljs feature need to be enabled, based on theme configuration
166163
if ('highlightjs' in config['theme']._vars
167164
and config['theme']._vars['highlightjs'] # noqa: W503
168165
and self.config['hljs'] is not False): # noqa: W503, E127
169-
logger.debug(('"highlightjs" value detected on theme config,'),
170-
('enable rendering after decryption.'))
166+
logger.debug('"highlightjs" value detected on theme config, enable rendering after decryption.')
171167
self.config['hljs'] = config['theme']._vars['highlightjs']
172168
else:
173169
logger.info('"highlightjs" feature is disabled in your plugin configuration.')
174170
self.config['hljs'] = False
175-
# Check if pymdownx.arithmatex feature need to be enabled, based on markdown_extensions
176-
# configuration
171+
# Check if pymdownx.arithmatex feature need to be enabled, based on markdown_extensions configuration
177172
if ('pymdownx.arithmatex' in config['markdown_extensions']
178173
and self.config['arithmatex'] is not False): # noqa: W503
179-
logger.debug(('"arithmatex" value detected on extensions config,'),
180-
('enable rendering after decryption.'))
174+
logger.debug('"arithmatex" value detected on extensions config, enable rendering after decryption.')
181175
self.config['arithmatex'] = True
182176
else:
183177
logger.info('"arithmatex" feature is disabled in your plugin configuration.')
184178
self.config['arithmatex'] = False
185179
# Check if mermaid feature need to be enabled, based on plugin configuration
186180
if config['plugins'].get('mermaid2') and self.config['mermaid2'] is not False:
187-
logger.debug(('"mermaid2" value detected on extensions config,'),
188-
('enable rendering after decryption.'))
181+
logger.debug('"mermaid2" value detected on extensions config, enable rendering after decryption.')
189182
self.config['mermaid2'] = True
190183
else:
191184
logger.info('"mermaid2" feature is disabled in your plugin configuration.')
192185
self.config['mermaid2'] = False
193186
# Warn about deprecated features on Vervion 2.0.0
194187
deprecated_options_detected = False
195188
if self.config.get('disable_cookie_protection'):
196-
logger.warning(('DEPRECATED: Feature "disable_cookie_protection" is no longer '),
197-
('supported. Can by remove.'))
189+
logger.warning('DEPRECATED: Feature "disable_cookie_protection" is no longer supported. Can by remove.')
198190
deprecated_options_detected = True
199191
if self.config.get('decrypt_search'):
200-
logger.warning(('DEPRECATED: Feature "decrypt_search" is no longer supported.'),
201-
('Use search_index on "clear" mode instead.'))
192+
logger.warning('DEPRECATED: Feature "decrypt_search" is no longer supported. Use search_index on "clear" mode instead.')
202193
deprecated_options_detected = True
203194
logger.info('Fallback "decrypt_search" configuraiton to "search_index" mode clear.')
204195
self.config['search_index'] = 'clear'
205196
if deprecated_options_detected:
206-
logger.warning(('DEPRECATED: '),
207-
('Features marked as deprecated will be remove in next minor version !'))
197+
logger.warning('DEPRECATED: Features marked as deprecated will be remove in next minor version !')
208198
# Re order plugins to be sure search-index are not encrypted
209199
if self.config['search_index'] == 'clear':
210-
logger.debug(('Reordering plugins loading and put search and encryptcontent'),
211-
('at the end of the event pipe.'))
200+
logger.debug('Reordering plugins loading and put search and encryptcontent at the end of the event pipe.')
212201
config['plugins'].move_to_end('search')
213202
config['plugins'].move_to_end('encryptcontent')
214203
# Enable experimental code .. :popcorn:
215204
if self.config['search_index'] == 'dynamically':
216-
logger.info(('EXPERIMENTAL MODE ENABLE. '),
217-
('Only work with default SearchPlugin, not Material.'))
205+
logger.info('EXPERIMENTAL MODE ENABLE. Only work with default SearchPlugin, not Material.')
218206
self.config['experimental'] = True
219207

220208
def on_pre_build(self, config, **kwargs):
@@ -252,28 +240,26 @@ def _add_entry_from_context(self, page):
252240
if not self.config.get('indexing') or self.config['indexing'] == 'full':
253241
text = parser.stripped_html.rstrip('\n')
254242
if (hasattr(page, 'encrypted') and hasattr(page, 'password')
255-
and page.password is not None): # noqa: W503
243+
and page.password is not None): # noqa: W503
256244
plugin = config['plugins']['encryptcontent']
257245
code = plugin.__encrypt_text_aes__(text, str(page.password))
258246
text = b';'.join(code).decode('ascii')
259247
self._add_entry(title=page.title, text=text, loc=url)
260248
if (self.config.get('indexing')
261-
and self.config['indexing'] in ['full', 'sections']): # noqa: W503
249+
and self.config['indexing'] in ['full', 'sections']): # noqa: W503
262250
for section in parser.data:
263251
if (hasattr(page, 'encrypted')
264-
and hasattr(page, 'password') # noqa: W503
265-
and page.password is not None): # noqa: W503, E127
252+
and hasattr(page, 'password') # noqa: W503
253+
and page.password is not None): # noqa: W503, E127
266254
self.create_entry_for_section(section, page.toc, url, page.password)
267255
else:
268256
self.create_entry_for_section(section, page.toc, url)
269257
SearchIndex.add_entry_from_context = _add_entry_from_context
270258
if self.config['experimental'] is True:
271259
if config['theme'].name == 'material':
272-
logger.error(("UNSUPPORTED Material theme "),
273-
("with experimantal feature search_index=dynamically !"))
260+
logger.error("UNSUPPORTED Material theme with experimantal feature search_index=dynamically !")
274261
exit("UNSUPPORTED Material theme: use search_index: [clear|encrypted] instead.")
275-
# Overwrite search/*.js files from templates/search with encryptcontent contrib
276-
# search assets
262+
# Overwrite search/*.js files from templates/search with encryptcontent contrib search assets
277263
config['theme'].dirs = [
278264
e for e in config['theme'].dirs
279265
if not re.compile(r".*/contrib/search/templates$").match(e)
@@ -330,8 +316,7 @@ def on_page_content(self, html, page, config, **kwargs):
330316
base_path = page.abs_url.replace(page.url, '') if page.abs_url is not None else '/'
331317
# Set password attributes on page for other mkdocs events
332318
setattr(page, 'password', str(self.config['password']))
333-
# Keep encrypted html as temporary variable on page cause we need clear html for search
334-
# plugin
319+
# Keep encrypted html as temporary variable on page cause we need clear html for search plugin
335320
setattr(page, 'html_encrypted', self.__encrypt_content__(html, base_path))
336321
return html
337322

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def read(fname):
1111

1212
setup(
1313
name='mkdocs-encryptcontent-plugin',
14-
version='2.1.0',
14+
version='2.2.0',
1515
author='CoinK0in',
1616
author_email='[email protected]',
1717
description='A MkDocs plugin that encrypt/decrypt markdown content with AES',
@@ -37,7 +37,8 @@ def read(fname):
3737
'Programming Language :: Python :: 3.6',
3838
'Programming Language :: Python :: 3.7',
3939
'Programming Language :: Python :: 3.8',
40-
'Programming Language :: Python :: 3.9'
40+
'Programming Language :: Python :: 3.9',
41+
'Programming Language :: Python :: 3.10'
4142
],
4243
packages=find_packages(exclude=['*.tests']),
4344
entry_points={

0 commit comments

Comments
 (0)