Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] Start refactoring api into /rest/ namespace #224

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion promgen/rest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2019 LINE Corporation
# These sources are released under the terms of the MIT license: see LICENSE

from rest_framework import viewsets
from rest_framework import permissions, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

Expand All @@ -10,6 +10,18 @@
from promgen import filters, models, prometheus, renderers, serializers


class AllViewSet(viewsets.ViewSet):
permission_classes = [permissions.AllowAny]

@action(detail=False, methods=["get"], renderer_classes=[renderers.RuleRenderer])
def rules(self, request):
rules = models.Rule.objects.filter(enabled=True)
return Response(
serializers.AlertRuleSerializer(rules, many=True).data,
headers={"Content-Disposition": "attachment; filename=alert.rule.yml"},
)


class ShardViewSet(viewsets.ModelViewSet):
queryset = models.Shard.objects.all()
filterset_class = filters.ShardFilter
Expand Down
2 changes: 1 addition & 1 deletion promgen/templates/promgen/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<li><a href="{% url 'api:api-root' %}">API</a></li>
<li><a href="{% url 'config-targets' %}">Export Targets</a></li>
<li><a href="{% url 'config-rules' %}">Export Rules</a></li>
<li><a href="{% url 'api:all-rules' %}">Export Rules</a></li>
<li><a href="{% url 'config-urls' %}">Export URL</a></li>

{% if EXTERNAL_LINKS %}
Expand Down
16 changes: 8 additions & 8 deletions promgen/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
from rest_framework import routers

router = routers.DefaultRouter()
router.register('service', rest.ServiceViewSet)
router.register('shard', rest.ShardViewSet)
router.register('project', rest.ProjectViewSet)
router.register("all", rest.AllViewSet, basename="all")
router.register("service", rest.ServiceViewSet)
router.register("shard", rest.ShardViewSet)
router.register("project", rest.ProjectViewSet)


urlpatterns = [
Expand Down Expand Up @@ -104,14 +105,12 @@
url('', include('django.contrib.auth.urls')),
url('', include('social_django.urls', namespace='social')),

# Public API

# Legacy API
path('api/v1/config', csrf_exempt(views.ApiConfig.as_view())),
path("api/", include((router.urls, "api"), namespace="old-api")),
path('api/v1/rules', csrf_exempt(views.RulesConfig.as_view())),

# Promgen API
path('api/v1/targets', csrf_exempt(views.ApiConfig.as_view()), name='config-targets'),
path('api/v1/rules', csrf_exempt(views.RulesConfig.as_view()), name='config-rules'),
path('api/v1/urls', csrf_exempt(views.URLConfig.as_view()), name='config-urls'),
path('api/v1/alerts', csrf_exempt(views.Alert.as_view()), name='alert'),
path('api/v1/host/<slug>', views.HostDetail.as_view()),
Expand All @@ -131,7 +130,8 @@
path("proxy/v1/silences", csrf_exempt(proxy.ProxySilences.as_view()), name="proxy-silence"),
path("proxy/v1/silences/<silence_id>", csrf_exempt(proxy.ProxyDeleteSilence.as_view()), name="proxy-silence-delete"),

path("api/", include((router.urls, "api"), namespace="api")),
# Promgen rest API
path("rest/", include((router.urls, "api"), namespace="api")),
]

try:
Expand Down