Skip to content

Commit e036ac2

Browse files
author
Bryce Larson
authored
Merge branch 'develop' into develop
2 parents 0f5e101 + c9c3a4b commit e036ac2

File tree

4 files changed

+82
-39
lines changed

4 files changed

+82
-39
lines changed

salt/modules/slsutil.py

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,11 @@ def banner(width=72, commentchar='#', borderchar='#', blockstart=None, blockend=
279279
:param newline: Boolean value to indicate whether the comment block should
280280
end with a newline. Default is ``False``.
281281
282-
This banner can be injected into any templated file, for example:
282+
**Example 1 - the default banner:**
283283
284284
.. code-block:: jinja
285285
286-
{{ salt['slsutil.banner'](width=120, commentchar='//') }}
287-
288-
The default banner:
286+
{{ salt['slsutil.banner']() }}
289287
290288
.. code-block:: none
291289
@@ -296,6 +294,42 @@ def banner(width=72, commentchar='#', borderchar='#', blockstart=None, blockend=
296294
# The contents of this file are managed by Salt. Any changes to this #
297295
# file may be overwritten automatically and without warning. #
298296
########################################################################
297+
298+
**Example 2 - a Javadoc-style banner:**
299+
300+
.. code-block:: jinja
301+
302+
{{ salt['slsutil.banner'](commentchar=' *', borderchar='*', blockstart='/**', blockend=' */') }}
303+
304+
.. code-block:: none
305+
306+
/**
307+
***********************************************************************
308+
* *
309+
* THIS FILE IS MANAGED BY SALT - DO NOT EDIT *
310+
* *
311+
* The contents of this file are managed by Salt. Any changes to this *
312+
* file may be overwritten automatically and without warning. *
313+
***********************************************************************
314+
*/
315+
316+
**Example 3 - custom text:**
317+
318+
.. code-block:: jinja
319+
320+
{{ set copyright='This file may not be copied or distributed without permission of SaltStack, Inc.' }}
321+
{{ salt['slsutil.banner'](title='Copyright 2019 SaltStack, Inc.', text=copyright, width=60) }}
322+
323+
.. code-block:: none
324+
325+
############################################################
326+
# #
327+
# Copyright 2019 SaltStack, Inc. #
328+
# #
329+
# This file may not be copied or distributed without #
330+
# permission of SaltStack, Inc. #
331+
############################################################
332+
299333
'''
300334

301335
if title is None:
@@ -304,18 +338,26 @@ def banner(width=72, commentchar='#', borderchar='#', blockstart=None, blockend=
304338
if text is None:
305339
text = ('The contents of this file are managed by Salt. '
306340
'Any changes to this file may be overwritten '
307-
'automatically and without warning')
341+
'automatically and without warning.')
308342

309343
# Set up some typesetting variables
310-
lgutter = commentchar.strip() + ' '
311-
rgutter = ' ' + commentchar.strip()
344+
ledge = commentchar.rstrip()
345+
redge = commentchar.strip()
346+
lgutter = ledge + ' '
347+
rgutter = ' ' + redge
312348
textwidth = width - len(lgutter) - len(rgutter)
313-
border_line = commentchar + borderchar[:1] * (width - len(commentchar) * 2) + commentchar
349+
350+
# Check the width
351+
if textwidth <= 0:
352+
raise salt.exceptions.ArgumentValueError('Width is too small to render banner')
353+
354+
# Define the static elements
355+
border_line = commentchar + borderchar[:1] * (width - len(ledge) - len(redge)) + redge
314356
spacer_line = commentchar + ' ' * (width - len(commentchar) * 2) + commentchar
315-
wrapper = textwrap.TextWrapper(width=(width - len(lgutter) - len(rgutter)))
316-
block = list()
317357

318358
# Create the banner
359+
wrapper = textwrap.TextWrapper(width=textwidth)
360+
block = list()
319361
if blockstart is not None:
320362
block.append(blockstart)
321363
block.append(border_line)

salt/modules/x509.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def read_certificate(certificate):
590590

591591
def read_certificates(glob_path):
592592
'''
593-
Returns a dict containing details of a all certificates matching a glob
593+
Returns a dict containing details of all certificates matching a glob
594594
595595
glob_path:
596596
A path to certificates to be read and returned.
@@ -651,8 +651,8 @@ def read_crl(crl):
651651
652652
:depends: - OpenSSL command line tool
653653
654-
csl:
655-
A path or PEM encoded string containing the CSL to read.
654+
crl:
655+
A path or PEM encoded string containing the CRL to read.
656656
657657
CLI Example:
658658
@@ -747,17 +747,17 @@ def write_pem(text, path, overwrite=True, pem_type=None):
747747
PEM string input to be written out.
748748
749749
path:
750-
Path of the file to write the pem out to.
750+
Path of the file to write the PEM out to.
751751
752752
overwrite:
753-
If True(default), write_pem will overwrite the entire pem file.
753+
If ``True`` (default), write_pem will overwrite the entire PEM file.
754754
Set False to preserve existing private keys and dh params that may
755-
exist in the pem file.
755+
exist in the PEM file.
756756
757757
pem_type:
758758
The PEM type to be saved, for example ``CERTIFICATE`` or
759759
``PUBLIC KEY``. Adding this will allow the function to take
760-
input that may contain multiple pem types.
760+
input that may contain multiple PEM types.
761761
762762
CLI Example:
763763
@@ -871,22 +871,22 @@ def create_crl( # pylint: disable=too-many-arguments,too-many-locals
871871
:depends: - PyOpenSSL Python module
872872
873873
path:
874-
Path to write the crl to.
874+
Path to write the CRL to.
875875
876876
text:
877877
If ``True``, return the PEM text without writing to a file.
878878
Default ``False``.
879879
880880
signing_private_key:
881881
A path or string of the private key in PEM format that will be used
882-
to sign this crl. This is required.
882+
to sign the CRL. This is required.
883883
884884
signing_private_key_passphrase:
885885
Passphrase to decrypt the private key.
886886
887887
signing_cert:
888888
A certificate matching the private key that will be used to sign
889-
this crl. This is required.
889+
the CRL. This is required.
890890
891891
revoked:
892892
A list of dicts containing all the certificates to revoke. Each dict
@@ -1119,9 +1119,9 @@ def create_certificate(
11191119
Default ``False``.
11201120
11211121
overwrite:
1122-
If True(default), create_certificate will overwrite the entire pem
1122+
If ``True`` (default), create_certificate will overwrite the entire PEM
11231123
file. Set False to preserve existing private keys and dh params that
1124-
may exist in the pem file.
1124+
may exist in the PEM file.
11251125
11261126
kwargs:
11271127
Any of the properties below can be included as additional
@@ -1131,7 +1131,7 @@ def create_certificate(
11311131
Request a remotely signed certificate from ca_server. For this to
11321132
work, a ``signing_policy`` must be specified, and that same policy
11331133
must be configured on the ca_server (name or list of ca server). See ``signing_policy`` for
1134-
details. Also the salt master must permit peers to call the
1134+
details. Also, the salt master must permit peers to call the
11351135
``sign_remote_certificate`` function.
11361136
11371137
Example:
@@ -1192,7 +1192,7 @@ def create_certificate(
11921192
11931193
public_key:
11941194
The public key to be included in this certificate. This can be sourced
1195-
from a public key, certificate, csr or private key. If a private key
1195+
from a public key, certificate, CSR or private key. If a private key
11961196
is used, the matching public key from the private key will be
11971197
generated before any processing is done. This means you can request a
11981198
certificate from a remote CA using a private key file as your
@@ -1256,7 +1256,7 @@ def create_certificate(
12561256
X509v3 Subject Alternative Name
12571257
12581258
crlDistributionPoints:
1259-
X509v3 CRL distribution points
1259+
X509v3 CRL Distribution points
12601260
12611261
issuingDistributionPoint:
12621262
X509v3 Issuing Distribution Point
@@ -1316,7 +1316,7 @@ def create_certificate(
13161316
signing_policy:
13171317
A signing policy that should be used to create this certificate.
13181318
Signing policies should be defined in the minion configuration, or in
1319-
a minion pillar. It should be a yaml formatted list of arguments
1319+
a minion pillar. It should be a YAML formatted list of arguments
13201320
which will override any arguments passed to this function. If the
13211321
``minions`` key is included in the signing policy, only minions
13221322
matching that pattern (see match.glob and match.compound) will be
@@ -1717,7 +1717,7 @@ def verify_private_key(private_key, public_key, passphrase=None):
17171717
17181718
public_key:
17191719
The public key to verify, can be a string or path to a PEM formatted
1720-
certificate, csr, or another private key.
1720+
certificate, CSR, or another private key.
17211721
17221722
passphrase:
17231723
Passphrase to decrypt the private key.
@@ -1743,7 +1743,7 @@ def verify_signature(certificate, signing_pub_key=None,
17431743
17441744
signing_pub_key:
17451745
The public key to verify, can be a string or path to a PEM formatted
1746-
certificate, csr, or private key.
1746+
certificate, CSR, or private key.
17471747
17481748
signing_pub_key_passphrase:
17491749
Passphrase to the signing_pub_key if it is an encrypted private key.
@@ -1883,7 +1883,7 @@ def will_expire(certificate, days):
18831883
ret['cn'] = _parse_subject(cert.get_subject())['CN']
18841884
ret['will_expire'] = _expiration_date.strftime(ts_pt) <= _check_time.strftime(ts_pt)
18851885
except ValueError as err:
1886-
log.debug('Unable to return details of a sertificate expiration: %s', err)
1886+
log.debug('Unable to return details of a certificate expiration: %s', err)
18871887
log.trace(err, exc_info=True)
18881888

18891889
return ret

salt/states/x509.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
:depends: M2Crypto
88
9-
This module can enable managing a complete PKI infrastructure including creating private keys, CA's,
9+
This module can enable managing a complete PKI infrastructure including creating private keys, CAs,
1010
certificates and CRLs. It includes the ability to generate a private key on a server, and have the
1111
corresponding public key sent to a remote CA to create a CA signed certificate. This can be done in
1212
a secure manner, where private keys are always generated locally and never moved across the network.
@@ -117,7 +117,7 @@
117117
118118
119119
This state will instruct all minions to trust certificates signed by our new CA.
120-
Using jinja to strip newlines from the text avoids dealing with newlines in the rendered yaml,
120+
Using Jinja to strip newlines from the text avoids dealing with newlines in the rendered YAML,
121121
and the :mod:`sign_remote_certificate <salt.states.x509.sign_remote_certificate>` state will
122122
handle properly formatting the text before writing the output.
123123
@@ -267,7 +267,7 @@ def private_key_managed(name,
267267
Cipher for encrypting the private key.
268268
269269
new:
270-
Always create a new key. Defaults to False.
270+
Always create a new key. Defaults to ``False``.
271271
Combining new with :mod:`prereq <salt.states.requsities.preqreq>`, or when used as part of a
272272
`managed_private_key` can allow key rotation whenever a new certificiate is generated.
273273
@@ -285,7 +285,7 @@ def private_key_managed(name,
285285
286286
Example:
287287
288-
The jinja templating in this example ensures a private key is generated if the file doesn't exist
288+
The Jinja templating in this example ensures a private key is generated if the file doesn't exist
289289
and that a new private key is generated whenever the certificate that uses it is to be renewed.
290290
291291
.. code-block:: jinja
@@ -404,7 +404,7 @@ def certificate_managed(name,
404404
Manages the private key corresponding to the certificate. All of the
405405
arguments supported by :py:func:`x509.private_key_managed
406406
<salt.states.x509.private_key_managed>` are supported. If `name` is not
407-
speicified or is the same as the name of the certificate, the private
407+
specified or is the same as the name of the certificate, the private
408408
key and certificate will be written together in the same file.
409409
410410
append_certs:
@@ -627,14 +627,14 @@ def crl_managed(name,
627627
Path to the certificate
628628
629629
signing_private_key
630-
The private key that will be used to sign this crl. This is
630+
The private key that will be used to sign the CRL. This is
631631
usually your CA's private key.
632632
633633
signing_private_key_passphrase
634634
Passphrase to decrypt the private key.
635635
636636
signing_cert
637-
The certificate of the authority that will be used to sign this crl.
637+
The certificate of the authority that will be used to sign the CRL.
638638
This is usually your CA's certificate.
639639
640640
revoked
@@ -650,8 +650,8 @@ def crl_managed(name,
650650
of pyOpenSSL less than 0.14.
651651
652652
days_remaining : 30
653-
The crl should be automatically recreated if there are less than
654-
``days_remaining`` days until the crl expires. Set to 0 to disable
653+
The CRL should be automatically recreated if there are less than
654+
``days_remaining`` days until the CRL expires. Set to 0 to disable
655655
automatic renewal.
656656
657657
include_expired : False

tests/unit/modules/test_slsutil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_banner(self):
3232
self.check_banner(width=20)
3333
self.check_banner(commentchar='//', borderchar='-')
3434
self.check_banner(title='title here', text='text here')
35+
self.check_banner(commentchar=' *')
3536

3637
def check_banner(self, width=72, commentchar='#', borderchar='#', blockstart=None, blockend=None,
3738
title=None, text=None, newline=True):
@@ -42,7 +43,7 @@ def check_banner(self, width=72, commentchar='#', borderchar='#', blockstart=Non
4243
for line in result:
4344
self.assertEqual(len(line), width)
4445
self.assertTrue(line.startswith(commentchar))
45-
self.assertTrue(line.endswith(commentchar))
46+
self.assertTrue(line.endswith(commentchar.strip()))
4647

4748
def test_boolstr(self):
4849
'''

0 commit comments

Comments
 (0)