mik-laj commented on a change in pull request #9273:
URL: https://github.com/apache/airflow/pull/9273#discussion_r440955054



##########
File path: airflow/api_connexion/endpoints/variable_endpoint.py
##########
@@ -14,41 +14,76 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from typing import Optional
 
-# TODO(mik-laj): We have to implement it.
-#     Do you want to help? Please look at: 
https://github.com/apache/airflow/issues/8142
+from flask import Response, make_response, request
+from marshmallow import ValidationError
 
+from airflow.api_connexion.exceptions import BadRequest, NotFound
+from airflow.api_connexion.schemas.variable_schema import 
variable_collection_schema, variable_schema
+from airflow.models import Variable
+from airflow.utils.session import provide_session
 
-def delete_variable():
+
+def delete_variable(variable_key: str) -> Response:
     """
     Delete variable
     """
-    raise NotImplementedError("Not implemented yet.")
+    Variable.delete(variable_key)
+    return make_response('', 204)
 
 
-def get_variable():
+def get_variable(variable_key: str) -> Response:
     """
     Get a variables by key
     """
-    raise NotImplementedError("Not implemented yet.")
+    try:
+        var = Variable.get(variable_key)
+    except KeyError:
+        raise NotFound("Variable not found")
+    return variable_schema.dump({"key": variable_key, "val": var})
 
 
-def get_variables():
+@provide_session
+def get_variables(session, limit: Optional[int], offset: Optional[int] = None) 
-> Response:
     """
     Get all variable values
     """
-    raise NotImplementedError("Not implemented yet.")
+    query = session.query(Variable)
+    if limit:
+        if offset:
+            query = query.offset(offset * limit)
+        query = query.limit(limit)
+    variables = query.all()
+    return variable_collection_schema.dump({
+        "variables": variables,
+        "total_entries": len(variables),
+    })
 
 
-def patch_variable():
+def patch_variable(variable_key: str):
     """
     Update a variable by key
     """
-    raise NotImplementedError("Not implemented yet.")
+    try:
+        var = variable_schema.loads(request.get_data())

Review comment:
       In my opinion the update_mask field should remain. We have only one 
field for now, but in the future we can add other fields. When we decide to 
keep this field, we will be able to change the structure of this object without 
introducing any breaking-change. In addition, this will allow us to maintain 
the consistency in the API. So I think every PATCH endpoint should have a 
update mask.
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to