in source/idea/idea-cluster-manager/src/ideaclustermanager/app/projects/projects_service.py [0:0]
def update_project(self, request: UpdateProjectRequest) -> UpdateProjectResult:
"""
Update a Project
:param request:
:return:
"""
if Utils.is_empty(request):
raise exceptions.invalid_params('request is required')
project = request.project
if Utils.is_empty(project):
raise exceptions.invalid_params('project is required')
if Utils.is_empty(project.project_id):
raise exceptions.invalid_params('project.project_id is required')
existing = self.projects_dao.get_project_by_id(project_id=project.project_id)
if existing is None:
raise exceptions.soca_exception(
error_code=errorcodes.PROJECT_NOT_FOUND,
message=f'project not found for id: {project.project_id}'
)
if Utils.is_not_empty(project.name) and existing['name'] != project.name:
same_name_project = self.projects_dao.get_project_by_name(project.name)
if same_name_project is not None and same_name_project['project_id'] != project.project_id:
raise exceptions.invalid_params(f'project with name: {project.name} already exists')
enable_budgets = Utils.get_as_bool(project.enable_budgets, False)
if enable_budgets:
if project.budget is None or Utils.is_empty(project.budget.budget_name):
raise exceptions.invalid_params('budget.budget_name is required when budgets are enabled')
budget_name = project.budget.budget_name
self.context.aws_util().budgets_get_budget(budget_name)
# none values will be skipped by db update. ensure enabled/disabled cannot be called via update project.
project.enabled = None
# Validate scripts
scripts = project.scripts
if scripts is not None:
if not LaunchScriptsHelper.validate_scripts(scripts):
raise exceptions.invalid_params(constants.SCRIPT_LOCATION_ERROR_MESSAGE)
# Validate security groups and ensure security group is within VPC
if project.security_groups:
vpc_id = self.context.config().get_string('cluster.network.vpc_id')
for security_group_id in project.security_groups:
if not self.context.aws_util().is_security_group_available(security_group_id=security_group_id,vpc_id=vpc_id):
self.logger.error(f'{security_group_id} is not a valid security group that can be attached')
raise exceptions.invalid_params(constants.SECURITY_GROUP_ERROR_MESSAGE)
# Update VDI role if new policies differ from existing policies
policy_arns = Utils.get_as_string_list(project.policy_arns, [])
existing_policies = Utils.get_value_as_list('policy_arns', existing, [])
policies_to_detach = set(existing_policies) - set(policy_arns)
policies_to_attach = set(policy_arns) - set(existing_policies)
if policies_to_detach or policies_to_attach:
for policy_arn in policy_arns:
if not self.context.aws_util().is_policy_valid(policy_arn=policy_arn):
self.logger.error(f'{policy_arn} is not a valid policy arn that can be attached')
raise exceptions.invalid_params(constants.POLICY_ARN_ERROR_MESSAGE)
self._update_vdi_role(project_name=project.name, policies_to_detach=policies_to_detach, policies_to_attach=policies_to_attach)
db_updated = self.projects_dao.update_project(self.projects_dao.convert_to_db(project))
updated_project = self.projects_dao.convert_from_db(db_updated)
return UpdateProjectResult(
project=updated_project
)