forked from ansible/eda-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config/ endpoint to display eda-server version (ansible#972)
* add a new endpoint api/eda/v1/config/ to retrieve eda-server config info including version * add get_eda_version function to retrieve version from package
- Loading branch information
1 parent
55e8897
commit 24cd4b3
Showing
9 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from rest_framework import serializers | ||
|
||
|
||
class ConfigSerializer(serializers.Serializer): | ||
"""Serializer for ConfigView response.""" | ||
|
||
time_zone = serializers.CharField( | ||
required=True, | ||
) | ||
|
||
version = serializers.CharField( | ||
required=True, | ||
) | ||
|
||
deployment_type = serializers.CharField( | ||
required=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2024 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from django.conf import settings | ||
from drf_spectacular.utils import OpenApiResponse, extend_schema | ||
from rest_framework import status | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from aap_eda.api.serializers import ConfigSerializer | ||
from aap_eda.utils import get_eda_version | ||
|
||
|
||
class ConfigView(APIView): | ||
permission_classes = [IsAuthenticated] | ||
|
||
@extend_schema( | ||
description="Get the current configuration info of EDA.", | ||
responses={ | ||
status.HTTP_200_OK: OpenApiResponse( | ||
ConfigSerializer, | ||
description=("Return the current configuration info of EDA."), | ||
) | ||
}, | ||
) | ||
def get(self, request): | ||
data = { | ||
"time_zone": settings.TIME_ZONE, | ||
"version": get_eda_version(), | ||
"deployment_type": settings.DEPLOYMENT_TYPE, | ||
} | ||
|
||
return Response(ConfigSerializer(data).data, status=status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2024 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import pytest | ||
from django.conf import settings | ||
|
||
from aap_eda.utils import get_eda_version | ||
from tests.integration.constants import api_url_v1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_v1_config(admin_client): | ||
response = admin_client.get(f"{api_url_v1}/config/") | ||
assert response.status_code == 200 | ||
assert response.data == { | ||
"time_zone": settings.TIME_ZONE, | ||
"version": get_eda_version(), | ||
"deployment_type": settings.DEPLOYMENT_TYPE, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters