-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The intention of this PR is to build a concrete strategy to follow when versioning the project API. issue: https://issues.redhat.com/browse/AAP-37993
- Loading branch information
Showing
41 changed files
with
766 additions
and
59 deletions.
There are no files selected for viewing
Empty file.
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,38 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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 ansible_ai_connect.ai.api import exceptions | ||
|
||
|
||
class APIViewSaasMixin: | ||
|
||
def initial(self, request, *args, **kwargs): | ||
self.check_saas_settings(request) | ||
return super().initial(request, *args, **kwargs) | ||
|
||
def check_saas_settings(self, request): | ||
"""call the correct error function when DEPLOYMENT_MODE is not saas | ||
and not in DEBUG mode""" | ||
if not settings.DEBUG and settings.DEPLOYMENT_MODE != "saas": | ||
self.not_implemented_error( | ||
request, message="This functionality is not available in the current environment" | ||
) | ||
|
||
def not_implemented_error(self, request, message=None, code=None): | ||
""" | ||
raise not implement exception when called | ||
""" | ||
raise exceptions.NotImplementedException(detail=message, code=code) |
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
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,31 @@ | ||
|
||
## Versioning principles and restrictions: | ||
|
||
The application API is organized by versions directory structure, that rely on some basic principles and restrictions: | ||
|
||
- The views and serializers outside the versions directories is considered as base code, | ||
in the future the related modules should be moved to a base directory. | ||
|
||
- urls modules use views that are imported only from the same version directory hierarchy. | ||
- urls modules use urls to include that are imported only from the same version directory hierarchy, | ||
an exception is made for urls to include from external application. | ||
|
||
- views modules can use serializers that are imported only from the same version directory hierarchy. | ||
|
||
views modules of a version x can: | ||
- reuse the base views, directly or modified (using inheritance). | ||
- reuse the views only from the previous x-1 version, directly or modified (using inheritance). | ||
|
||
serializers modules of a version x can: | ||
- reuse the base serializers, directly or modified (using inheritance). | ||
- reuse the serializers only from the previous x-1 version, directly or modified (using inheritance). | ||
|
||
## Generate a concrete API schema version | ||
|
||
```commandline | ||
VERSION="v1" podman exec -it --user=0 docker-compose-django-1 wisdom-manage spectacular --api-version $VERSION --file /var/www/ansible-ai-connect-service/ansible_ai_connect/schema-$VERSION.yaml | ||
``` | ||
This will generate a schema file with requested version at ansible_ai_connect directory | ||
|
||
the default format is openapi (yaml file format) | ||
but also openapi-json can be produced with "--format openapi-json" option |
Empty file.
Empty file.
Empty file.
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,28 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("completions/", views.Completions.as_view(), name="completions"), | ||
path("contentmatches/", views.ContentMatches.as_view(), name="contentmatches"), | ||
path("explanations/", views.Explanation.as_view(), name="explanations"), | ||
path("generations/", views.GenerationPlaybook.as_view(), name="generations"), | ||
path("generations/playbook", views.GenerationPlaybook.as_view(), name="generations/playbook"), | ||
path("generations/role", views.GenerationRole.as_view(), name="generations/role"), | ||
path("feedback/", views.Feedback.as_view(), name="feedback"), | ||
path("chat/", views.Chat.as_view(), name="chat"), | ||
] |
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,33 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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 ansible_ai_connect.ai.api.views import ( | ||
Chat, | ||
Completions, | ||
ContentMatches, | ||
Explanation, | ||
Feedback, | ||
GenerationPlaybook, | ||
GenerationRole, | ||
) | ||
|
||
__all__ = [ | ||
Completions, | ||
ContentMatches, | ||
Explanation, | ||
GenerationPlaybook, | ||
GenerationRole, | ||
Feedback, | ||
Chat, | ||
] |
Empty file.
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,21 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.TelemetrySettingsView.as_view(), name="telemetry_settings"), | ||
] |
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,19 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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 ansible_ai_connect.ai.api.telemetry.api_telemetry_settings_views import ( | ||
TelemetrySettingsView, | ||
) | ||
|
||
__all__ = [TelemetrySettingsView] |
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,32 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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 django.urls import include, path | ||
|
||
from .ai import urls as ai_urls | ||
from .telemetry import urls as telemetry_urls | ||
from .users import urls as me_urls | ||
from .wca import urls as wca_urls | ||
|
||
urlpatterns = [ | ||
path("ai/", include(ai_urls)), | ||
path("me/", include(me_urls)), | ||
] | ||
|
||
if settings.DEBUG or settings.DEPLOYMENT_MODE == "saas": | ||
urlpatterns += [ | ||
path("telemetry/", include(telemetry_urls)), | ||
path("wca/", include(wca_urls)), | ||
] |
Empty file.
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,22 @@ | ||
# Copyright Red Hat | ||
# | ||
# 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.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.CurrentUserView.as_view(), name="me"), | ||
path("summary/", views.MarkdownCurrentUserView.as_view(), name="summary"), | ||
] |
Oops, something went wrong.