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
b183e5dd
Commit
b183e5dd
authored
Sep 24, 2020
by
lukas.burgey
Browse files
Lint the deployments module
parent
15b4d7c8
Pipeline
#110706
passed with stage
in 1 minute and 24 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
feudal/backend/models/deployments.py
View file @
b183e5dd
...
...
@@ -60,21 +60,15 @@ def user_info_default(): # pragma: no cover
def
get_deployment
(
user
,
vo
=
None
,
service
=
None
):
if
vo
is
not
None
and
service
is
not
None
:
raise
ValueError
(
'Cannot create deployment for both vo and service'
)
if
vo
is
not
None
:
if
vo
is
not
None
and
service
is
None
:
# get_deployment updates automatically
return
VODeployment
.
get_deployment
(
user
,
vo
)
if
service
is
not
None
:
if
service
is
not
None
and
vo
is
None
:
# get_deployment updates automatically
return
ServiceDeployment
.
get_deployment
(
user
,
service
)
deps
=
Deployment
.
objects
.
filter
(
user
=
user
)
for
dep
in
deps
:
dep
.
update
()
return
deps
raise
ValueError
(
"Exactly one of 'vo' or 'service' must be set"
)
class
Deployment
(
PolymorphicModel
):
...
...
@@ -209,17 +203,6 @@ class VODeployment(Deployment):
def
routing_key
(
self
):
return
self
.
vo
.
name
@
classmethod
def
create
(
cls
,
*
args
,
**
kwargs
):
user
=
kwargs
.
get
(
'user'
)
vo
=
kwargs
.
get
(
'vo'
)
if
vo
not
in
user
.
vos
.
all
():
raise
ValueError
(
'User is not permitted to have a deployment of this vo!'
)
return
cls
(
*
args
,
**
kwargs
)
# _assure_states_exist creates missing DeploymentState for this deployment
# returns True if new states were created
def
_assure_states_exist
(
self
):
...
...
@@ -276,19 +259,6 @@ class ServiceDeployment(Deployment):
def
routing_key
(
self
):
return
self
.
service
.
name
@
classmethod
def
create
(
cls
,
*
args
,
**
kwargs
):
user
=
kwargs
.
get
(
'user'
)
service
=
kwargs
.
get
(
'service'
)
# check if one of the users vos can be used for the service
for
vo
in
user
.
vos
.
all
():
if
vo
in
service
.
vos
.
all
():
return
cls
(
*
args
,
**
kwargs
)
raise
ValueError
(
'User is not permitted to have a deployment of this service!'
)
def
_assure_states_exist
(
self
):
_
,
created
=
DeploymentState
.
get_or_create
(
self
.
user
,
self
.
service
,
self
)
return
created
...
...
@@ -624,7 +594,7 @@ class DeploymentState(models.Model):
for
key
in
self
.
user
.
ssh_keys
.
all
():
CredentialState
.
get_credential_state
(
key
,
self
)
def
_set_state
(
self
,
state
,
publish_to_user
=
False
,
publish_to_client
=
False
):
def
_set_state
(
self
,
state
):
self
.
_assure_credential_states_exist
()
# same state
...
...
@@ -638,12 +608,6 @@ class DeploymentState(models.Model):
self
.
save
()
if
publish_to_user
:
self
.
publish_to_user
()
if
publish_to_client
:
self
.
publish_to_client
()
def
publish_to_user
(
self
):
if
self
.
user
is
None
:
LOGGER
.
debug
(
self
.
msg
(
'publish_to_user: User is None'
))
...
...
@@ -658,10 +622,6 @@ class DeploymentState(models.Model):
)
def
publish_to_client
(
self
):
# no need to publish if not pending
if
not
self
.
is_pending
:
return
self
.
audit_log_request
()
LOGGER
.
log
(
settings
.
DEBUGX_LOG_LEVEL
,
self
.
msg
(
'publish_to_client'
))
...
...
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