-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Domains REST API endpoint
This commit implements an API endpoint that allows making GET, POST, PUT, and PATCH requests to read, create, and update Domain objects. This implementation includes helper functions in utils.py responsible for configuring sssd service accordingly. Signed-off-by: Francisco Trivino <[email protected]>
- Loading branch information
Showing
7 changed files
with
614 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Copyright (C) 2023 FreeIPA Contributors see COPYING for license | ||
# | ||
|
||
import logging | ||
|
||
from rest_framework.serializers import ModelSerializer | ||
|
||
from domains.models import Domain | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DomainSerializer(ModelSerializer): | ||
class Meta: | ||
model = Domain | ||
fields = ( | ||
'name', | ||
'integration_domain_url', | ||
'client_id', | ||
'client_secret', | ||
'description', | ||
'id_provider', | ||
'user_extra_attrs', | ||
'ldap_tls_cacert', | ||
) |
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,68 @@ | ||
# | ||
# Copyright (C) 2023 FreeIPA Contributors see COPYING for license | ||
# | ||
|
||
import logging | ||
|
||
from django.db import models | ||
from django.utils.translation import gettext as _ | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Domain(models.Model): | ||
""" | ||
Integration Domain model. | ||
This defines an integration domain supported by ipatuura service. | ||
The fields corresponds to the integration domain required | ||
configuration fields. | ||
""" | ||
|
||
# Field Choices for the supported integration domain provider types | ||
DOMAIN_PROVIDER_TYPE = ( | ||
('ipa', _('FreeIPA Provider')), | ||
('ad', _('LDAP AD Provider')), | ||
('ldap', _('LDAP Provider')), | ||
) | ||
|
||
# TODO: implement is_active boolean flag | ||
# so that designates whether the integration domain should be considered active. | ||
# is_active = models.BooleanField(verbose_name='is active?', default=True) | ||
|
||
# TODO: implement remove_datetime timestampt | ||
# datetime | ||
# remove_datetime = models.DateTimeField(verbose_name='remove date', blank=True, null=True) | ||
|
||
# Domain Name | ||
name = models.CharField(primary_key=True, max_length=80) | ||
|
||
# The connection URL to the identity server | ||
integration_domain_url = models.CharField(max_length=80) | ||
|
||
# Temporary admin service username | ||
client_id = models.CharField(max_length=20) | ||
|
||
# Temporary admin service password | ||
client_secret = models.CharField(max_length=20) | ||
|
||
# Optional description | ||
description = models.TextField(blank=True) | ||
|
||
# Identity provider type | ||
id_provider = models.CharField( | ||
max_length=5, | ||
choices=DOMAIN_PROVIDER_TYPE, | ||
default='ipa', | ||
) | ||
|
||
# Comma-separated list of LDAP attributes that SSSD would | ||
# fetch along with the usual set of user attributes | ||
user_extra_attrs = models.CharField(max_length=100) | ||
|
||
# LDAP auth with TLS support, ipa-tuura needs to fetch the CA certificate file | ||
# that is configured on the AD/LDAP server before proceeding... | ||
ldap_tls_cacert = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name |
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,34 @@ | ||
# | ||
# Copyright (C) 2023 FreeIPA Contributors see COPYING for license | ||
# | ||
|
||
"""Integration Domain URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.0/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
import logging | ||
|
||
from django.urls import include, re_path | ||
from rest_framework.routers import DefaultRouter | ||
from domains.views import DomainViewSet | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
router = DefaultRouter() | ||
router.register('domain', DomainViewSet) | ||
|
||
urlpatterns = [ | ||
re_path('^', include(router.urls)), | ||
] |
Oops, something went wrong.