Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
3b116b81
Commit
3b116b81
authored
Dec 11, 2017
by
Lukas Burgey
Browse files
Add updating of rabbitmq permissions
parent
6a17098f
Changes
4
Show whitespace changes
Inline
Side-by-side
django_backend/backend/clientapi/urls.py
View file @
3b116b81
...
...
@@ -11,5 +11,5 @@ from . import views
urlpatterns
=
[
# url(r'^', include(router.urls)),
url
(
r
'^deployments'
,
views
.
DeploymentsView
.
as_view
()),
url
(
r
'^
services
'
,
views
.
Service
View
.
as_view
()),
url
(
r
'^
config
'
,
views
.
Configuration
View
.
as_view
()),
]
django_backend/backend/clientapi/views.py
View file @
3b116b81
...
...
@@ -2,6 +2,7 @@
from
rest_framework
import
generics
from
rest_framework.authentication
import
TokenAuthentication
from
..
import
rabbitmq
from
.
import
serializers
,
models
# authentication class for the client api
...
...
@@ -25,9 +26,15 @@ class DeploymentsView(generics.RetrieveAPIView):
return
d
class
ServiceView
(
generics
.
ListAPIView
):
# the client has to fetch the configuration (like services etc.) here
class
ConfigurationView
(
generics
.
ListAPIView
):
authentication_classes
=
authentication_classes
serializer_class
=
serializers
.
ServiceSerializer
def
get_queryset
(
self
):
return
self
.
request
.
user
.
site
.
services
.
all
()
site
=
self
.
request
.
user
.
site
# we update the rabbitmq permission here, so the
# client can access all of his services, even new ones
rabbitmq
.
RabbitMQInstance
().
update_site
(
site
)
return
site
.
services
.
all
()
django_backend/backend/models.py
View file @
3b116b81
...
...
@@ -58,7 +58,9 @@ class Site(models.Model):
)
name
=
models
.
CharField
(
max_length
=
150
,
unique
=
True
)
description
=
models
.
TextField
(
max_length
=
300
,
blank
=
True
)
last_fetch
=
models
.
DateTimeField
(
default
=
datetime
.
utcfromtimestamp
(
0
))
last_fetch
=
models
.
DateTimeField
(
default
=
make_aware
(
datetime
.
utcfromtimestamp
(
0
)),
editable
=
False
)
def
__str__
(
self
):
return
self
.
name
...
...
django_backend/backend/rabbitmq.py
View file @
3b116b81
...
...
@@ -43,12 +43,10 @@ class RabbitMQInstance:
'read'
:
'^service\.({})$'
.
format
(
services
),
}
# TODO might fail
r
=
requests
.
put
(
set_topic_permission_uri
,
json
=
set_topic_permission_data
,
auth
=
self
.
auth
)
print
(
'RabbitMQ: set_topic_permissions {}'
.
format
(
r
.
status_code
))
r
.
raise_for_status
()
# set permissions for the user
def
set_permissions
(
self
,
site
):
...
...
@@ -65,10 +63,9 @@ class RabbitMQInstance:
'read'
:
permission
,
}
# TODO might fail
r
=
requests
.
put
(
set_permission_uri
,
json
=
set_permission_data
,
auth
=
self
.
auth
)
print
(
'RabbitMQ: set_permissions {}'
.
format
(
r
.
status_code
)
)
r
.
raise_for_status
(
)
# create user at the rabbitmq instance
def
create_user
(
self
,
site
):
...
...
@@ -78,16 +75,14 @@ class RabbitMQInstance:
username
)
print
(
'registerring client {}'
.
format
(
site
.
client
.
username
))
user_creation_data
=
{
'password'
:
str
(
site
.
client
.
auth_token
.
key
),
'tags'
:
''
,
}
# TODO might fail
r
=
requests
.
put
(
user_creation_uri
,
json
=
user_creation_data
,
auth
=
self
.
auth
)
print
(
'RabbitMQ: create_user {}'
.
format
(
r
.
status_code
)
)
r
.
raise_for_status
(
)
# delete user at the rabbitmq instance
def
delete_user
(
self
,
site
):
...
...
@@ -98,15 +93,26 @@ class RabbitMQInstance:
'password'
:
str
(
site
.
client
.
auth_token
.
key
),
'tags'
:
''
,
}
# TODO might fail
r
=
requests
.
delete
(
user_creation_uri
,
json
=
user_creation_data
,
auth
=
self
.
auth
)
print
(
'RabbitMQ: delete_user {}'
.
format
(
r
.
status_code
))
r
.
raise_for_status
()
# PUBLIC API
def
register_site
(
self
,
site
):
print
(
'RabbitMQ: register: {} / {}'
.
format
(
site
.
name
,
site
.
client
.
username
))
self
.
create_user
(
site
)
self
.
set_permissions
(
site
)
self
.
set_topic_permissions
(
site
)
def
update_site
(
self
,
site
):
print
(
'RabbitMQ: update: {} / {}'
.
format
(
site
.
name
,
site
.
client
.
username
))
self
.
set_topic_permissions
(
site
)
def
deregister_site
(
self
,
site
):
print
(
'RabbitMQ: deregister: {} / {}'
.
format
(
site
.
name
,
site
.
client
.
username
))
self
.
delete_user
(
site
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment