amoghrajesh commented on code in PR #44449:
URL: https://github.com/apache/airflow/pull/44449#discussion_r1862196084
##########
airflow/api_fastapi/execution_api/routes/variables.py:
##########
@@ -67,7 +67,29 @@ def get_variable(variable_key: str, token: deps.TokenDep) ->
VariableResponse:
return VariableResponse(key=variable_key, value=variable_value)
-def has_variable_access(variable_key: str, token: TIToken) -> bool:
[email protected](
+ "",
+ responses={
+ status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
+ status.HTTP_403_FORBIDDEN: {"description": "Task does not have access
to the variable"},
+ },
+)
+def post_variable(body: VariablePostBody, token: deps.TokenDep) ->
VariableResponse:
+ """Set an Airflow Variable."""
+ if not has_variable_access(body.key, token, write_access=True):
+ raise HTTPException(
+ status_code=status.HTTP_403_FORBIDDEN,
+ detail={
+ "reason": "access_denied",
+ "message": f"Task does not have access to write variable
{body.key}",
+ },
+ )
+
+ Variable.set(**body.model_dump())
+ return VariableResponse(key=body.key, value=body.value)
Review Comment:
Yea should be good enough, but I wasn't too sure why the legacy and the new
core api returns the variable.
But in our case, should be ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]