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
e7a3b0f4
Commit
e7a3b0f4
authored
Jul 05, 2018
by
Lukas Burgey
Browse files
Change some properties
parent
036b2b6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/clientapi/serializers.py
View file @
e7a3b0f4
...
...
@@ -9,7 +9,9 @@ from .. import models, serializers as backend_serializers
class
ServiceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
models
.
Service
fields
=
[
'name'
]
fields
=
[
'name'
,
]
class
UserSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -49,7 +51,6 @@ class DeploymentStateSerializer(serializers.Serializer):
id
=
serializers
.
IntegerField
()
state_target
=
serializers
.
CharField
()
user
=
UserSerializer
()
service
=
ServiceSerializer
()
key
=
backend_serializers
.
SSHPublicKeySerializer
()
...
...
django_backend/backend/frontend/serializers.py
View file @
e7a3b0f4
...
...
@@ -22,15 +22,18 @@ class ServiceSerializer(serializers.ModelSerializer):
'name'
,
'site'
,
'groups'
,
'description'
,
]
class
DeploymentStateItemSerializer
(
serializers
.
ModelSerializer
):
service
=
ServiceSerializer
()
services
=
ServiceSerializer
(
many
=
True
)
key
=
backend_serializers
.
SSHPublicKeyRefSerializer
()
site
=
SiteSerializer
()
questionnaire
=
serializers
.
JSONField
()
credentials
=
serializers
.
JSONField
()
group
=
backend_serializers
.
GroupSerializer
()
class
Meta
:
model
=
models
.
DeploymentStateItem
...
...
@@ -42,6 +45,8 @@ class DeploymentStateItemSerializer(serializers.ModelSerializer):
'credentials'
,
'key'
,
'service'
,
'services'
,
'group'
,
]
...
...
@@ -62,6 +67,7 @@ class DeploymentStateSerializer(serializers.ModelSerializer):
class
DeploymentSerializer
(
serializers
.
ModelSerializer
):
sites
=
SiteSerializer
(
many
=
True
)
service
=
ServiceSerializer
()
services
=
ServiceSerializer
(
many
=
True
)
ssh_keys
=
backend_serializers
.
SSHPublicKeyRefSerializer
(
many
=
True
)
...
...
@@ -71,6 +77,7 @@ class DeploymentSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
models
.
Deployment
fields
=
[
'sites'
,
'service'
,
'services'
,
'group'
,
...
...
@@ -89,7 +96,7 @@ class UserSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
models
.
User
fields
=
[
'
email
'
,
'
profile_name
'
,
'groups'
,
'id'
,
'ssh_keys'
,
...
...
django_backend/backend/models.py
View file @
e7a3b0f4
...
...
@@ -271,6 +271,15 @@ class User(AbstractUser):
editable
=
False
,
)
@
property
def
profile_name
(
self
):
if
'email'
in
self
.
userinfo
:
return
self
.
userinfo
[
'email'
]
elif
'name'
:
return
self
.
userinfo
[
'name'
]
else
:
return
self
.
id
@
property
def
deployment_states
(
self
):
states
=
[]
...
...
@@ -317,13 +326,11 @@ class User(AbstractUser):
if
'sub'
not
in
userinfo
:
raise
Exception
(
'Missing attribute in userinfo: sub'
)
sub
=
userinfo
[
'sub'
]
username
=
sub
email
=
''
if
'email'
not
in
userinfo
:
username
=
sub
email
=
''
else
:
if
'email'
in
userinfo
:
username
=
userinfo
[
'email'
]
email
=
userinfo
[
'email'
]
user
=
cls
(
user_type
=
'oidcuser'
,
...
...
@@ -421,6 +428,11 @@ class User(AbstractUser):
def
update_userinfo
(
self
,
userinfo
):
self
.
userinfo
=
userinfo
self
.
save
()
if
'sub'
not
in
userinfo
:
raise
Exception
(
'Missing attribute in userinfo: sub'
)
sub
=
userinfo
[
'sub'
]
groups
=
userinfo
.
get
(
'groups'
,
[])
# FIXME probably inefficient
self
.
groups
.
clear
()
...
...
@@ -459,7 +471,6 @@ class User(AbstractUser):
key
.
save
()
class
Site
(
models
.
Model
):
client
=
models
.
OneToOneField
(
User
,
...
...
@@ -581,13 +592,21 @@ class SSHPublicKey(models.Model):
return
'[SSHKey:{}] {}'
.
format
(
self
,
msg
)
# Deployment describes the credential state per user (and site) as it is supposed to be
# Deployment describes the supposed state of the users ssh keys at either:
# - a group (and and the services associated with the group)
# - a single service
#
# (exception: if is_active=False the ssh_keys contain the keys to be deployed
# if the deployment is reactivated)
# DeploymentState track the state of a single ssh key at either:
# - a group (and and the services associated with the group)
# - a single service
# DeploymentStateItem track the acknowledgements from the clients for either :
# - the sites that handle the associated group (i.e provide a service for members of the group)
# - the sites that provide the associated service
#
# DeploymentState is what is sent to the clients via rabbitmq
# The DeploymentStateItem track the acknowledgements from the clients
# Note: two possible kinds of Deployment:
# (group is None and service is not None) or
# (group is not None and service is None)
class
Deployment
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
...
...
@@ -602,12 +621,6 @@ class Deployment(models.Model):
null
=
True
,
blank
=
True
,
)
# only used when group is set and service is not set
@
property
def
services
(
self
):
if
self
.
group
is
not
None
:
return
self
.
group
.
services
.
all
()
return
None
service
=
models
.
ForeignKey
(
Service
,
...
...
@@ -625,6 +638,18 @@ class Deployment(models.Model):
default
=
True
,
)
# only used when group is not None and service is None
@
property
def
services
(
self
):
if
self
.
group
is
not
None
:
return
self
.
group
.
services
.
all
()
return
None
# only used when group is not None and service is None
@
property
def
sites
(
self
):
return
Site
.
objects
.
filter
(
services__groups
=
self
.
group
).
distinct
()
# get a deployment for a user/service.
# if it does not exist it is created
@
classmethod
...
...
@@ -774,6 +799,10 @@ class DeploymentState(models.Model):
def
service
(
self
):
return
self
.
deployment
.
service
@
property
def
services
(
self
):
return
self
.
deployment
.
services
@
property
def
group
(
self
):
return
self
.
deployment
.
group
...
...
@@ -811,13 +840,13 @@ class DeploymentState(models.Model):
)
deploy
.
save
()
elif
deployment
.
group
is
not
None
:
for
service
in
deployment
.
group
.
services
.
all
():
for
site
in
service
.
site
.
all
()
:
deploy
=
DeploymentStateItem
(
parent
=
state
,
site
=
site
,
)
deploy
.
save
()
# every site which provides a service for group
for
site
in
deployment
.
sites
:
deploy
=
DeploymentStateItem
(
parent
=
state
,
site
=
site
,
)
deploy
.
save
()
return
state
...
...
@@ -914,13 +943,21 @@ class DeploymentStateItem(models.Model):
def
user
(
self
):
return
self
.
parent
.
user
@
property
def
key
(
self
):
return
self
.
parent
.
key
@
property
def
service
(
self
):
return
self
.
parent
.
service
@
property
def
key
(
self
):
return
self
.
parent
.
key
def
group
(
self
):
return
self
.
parent
.
group
@
property
def
services
(
self
):
return
self
.
parent
.
services
.
filter
(
groups
=
self
.
group
)
# STATE transitions
# user: deployment requested
...
...
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