Exemple #1
0
    def approve_view(self, request, approval_id):
        user = get_object_or_404(User, approval_id=approval_id)
        current_ns = user.service_account.namespace if user.service_account else None

        context = dict(
            self.admin_site.each_context(request),
            user=user,
            all_namespaces=models.KubernetesNamespace.objects.all(),
            current_ns=current_ns
        )
        if request.method == 'POST':
            if request.POST['choice'] == "approve_choose":
                new_ns = get_object_or_404(models.KubernetesNamespace, name=request.POST['approve_choose_name'])
                new_svc = get_object_or_404(models.KubernetesServiceAccount, namespace=new_ns, name="default")
                if user.approve(request, new_svc):
                    user.save()
            if request.POST['choice'] == "approve_create":
                new_ns = models.KubernetesNamespace(name=request.POST['approve_create_name'])
                new_ns.save()
                if sync(request):  # creates "default" service account automatically
                    new_svc = get_object_or_404(models.KubernetesServiceAccount, namespace=new_ns, name="default")
                    if user.approve(request, new_svc):
                        user.save()
                    else:
                        new_ns.delete()
            if request.POST['choice'] == "reject":
                if user.reject(request):
                    user.save()
            return redirect('admin:kubeportal_user_changelist')
        else:
            if user.has_access_approved or user.has_access_rejected:
                context['answered_decision'] = user.state
                context['answered_by'] = user.answered_by
            return TemplateResponse(request, "admin/approve.html", context)
Exemple #2
0
    def handle(self, *args, **option):
        init()

        ns_logs, svca_logs = sync()
        print("Namespace synchronization:")
        for line in ns_logs:
            self.print_line(line)
        print("\nService account synchronization:")
        for line in svca_logs:
            self.print_line(line)
Exemple #3
0
def sync_view(request):
    kubernetes.sync(request)
    return redirect('admin:index')
Exemple #4
0
 def save_model(self, request, obj, form, change):
     super().save_model(request, obj, form, change)
     sync(request)
Exemple #5
0
 def sync_view(self, request):
     sync(request)
     return redirect('admin:index')
Exemple #6
0
 def _call_sync(self, expect_success=True):
     # We are calling the sync method directly here, and not through the view,
     # so that the result of sync is directly analyzed
     request = self._build_full_request_mock('admin:index')
     sync_success = kubernetes.sync(request)
     self.assertEquals(sync_success, expect_success)
Exemple #7
0
 def save_model(self, request, obj, form, change):
     super().save_model(request, obj, form, change)
     kubernetes.sync(request)