Skip to content

Commit

Permalink
Release 0.1.3
Browse files Browse the repository at this point in the history
Changelog:

* Fix bugs in GUI
* Fix bug with search in API
* Add error page
* Add new hook types
* Hide encrypted values in templates

See merge request cloud/polemarch!50
  • Loading branch information
onegreyonewhite committed Dec 26, 2017
2 parents 4b46f96 + 7101427 commit 9327f6d
Show file tree
Hide file tree
Showing 40 changed files with 544 additions and 188 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@ release_pypi:
- twine upload -u ${PYPI_UPLOAD_NAME} -p ${PYPI_UPLOAD_PASSWORD} dist/*.tar.gz
allow_failure: true
when: manual
artifacts:
name: "release-rpm-${CI_BUILD_REF_NAME}.${CI_BUILD_ID}"
paths:
- dist/
2 changes: 1 addition & 1 deletion .pep8
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ exclude = ./polemarch/*/migrations/*,./polemarch/main/settings*.py,.tox/*,./etc/

[flake8]
ignore = E221,E222,E121,E123,E126,E226,E24,E704,E116,E731,E722,E741
exclude = ./polemarch/*/migrations/*,./polemarch/main/settings*.py,.tox/*,./etc/*,./*/__init__.py,./t_openstack.py
exclude = ./polemarch/*/migrations/*,./polemarch/main/settings*.py,.tox/*,./etc/*,./*/__init__.py,./t_openstack.py,./polemarch/projects/*
2 changes: 1 addition & 1 deletion LICENSE_NAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AGPLv3+
AGPLv3+ or Proprietary
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Polemarch
=========

.. image:: https://readthedocs.org/projects/polemarch/badge/?version=stable
:target: http://polemarch.readthedocs.io/en/stable/?badge=stable
:alt: Documentation Status

**Polemarch** is service for orchestration infrastructure by ansible.
Simply WEB gui for orchestration infrastructure by ansible playbooks.

Expand Down
3 changes: 2 additions & 1 deletion deb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ chown -R $(USER):$(USER) /var/log/$(NAME)
chown -R $(USER):$(USER) /var/run/$(NAME)
chown -R $(USER):$(USER) /var/lock/$(NAME)
# making migration and activate services
sudo -H -u $(USER) /opt/$(NAME)/bin/polemarchctl migrate
# sudo -H -u $(USER) /opt/$(NAME)/bin/polemarchctl migrate
su - $(USER) -c "/opt/$(NAME)/bin/polemarchctl migrate"
systemctl daemon-reload
systemctl enable polemarchweb.service
systemctl enable polemarchworker.service
Expand Down
2 changes: 2 additions & 0 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ To load the saved data, use:

sudo -u polemarch /opt/polemarch/bin/polemarchctl loaddata /home/polemarch/backup.json

But more faster backup is SQL backup and projects dir. We strongly recommended this manual backup in production.


Update
------
Expand Down
2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .environment import prepare_environment

__version__ = "0.1.2"
__version__ = "0.1.3"

def _main(**kwargs):
# pylint: disable=unused-variable
Expand Down
2 changes: 1 addition & 1 deletion polemarch/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class HistoryModelViewSet(GenericViewSet,


class ModelViewSetSet(GenericViewSet, viewsets.ModelViewSet):
pass
POST_WHITE_LIST = []


class NonModelsViewSet(GenericViewSet):
Expand Down
8 changes: 5 additions & 3 deletions polemarch/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ def has_object_permission(self, request, view, obj):
return True
if request.user == obj: # nocv
return True
if request.method not in permissions.SAFE_METHODS: # nocv
return obj.editable_by(request.user)
return obj.viewable_by(request.user) # nocv
if request.method in permissions.SAFE_METHODS: # nocv
return obj.viewable_by(request.user) # nocv
if view.action in view.POST_WHITE_LIST: # nocv
return obj.viewable_by(request.user) # nocv
return obj.editable_by(request.user)


class SuperUserPermission(ModelPermission):
Expand Down
3 changes: 2 additions & 1 deletion polemarch/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class HostFilter(_BaseHGIFilter):
class Meta:
model = models.Host
fields = ('id',
'name',)
'name',
'type')


class GroupFilter(_BaseHGIFilter):
Expand Down
1 change: 1 addition & 0 deletions polemarch/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class Meta:
'id',
'name',
'type',
'when',
'recipients'
)

Expand Down
11 changes: 9 additions & 2 deletions polemarch/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class TeamViewSet(base.PermissionMixin, base.ModelViewSetSet):
serializer_class_one = serializers.OneTeamSerializer
filter_class = filters.TeamFilter

def get_extra_queryset(self):
return self.queryset


class HostViewSet(base.PermissionMixin, base.ModelViewSetSet):
model = serializers.models.Host
Expand Down Expand Up @@ -109,6 +112,7 @@ class ProjectViewSet(base.PermissionMixin, base.ModelViewSetSet,
serializer_class = serializers.ProjectSerializer
serializer_class_one = serializers.OneProjectSerializer
filter_class = filters.ProjectFilter
POST_WHITE_LIST = ['sync', 'execute_playbook', 'execute_module']

@list_route(methods=["get"], url_path="supported-repos")
def supported_repos(self, request):
Expand Down Expand Up @@ -146,6 +150,7 @@ class PeriodicTaskViewSet(base.LimitedPermissionMixin, base.ModelViewSetSet):
serializer_class = serializers.PeriodictaskSerializer
serializer_class_one = serializers.OnePeriodictaskSerializer
filter_class = filters.PeriodicTaskFilter
POST_WHITE_LIST = ['execute']

@detail_route(methods=["post"])
def execute(self, request, *args, **kwargs):
Expand All @@ -158,6 +163,7 @@ class HistoryViewSet(base.LimitedPermissionMixin, base.HistoryModelViewSet):
serializer_class = serializers.HistorySerializer
serializer_class_one = serializers.OneHistorySerializer
filter_class = filters.HistoryFilter
POST_WHITE_LIST = ['cancel']

@detail_route(methods=["get"])
def raw(self, request, *args, **kwargs):
Expand Down Expand Up @@ -190,6 +196,7 @@ class TemplateViewSet(base.PermissionMixin, base.ModelViewSetSet):
serializer_class = serializers.TemplateSerializer
serializer_class_one = serializers.OneTemplateSerializer
filter_class = filters.TemplateFilter
POST_WHITE_LIST = ['execute']

@list_route(methods=["get"], url_path="supported-kinds")
def supported_kinds(self, request):
Expand All @@ -210,8 +217,8 @@ class HookViewSet(base.ModelViewSetSet):
@list_route(['get'])
def types(self, request):
data = dict(
types=self.model.handlers.list(),
when=self.model.handlers.when_types
types=self.model.handlers.list().keys(),
when=self.model.handlers.when_types_names
)
return base.Response(data, 200).resp

Expand Down
18 changes: 18 additions & 0 deletions polemarch/main/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ def on_execution(self, message):

def after_execution(self, message):
return self.send(message, when='after_execution')

def on_user_add(self, message):
return self.send(message, when='on_user_add')

def on_user_upd(self, message):
return self.send(message, when='on_user_upd')

def on_user_del(self, message):
return self.send(message, when='on_user_del')

def on_object_add(self, message):
return self.send(message, when='on_object_add')

def on_object_upd(self, message):
return self.send(message, when='on_object_upd')

def on_object_del(self, message):
return self.send(message, when='on_object_del')
60 changes: 58 additions & 2 deletions polemarch/main/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import
import os
import json

from collections import OrderedDict
import django_celery_beat
from django_celery_beat.models import IntervalSchedule, CrontabSchedule
from django.db.models import signals
Expand All @@ -13,12 +13,39 @@
from .vars import Variable
from .hosts import Host, Group, Inventory
from .projects import Project
from .users import UserGroup, ACLPermission
from .users import BaseUser, UserGroup, ACLPermission
from .tasks import Task, PeriodicTask, History, HistoryLines, Template
from .hooks import Hook
from ..validators import RegexValidator
from ..exceptions import UnknownTypeException
from ..utils import raise_context, AnsibleArgumentsReference
from ..tasks import SendHook


#####################################
# FUNCTIONS
#####################################
def send_hook(when, target):
msg = OrderedDict(when=when)
msg['target'] = target
SendHook.delay(when, msg)


@raise_context()
def send_user_hook(when, instance):
send_hook(
when, OrderedDict(
user_id=instance.id,
username=instance.username,
admin=instance.is_staff
)
)


@raise_context()
def send_polemarch_models(when, instance, **kwargs):
target = OrderedDict(id=instance.id, name=instance.name, **kwargs)
send_hook(when, target)


#####################################
Expand Down Expand Up @@ -164,3 +191,32 @@ def check_hook(instance, **kwargs):
errors = instance.handlers.validate(instance)
if errors:
raise ValidationError(errors)


@receiver([signals.post_save, signals.post_delete], sender=BaseUser,
dispatch_uid='user_add_hook')
def user_add_hook(instance, **kwargs):
created = kwargs.get('created', None)
when = None
if created is None:
when = "on_user_del"
elif not created:
when = "on_user_upd"
elif created:
when = "on_user_add"
send_user_hook(when, instance) if when else None


@receiver([signals.post_save, signals.post_delete], sender=Project)
@receiver([signals.post_save, signals.post_delete], sender=PeriodicTask)
@receiver([signals.post_save, signals.post_delete], sender=Inventory)
@receiver([signals.post_save, signals.post_delete], sender=Group)
@receiver([signals.post_save, signals.post_delete], sender=Host)
def polemarch_hook(instance, **kwargs):
created = kwargs.get('created', None)
when = "on_object_add"
if created is None:
when = "on_object_del"
elif not created:
when = "on_object_upd"
send_polemarch_models(when, instance)
12 changes: 11 additions & 1 deletion polemarch/main/models/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@


class HookHandlers(ModelHandlers):
when_types = ['on_execution', 'after_execution']
when_types_names = dict(
on_execution="Before start task",
after_execution="After end task",
on_user_add="When new user register",
on_user_upd="When user update data",
on_user_del="When user was removed",
on_object_add="When new Polemarch object was added",
on_object_upd="When Polemarch object was updated",
on_object_del="When Polemarch object was removed",
)
when_types = when_types_names.keys()

def get_handler(self, obj):
return self[obj.type](obj, self.when_types, **self.opts(obj.type))
Expand Down
20 changes: 18 additions & 2 deletions polemarch/main/models/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def _convert_to_data(self, value):
else:
raise ValueError("Unknown data type set.")

def keep_encrypted(self, new_vars):
if not self.template_data:
return new_vars
old_vars = self.data['vars']
for key in new_vars.keys():
if new_vars[key] == '[~~ENCRYPTED~~]':
new_vars[key] = old_vars.get(key, new_vars[key])
return new_vars

def set_data(self, value):
data = self._convert_to_data(value)
project_id = data.pop('project', None)
Expand All @@ -231,6 +240,7 @@ def set_data(self, value):
self.inventory = Inventory.objects.get(pk=int(inventory_id)).id
except (ValueError, TypeError, Inventory.DoesNotExist):
self.inventory = inventory_id
data['vars'] = self.keep_encrypted(data['vars'])
self.template_data = json.dumps(data)

def __setattr__(self, key, value):
Expand Down Expand Up @@ -422,12 +432,18 @@ def editable_by(self, user):
return self.project.editable_by(user)
return self.inventory.editable_by(user)

def _inventory_editable(self, user):
return self.inventory and self.inventory.editable_by(user)

def _inventory_viewable(self, user):
return not self.inventory or self.inventory.viewable_by(user)

def viewable_by(self, user):
return (
self.project.editable_by(user) or
self.inventory.editable_by(user) or
self._inventory_editable(user) or
(self.initiator == user.id and self.initiator_type == "users") or
(self.project.viewable_by(user) & self.inventory.viewable_by(user))
(self.project.viewable_by(user) & self._inventory_viewable(user))
)


Expand Down
11 changes: 9 additions & 2 deletions polemarch/main/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@

{% if user.is_superuser %}
var is_superuser = true
{% else %}
var is_superuser = false
var is_staff = true
{% else %}
{% if user.is_staff %}
var is_superuser = true
var is_staff = true
{% else %}
var is_superuser = false
var is_staff = false
{% endif %}
{% endif %}

window.pmStaticPath = "{% static '' %}";
Expand Down
Loading

0 comments on commit 9327f6d

Please sign in to comment.