Merge "Encrypt: never strip with --infile"

This commit is contained in:
Zuul 2021-04-24 05:38:12 +00:00 committed by Gerrit Code Review
commit 110a460dd2

View File

@ -497,7 +497,8 @@ class ZuulClient():
required=False, default=None)
cmd_encrypt.add_argument('--no-strip', action='store_true',
help='Do not strip whitespace from beginning '
'or end of input.',
'or end of input. Ignored when '
'--infile is used.',
default=False)
cmd_encrypt.add_argument('--secret-name',
default=None,
@ -530,7 +531,9 @@ class ZuulClient():
raise ArgumentException(
'Either provide a public key or a project to continue'
)
strip = not self.args.no_strip
if self.args.infile:
strip = False
try:
with open(self.args.infile) as f:
plaintext = f.read()
@ -541,7 +544,7 @@ class ZuulClient():
'Insufficient rights to open %s' % self.args.infile)
else:
plaintext = sys.stdin.read()
if not self.args.no_strip:
if strip:
plaintext = plaintext.strip()
pubkey_file = tempfile.NamedTemporaryFile(delete=False)
self.log.debug('Creating temporary key file %s' % pubkey_file.name)