Skip to content

Commit

Permalink
[fixcore][fix] Do not write to a temp directory when internal (#1990)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Melkozerov <[email protected]>
  • Loading branch information
aquamatthias and meln1k authored Mar 14, 2024
1 parent 0bbeb32 commit 879aec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fixcore/fixcore/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3834,9 +3834,9 @@ def args_info(self) -> ArgsInfo:
return [ArgInfo(expects_value=True, value_hint="file", help_text="file to write to")]

@staticmethod
async def write_result_to_file(in_stream: JsStream, file_name: str) -> AsyncIterator[JsonElement]:
async def write_result_to_file(ctx: CLIContext, in_stream: JsStream, file_name: str) -> AsyncIterator[JsonElement]:
async with TemporaryDirectory() as temp_dir:
path = os.path.join(temp_dir, uuid_str())
path = file_name if ctx.intern else os.path.join(temp_dir, uuid_str())
async with aiofiles.open(path, "w") as f:
async with in_stream.stream() as streamer:
async for out in streamer:
Expand All @@ -3858,7 +3858,7 @@ def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwa
if (ex := self.get_previous_command(kwargs)) and ex.action.produces == MediaType.FilePath:
fn = self.already_file_stream
else:
fn = self.write_result_to_file
fn = partial(self.write_result_to_file, ctx)
return CLIFlow(lambda in_stream: fn(in_stream, arg), MediaType.FilePath, required_permissions={Permission.read})


Expand Down
5 changes: 5 additions & 0 deletions fixcore/fixcore/cli/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ def graph_name(self) -> GraphName:
def section(self) -> str:
return self.env.get("section", PathRoot)

@property
def intern(self) -> bool:
# currently only 2 sources: api and task_handler
return self.source == "task_handler"

@property
def user_permissions(self) -> Set[Permission]:
return self.user.permissions if self.user else set()
Expand Down

0 comments on commit 879aec5

Please sign in to comment.