stages/authenticator: vendor otp (#6741)
* initial import Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update imports Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove email and hotp for now Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove things we don't need and clean up Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial merge static Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial merge totp Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more fixes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migrations Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update webui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add system migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more cleanup, add doctests to test_runner Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more cleanup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fixup more lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * cleanup last tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update docstrings Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * implement SerializerModel Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix web format Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
		
							
								
								
									
										47
									
								
								lifecycle/system_migrations/otp_merge.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								lifecycle/system_migrations/otp_merge.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| # flake8: noqa | ||||
| from os import system | ||||
|  | ||||
| from lifecycle.migrate import BaseMigration | ||||
|  | ||||
| SQL_STATEMENT = """ | ||||
| BEGIN TRANSACTION; | ||||
| DELETE FROM django_migrations WHERE app = 'otp_static'; | ||||
| DELETE FROM django_migrations WHERE app = 'otp_totp'; | ||||
| -- Rename tables (static) | ||||
| ALTER TABLE otp_static_staticdevice RENAME TO authentik_stages_authenticator_static_staticdevice; | ||||
| ALTER TABLE otp_static_statictoken RENAME TO authentik_stages_authenticator_static_statictoken; | ||||
| ALTER SEQUENCE otp_static_statictoken_id_seq RENAME TO authentik_stages_authenticator_static_statictoken_id_seq; | ||||
| ALTER SEQUENCE otp_static_staticdevice_id_seq RENAME TO authentik_stages_authenticator_static_staticdevice_id_seq; | ||||
| -- Rename tables (totp) | ||||
| ALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice; | ||||
| ALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq; | ||||
| COMMIT;""" | ||||
|  | ||||
|  | ||||
| class Migration(BaseMigration): | ||||
|     def needs_migration(self) -> bool: | ||||
|         self.cur.execute( | ||||
|             "select * from information_schema.tables WHERE table_name='otp_static_staticdevice'" | ||||
|         ) | ||||
|         return bool(self.cur.rowcount) | ||||
|  | ||||
|     def system_crit(self, command): | ||||
|         retval = system(command)  # nosec | ||||
|         if retval != 0: | ||||
|             raise Exception("Migration error") | ||||
|  | ||||
|     def run(self): | ||||
|         self.cur.execute(SQL_STATEMENT) | ||||
|         self.con.commit() | ||||
|         self.system_crit( | ||||
|             "./manage.py migrate authentik_stages_authenticator_static 0008_initial --fake" | ||||
|         ) | ||||
|         self.system_crit( | ||||
|             "./manage.py migrate authentik_stages_authenticator_static 0009_throttling --fake" | ||||
|         ) | ||||
|         self.system_crit( | ||||
|             "./manage.py migrate authentik_stages_authenticator_totp 0008_initial --fake" | ||||
|         ) | ||||
|         self.system_crit( | ||||
|             "./manage.py migrate authentik_stages_authenticator_totp 0009_auto_20190420_0723 --fake" | ||||
|         ) | ||||
		Reference in New Issue
	
	Block a user
	 Jens L
					Jens L