Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional output path parameter to sign and asign methods #5924

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/5923.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add optional ``output_path`` parameter to SigningService.sign and SigningService.asign methods to allow parsing an output to the signing script.
20 changes: 15 additions & 5 deletions pulpcore/app/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def _env_variables(self, env_vars=None):
env.update(env_vars)
return env

def sign(self, filename, env_vars=None):
def sign(self, filename, output_path=None, env_vars=None):
"""
Signs the file provided via 'filename' by invoking an external script (or executable).

Expand All @@ -796,15 +796,21 @@ def sign(self, filename, env_vars=None):
Args:
filename (str): A relative path to a file which is intended to be signed.
env_vars (dict): dictionary of environment variables
output_path (str): Allow contents to be signed at a specific location.

Raises:
RuntimeError: If the return code of the script is not equal to 0.

Returns:
A dictionary as validated by the validate() method.
"""
command = [self.script, filename]

if output_path:
command.append(output_path)

completed_process = subprocess.run(
[self.script, filename],
command,
env=self._env_variables(env_vars),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -820,11 +826,15 @@ def sign(self, filename, env_vars=None):

return return_value

async def asign(self, filename, env_vars=None):
async def asign(self, filename, output_path=None, env_vars=None):
"""Async version of sign."""
command = [self.script, filename]

if output_path:
command.append(output_path)

process = await asyncio.create_subprocess_exec(
self.script,
filename,
*command,
env=self._env_variables(env_vars),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
Expand Down
Loading