Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip][do not merge] Project deletion workflow #3

Open
wants to merge 1 commit into
base: train
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions cc/keystone/cmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from builtins import input

import datetime
import re

import pbr.version
Expand Down Expand Up @@ -462,12 +463,62 @@ def main():
print("failed: %s" % e)


class ProjectDeletion(BaseApp):
"""Perform the project deletion workflow

The project deletion workflow consists of 2 parts:
1. For new disabled projects, set their deletion date
2. Delete projects whose deletion date has passed

The deletion date is passed as a parameter. The command honors
immutability of the projects.
"""
name = 'project_deletion'

def __init__(self):
super(ProjectDeletion, self).__init__()

@classmethod
def add_argument_parser(cls, subparsers):
parser = super(ProjectDeletion, cls).add_argument_parser(subparsers)
parser.add_argument('--delete-after-days', default=None, required=True,
type=int, help=('After how many days delete the '
'projects'))
return parser

@staticmethod
def main():
drivers = backends.load_backends()
resource_manager = drivers['resource_api']

for project_ref in resource_manager.list_projects():
if not project_ref['enabled']:
if 'delete_date' not in project_ref['extra']:
# new disabled project; mark it for deletion
LOG.info('Marking project %s (%s) for deletion',
project_ref['id'], project_ref['name'])
delete_after = CONF.command.delete_after_days
delete_date = (datetime.datetime.now() +
datetime.timedelta(days=delete_after))
project_ref['extra']['delete_date'] = delete_date.isoformat()
resource_manager.update_project(project_ref['id'], project_ref)
else:
# this is an old disabled project; should we delete it?
delete_date = datetime.datetime.fromisoformat(
project_ref['extra']['delete_date'])
if delete_date < datetime.datetime.now():
LOG.info('Deleting project %s (%s)',
project_ref['id'], project_ref['name'])
resource_manager.delete_project(project_ref['id'])


CMDS = [
RepairAssignments,
RepairIdMappings,
RotateSecretKeys,
FernetTokenDoctor,
UserScore,
ProjectDeletion,
]


Expand Down