Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
feudal
feudalBackend
Commits
179c1bb1
Commit
179c1bb1
authored
Jun 15, 2018
by
Lukas Burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add publish by site logic
parent
99fba34f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
15 deletions
+56
-15
django_backend/backend/auth/v1/client_views.py
django_backend/backend/auth/v1/client_views.py
+16
-8
django_backend/backend/clientapi/serializers.py
django_backend/backend/clientapi/serializers.py
+1
-1
django_backend/backend/clientapi/views.py
django_backend/backend/clientapi/views.py
+1
-0
django_backend/backend/models.py
django_backend/backend/models.py
+38
-6
No files found.
django_backend/backend/auth/v1/client_views.py
View file @
179c1bb1
...
...
@@ -131,7 +131,8 @@ def _resource_authorized_apiclient(request):
and
name
.
startswith
(
'amq.gen-'
)
)
or
(
resource
==
'exchange'
and
name
==
RabbitMQInstance
.
load
().
exchange
# TODO
#and name in RabbitMQInstance.load().exchanges
and
not
'write'
in
permission
)
...
...
@@ -209,13 +210,20 @@ def topic_endpoint(request):
user
=
_apiclient_get
(
request
)
if
user
:
routing_key
=
request
.
POST
.
get
(
'routing_key'
,
''
)
if
routing_key
.
startswith
(
'service.'
):
match
=
re
.
search
(
'service.(.+)'
,
routing_key
)
if
match
:
service_name
=
match
.
group
(
1
)
for
service
in
user
.
site
.
services
.
all
():
if
service_name
==
service
.
name
:
return
ALLOW
if
name
==
'deployments'
:
if
routing_key
.
startswith
(
'service.'
):
match
=
re
.
search
(
'service.(.+)'
,
routing_key
)
if
match
:
service_name
=
match
.
group
(
1
)
for
service
in
user
.
site
.
services
.
all
():
if
service_name
==
service
.
name
:
return
ALLOW
elif
name
==
'sites'
:
LOGGER
.
debug
(
routing_key
)
if
routing_key
==
user
.
site
.
name
:
return
ALLOW
else
:
LOGGER
.
error
(
"Client of site %s tried to access site %s"
,
user
.
site
,
routing_key
)
LOGGER
.
error
(
'Authorization check for topic failed for %s'
,
request
.
POST
)
return
DENY
django_backend/backend/clientapi/serializers.py
View file @
179c1bb1
...
...
@@ -55,4 +55,4 @@ class SiteSerializer(serializers.Serializer):
class
RabbitMQInstanceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
models
.
RabbitMQInstance
fields
=
[
'vhost'
,
'exchange'
]
fields
=
[
'vhost'
]
django_backend/backend/clientapi/views.py
View file @
179c1bb1
...
...
@@ -34,6 +34,7 @@ class ConfigurationView(views.APIView):
'rabbitmq_config'
:
RabbitMQInstanceSerializer
(
RabbitMQInstance
.
load
(),
).
data
,
'site'
:
request
.
user
.
site
.
name
,
}
return
Response
(
response
)
...
...
django_backend/backend/models.py
View file @
179c1bb1
...
...
@@ -44,6 +44,9 @@ class SingletonModel(models.Model):
obj
.
set_cache
()
return
cache
.
get
(
cls
.
__name__
)
def
exchanges_default
():
return
[]
# clients are registerred at rabbitmq, when they are assigned to a site
# (because we only then know what services they provide)
...
...
@@ -56,9 +59,10 @@ class RabbitMQInstance(SingletonModel):
max_length
=
150
,
default
=
'%2f'
,
)
exchange
=
models
.
CharField
(
max_length
=
150
,
default
=
'deployments'
,
exchanges
=
JSONField
(
default
=
exchanges_default
,
null
=
True
,
blank
=
True
,
)
port
=
models
.
IntegerField
(
default
=
15672
,
...
...
@@ -87,12 +91,17 @@ class RabbitMQInstance(SingletonModel):
def
_init_exchanges
(
self
,
channel
):
channel
.
exchange_declare
(
exchange
=
self
.
exchange
,
exchange
=
'deployments'
,
durable
=
True
,
auto_delete
=
False
,
exchange_type
=
'topic'
,
)
channel
.
exchange_declare
(
exchange
=
'sites'
,
durable
=
True
,
auto_delete
=
False
,
exchange_type
=
'topic'
,
)
# TODO put in config
channel
.
exchange_declare
(
exchange
=
'update'
,
durable
=
True
,
...
...
@@ -154,11 +163,18 @@ class RabbitMQInstance(SingletonModel):
# PUBLIC API
def
publish_by_service
(
self
,
service
,
msg
):
self
.
_publish
(
self
.
exchange
,
'deployments'
,
service
.
routing_key
,
msg
,
)
def
publish_by_site
(
self
,
site
,
msg
):
self
.
_publish
(
'sites'
,
site
.
name
,
msg
,
)
def
publish_to_webpage
(
self
,
user
,
msg
):
# noise
# LOGGER.debug('Signalling webpage of user %s', user)
...
...
@@ -920,6 +936,22 @@ class DeploymentTaskItem(models.Model):
self
.
questionnaire
=
answers
self
.
save
()
# publish the task item
self
.
publish
()
# only used when we got a questionnaire_answered
def
publish
(
self
):
# mitigating circular dependencies here
from
.clientapi.serializers
import
DeploymentTaskSerializer
data
=
DeploymentTaskSerializer
(
self
.
task
).
data
data
[
'questionnaire'
]
=
self
.
questionnaire
RabbitMQInstance
.
load
().
publish_by_site
(
self
.
site
,
json
.
dumps
(
data
),
)
def
__str__
(
self
):
return
"{}@{}#{}"
.
format
(
self
.
task
,
...
...
Write
Preview
Markdown
is supported
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