From ae5f57645fc89de0bdb7296f3f9c82c0c8594c1e Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 08:24:18 -0500 Subject: [PATCH 01/12] Update support wording --- capsulflask/templates/support.html | 7 ------- 1 file changed, 7 deletions(-) diff --git a/capsulflask/templates/support.html b/capsulflask/templates/support.html index 07888f1..855bdf7 100644 --- a/capsulflask/templates/support.html +++ b/capsulflask/templates/support.html @@ -12,13 +12,6 @@ {% endblock %} {% block subcontent %} -

- Note: We maintain a searchable archive of all support emails at - https://lists.cyberia.club/~cyberia/support -

-

- If you do not want your mail to appear in a public archive, email capsul@cyberia.club instead. -

Please describe your problem or feature request, and we will do our best to get back to you promptly. Thank you very much.

-- 2.40.1 From dbe75dd868d63465f784be03fb02765fef5b46a8 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 08:26:25 -0500 Subject: [PATCH 02/12] * --- capsulflask/templates/support.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capsulflask/templates/support.html b/capsulflask/templates/support.html index 855bdf7..71f0d93 100644 --- a/capsulflask/templates/support.html +++ b/capsulflask/templates/support.html @@ -7,7 +7,7 @@

SUPPORT

{% endblock %} -- 2.40.1 From c6380f292fa74d23586191a9fb0d0569fb87d4f1 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 08:27:38 -0500 Subject: [PATCH 03/12] Add ops --- capsulflask/templates/support.html | 1 + 1 file changed, 1 insertion(+) diff --git a/capsulflask/templates/support.html b/capsulflask/templates/support.html index 71f0d93..0f14579 100644 --- a/capsulflask/templates/support.html +++ b/capsulflask/templates/support.html @@ -8,6 +8,7 @@
support@cyberia.club (private) + ops@cyberia.club (public)
{% endblock %} -- 2.40.1 From 59b72adefb976828268d63d71e1929fcb9850d41 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 08:28:21 -0500 Subject: [PATCH 04/12] Add linebreak to support page --- capsulflask/templates/support.html | 1 + 1 file changed, 1 insertion(+) diff --git a/capsulflask/templates/support.html b/capsulflask/templates/support.html index 0f14579..32373e0 100644 --- a/capsulflask/templates/support.html +++ b/capsulflask/templates/support.html @@ -8,6 +8,7 @@
support@cyberia.club (private) +
ops@cyberia.club (public)
{% endblock %} -- 2.40.1 From dc8da3170b98da06b5ab160d4eaaf5abcbbb5d16 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 08:29:33 -0500 Subject: [PATCH 05/12] Remove ops linky --- capsulflask/templates/support.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/capsulflask/templates/support.html b/capsulflask/templates/support.html index 32373e0..3d4fe7c 100644 --- a/capsulflask/templates/support.html +++ b/capsulflask/templates/support.html @@ -7,9 +7,7 @@

SUPPORT

{% endblock %} -- 2.40.1 From a9c4ae757209582b3865a65d03b75134decb8889 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 09:33:32 -0500 Subject: [PATCH 06/12] Add archlinux, bump everything' --- capsulflask/db.py | 2 +- capsulflask/schema_migrations/19_down_os_updates.sql | 6 ++++++ capsulflask/schema_migrations/19_up_os_updates.sql | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 capsulflask/schema_migrations/19_down_os_updates.sql create mode 100644 capsulflask/schema_migrations/19_up_os_updates.sql diff --git a/capsulflask/db.py b/capsulflask/db.py index 23b3621..ddd7081 100644 --- a/capsulflask/db.py +++ b/capsulflask/db.py @@ -43,7 +43,7 @@ def init_app(app, is_running_server): hasSchemaVersionTable = False actionWasTaken = False schemaVersion = 0 - desiredSchemaVersion = 18 + desiredSchemaVersion = 19 cursor = connection.cursor() diff --git a/capsulflask/schema_migrations/19_down_os_updates.sql b/capsulflask/schema_migrations/19_down_os_updates.sql new file mode 100644 index 0000000..9598409 --- /dev/null +++ b/capsulflask/schema_migrations/19_down_os_updates.sql @@ -0,0 +1,6 @@ +DELETE FROM os_images WHERE id = 'guixsystem130'; +DELETE FROM os_images WHERE id = 'archlinux'; +UPDATE os_images SET deprecated = FALSE WHERE id = 'guixsystem120'; +UPDATE os_images SET description = 'Ubuntu 20.04 LTS (Fossa)' WHERE id = 'ubuntu20'; + +UPDATE schemaversion SET version = 18; diff --git a/capsulflask/schema_migrations/19_up_os_updates.sql b/capsulflask/schema_migrations/19_up_os_updates.sql new file mode 100644 index 0000000..4237e4a --- /dev/null +++ b/capsulflask/schema_migrations/19_up_os_updates.sql @@ -0,0 +1,10 @@ +INSERT INTO os_images (id, template_image_file_name, description, deprecated) +VALUES ('guixsystem130', 'guixsystem/1.3.0/root.img.qcow2', 'Guix System 1.3.0', FALSE); +INSERT INTO os_images (id, template_image_file_name, description, deprecated) +VALUES ('archlinux', 'archlinux/root.img.qcow2', 'Arch Linux', FALSE); + +UPDATE os_images SET deprecated = TRUE WHERE id = 'guixsystem120'; +UPDATE os_images SET description = 'Ubuntu 20.04 (Focal)' WHERE id = 'ubuntu20'; + + +UPDATE schemaversion SET version = 19; -- 2.40.1 From f94d3aa1d3b7ec71f9ed1989096e492fc54850c2 Mon Sep 17 00:00:00 2001 From: j3s Date: Sun, 25 Jul 2021 09:36:04 -0500 Subject: [PATCH 07/12] Add centos deprecation yeet --- capsulflask/schema_migrations/19_down_os_updates.sql | 2 ++ capsulflask/schema_migrations/19_up_os_updates.sql | 2 ++ 2 files changed, 4 insertions(+) diff --git a/capsulflask/schema_migrations/19_down_os_updates.sql b/capsulflask/schema_migrations/19_down_os_updates.sql index 9598409..a9e2083 100644 --- a/capsulflask/schema_migrations/19_down_os_updates.sql +++ b/capsulflask/schema_migrations/19_down_os_updates.sql @@ -1,6 +1,8 @@ DELETE FROM os_images WHERE id = 'guixsystem130'; DELETE FROM os_images WHERE id = 'archlinux'; UPDATE os_images SET deprecated = FALSE WHERE id = 'guixsystem120'; +UPDATE os_images SET deprecated = FALSE WHERE id = 'centos7'; +UPDATE os_images SET deprecated = FALSE WHERE id = 'centos8'; UPDATE os_images SET description = 'Ubuntu 20.04 LTS (Fossa)' WHERE id = 'ubuntu20'; UPDATE schemaversion SET version = 18; diff --git a/capsulflask/schema_migrations/19_up_os_updates.sql b/capsulflask/schema_migrations/19_up_os_updates.sql index 4237e4a..59b1db4 100644 --- a/capsulflask/schema_migrations/19_up_os_updates.sql +++ b/capsulflask/schema_migrations/19_up_os_updates.sql @@ -4,6 +4,8 @@ INSERT INTO os_images (id, template_image_file_name, description, deprecated) VALUES ('archlinux', 'archlinux/root.img.qcow2', 'Arch Linux', FALSE); UPDATE os_images SET deprecated = TRUE WHERE id = 'guixsystem120'; +UPDATE os_images SET deprecated = TRUE WHERE id = 'centos7'; +UPDATE os_images SET deprecated = TRUE WHERE id = 'centos8'; UPDATE os_images SET description = 'Ubuntu 20.04 (Focal)' WHERE id = 'ubuntu20'; -- 2.40.1 From f3630fbacfdb953512f2a2904929c5f37eb96bef Mon Sep 17 00:00:00 2001 From: forest Date: Mon, 26 Jul 2021 15:29:34 -0500 Subject: [PATCH 08/12] account-balance cli command --- capsulflask/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/capsulflask/cli.py b/capsulflask/cli.py index f13c304..0ab191d 100644 --- a/capsulflask/cli.py +++ b/capsulflask/cli.py @@ -62,6 +62,18 @@ def sql_script(f, c): model.connection.commit() +@bp.cli.command('account-balance') +@click.option('-u', help='users email address') +@with_appcontext +def account_balance(u): + vms = get_model().list_vms_for_account(u) + payments = get_model().list_payments_for_account(u) + click.echo(".") + click.echo(".") + click.echo(get_account_balance(vms, payments, datetime.utcnow())) + click.echo(".") + + @bp.cli.command('cron-task') @with_appcontext -- 2.40.1 From ba997bb3ff6a36b49ae51f9edbfab89bd7657282 Mon Sep 17 00:00:00 2001 From: forest Date: Mon, 16 Aug 2021 13:24:11 -0500 Subject: [PATCH 09/12] defer fkey constraints until end of txn -- allow change email --- capsulflask/db.py | 2 +- .../20_down_deferrable_constraints.sql | 21 +++++++++++++++++++ .../20_up_deferrable_constraints.sql | 21 +++++++++++++++++++ docs/database.md | 17 +++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 capsulflask/schema_migrations/20_down_deferrable_constraints.sql create mode 100644 capsulflask/schema_migrations/20_up_deferrable_constraints.sql diff --git a/capsulflask/db.py b/capsulflask/db.py index ddd7081..0c291a0 100644 --- a/capsulflask/db.py +++ b/capsulflask/db.py @@ -43,7 +43,7 @@ def init_app(app, is_running_server): hasSchemaVersionTable = False actionWasTaken = False schemaVersion = 0 - desiredSchemaVersion = 19 + desiredSchemaVersion = 20 cursor = connection.cursor() diff --git a/capsulflask/schema_migrations/20_down_deferrable_constraints.sql b/capsulflask/schema_migrations/20_down_deferrable_constraints.sql new file mode 100644 index 0000000..ecd2355 --- /dev/null +++ b/capsulflask/schema_migrations/20_down_deferrable_constraints.sql @@ -0,0 +1,21 @@ + +ALTER TABLE host_network ALTER CONSTRAINT host_network_host_fkey NOT DEFERRABLE; +ALTER TABLE host_operation ALTER CONSTRAINT host_operation_host_fkey NOT DEFERRABLE; +ALTER TABLE host_operation ALTER CONSTRAINT host_operation_operation_fkey NOT DEFERRABLE; +ALTER TABLE login_tokens ALTER CONSTRAINT login_tokens_email_fkey NOT DEFERRABLE; +ALTER TABLE operations ALTER CONSTRAINT operations_email_fkey NOT DEFERRABLE; +ALTER TABLE payment_sessions ALTER CONSTRAINT payment_sessions_email_fkey NOT DEFERRABLE; +ALTER TABLE payments ALTER CONSTRAINT payments_email_fkey NOT DEFERRABLE; +ALTER TABLE ssh_public_keys ALTER CONSTRAINT ssh_public_keys_email_fkey NOT DEFERRABLE; +ALTER TABLE unresolved_btcpay_invoices ALTER CONSTRAINT unresolved_btcpay_invoices_email_fkey NOT DEFERRABLE; +ALTER TABLE unresolved_btcpay_invoices ALTER CONSTRAINT unresolved_btcpay_invoices_email_payment_id_fkey NOT DEFERRABLE; +ALTER TABLE vm_ssh_authorized_key ALTER CONSTRAINT vm_ssh_public_key_email_ssh_public_key_name_fkey NOT DEFERRABLE; +ALTER TABLE vm_ssh_authorized_key ALTER CONSTRAINT vm_ssh_public_key_email_vm_id_fkey NOT DEFERRABLE; +ALTER TABLE vm_ssh_host_key ALTER CONSTRAINT vm_ssh_host_key_email_vm_id_fkey NOT DEFERRABLE; +ALTER TABLE vms ALTER CONSTRAINT vms_email_fkey NOT DEFERRABLE; +ALTER TABLE vms ALTER CONSTRAINT vms_host_network_name_fkey NOT DEFERRABLE; +ALTER TABLE vms ALTER CONSTRAINT vms_host_fkey NOT DEFERRABLE; +ALTER TABLE vms ALTER CONSTRAINT vms_os_fkey NOT DEFERRABLE; +ALTER TABLE vms ALTER CONSTRAINT vms_size_fkey NOT DEFERRABLE; + +UPDATE schemaversion SET version = 19; \ No newline at end of file diff --git a/capsulflask/schema_migrations/20_up_deferrable_constraints.sql b/capsulflask/schema_migrations/20_up_deferrable_constraints.sql new file mode 100644 index 0000000..b4b560a --- /dev/null +++ b/capsulflask/schema_migrations/20_up_deferrable_constraints.sql @@ -0,0 +1,21 @@ + +ALTER TABLE host_network ALTER CONSTRAINT host_network_host_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE host_operation ALTER CONSTRAINT host_operation_host_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE host_operation ALTER CONSTRAINT host_operation_operation_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE login_tokens ALTER CONSTRAINT login_tokens_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE operations ALTER CONSTRAINT operations_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE payment_sessions ALTER CONSTRAINT payment_sessions_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE payments ALTER CONSTRAINT payments_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE ssh_public_keys ALTER CONSTRAINT ssh_public_keys_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE unresolved_btcpay_invoices ALTER CONSTRAINT unresolved_btcpay_invoices_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE unresolved_btcpay_invoices ALTER CONSTRAINT unresolved_btcpay_invoices_email_payment_id_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vm_ssh_authorized_key ALTER CONSTRAINT vm_ssh_public_key_email_ssh_public_key_name_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vm_ssh_authorized_key ALTER CONSTRAINT vm_ssh_public_key_email_vm_id_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vm_ssh_host_key ALTER CONSTRAINT vm_ssh_host_key_email_vm_id_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vms ALTER CONSTRAINT vms_email_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vms ALTER CONSTRAINT vms_host_network_name_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vms ALTER CONSTRAINT vms_host_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vms ALTER CONSTRAINT vms_os_fkey DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vms ALTER CONSTRAINT vms_size_fkey DEFERRABLE INITIALLY DEFERRED; + +UPDATE schemaversion SET version = 20; \ No newline at end of file diff --git a/docs/database.md b/docs/database.md index f192783..a3ef307 100644 --- a/docs/database.md +++ b/docs/database.md @@ -48,3 +48,20 @@ $ pipenv run flask cli sql -c "SELECT id, created, email, dollars, invalidated f ## how to view the logs on the database server (legion.cyberia.club) `sudo -u postgres pg_dump capsul-flask | gzip -9 > capsul-backup-2021-02-15.gz` + + +## changing the email address on an account + +``` +UPDATE accounts SET lower_case_email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE accounts SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE login_tokens SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE operations SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE payment_sessions SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE payments SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE ssh_public_keys SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE unresolved_btcpay_invoices SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE vm_ssh_authorized_key SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE vm_ssh_host_key SET email = 'new@email.address' WHERE email = 'old@email.address' ; +UPDATE vms SET email = 'new@email.address' WHERE email = 'old@email.address' ; +``` -- 2.40.1 From f8e187ff8445eb9e760d104903b4d61d1c64b5c5 Mon Sep 17 00:00:00 2001 From: forest Date: Fri, 27 Aug 2021 12:14:38 -0500 Subject: [PATCH 10/12] local variable 'assigned_hosts_string' referenced before assignment --- capsulflask/hub_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capsulflask/hub_model.py b/capsulflask/hub_model.py index 375bb9f..73f60f5 100644 --- a/capsulflask/hub_model.py +++ b/capsulflask/hub_model.py @@ -228,8 +228,8 @@ class CapsulFlaskHub(VirtualizationInterface): # no need to do anything here since if it cant be parsed then generic_operation will handle it. pass + assigned_hosts_string = ", ".join(assigned_hosts) if number_of_assigned != 1: - assigned_hosts_string = ", ".join(assigned_hosts) raise ValueError(f"expected create capsul operation {operation_id} to be assigned to one host, it was assigned to {number_of_assigned} ({assigned_hosts_string})") if error_message != "": raise ValueError(f"create capsul operation {operation_id} on {assigned_hosts_string} failed with {error_message}") -- 2.40.1 From 3346a45ed422dd0e4a9b78f6c8ec095253ea8f4a Mon Sep 17 00:00:00 2001 From: forest Date: Fri, 27 Aug 2021 12:18:17 -0500 Subject: [PATCH 11/12] return success whn attempting to destroy a capsul that doesnt exist --- capsulflask/spoke_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/capsulflask/spoke_api.py b/capsulflask/spoke_api.py index 3ca86bc..f7513aa 100644 --- a/capsulflask/spoke_api.py +++ b/capsulflask/spoke_api.py @@ -182,7 +182,10 @@ def handle_destroy(operation_id, request_body): return abort(400, f"bad request; email is required for destroy") try: - current_app.config['SPOKE_MODEL'].destroy(id=request_body['id'], email=request_body['email']) + vm = current_app.config['SPOKE_MODEL'].get(request_body['id'], False) + current_app.logger.warning(f"destroy {request_body['id']} was called for {request_body['email']}, however the vm does not exist. returning success. ") + if vm is not None: + current_app.config['SPOKE_MODEL'].destroy(id=request_body['id'], email=request_body['email']) except: error_message = my_exec_info_message(sys.exc_info()) params = f"email='{request_body['email'] if 'email' in request_body else 'KeyError'}', " -- 2.40.1 From 5a67a58f98b602e7ea3a3c44d5bee43bf52a725c Mon Sep 17 00:00:00 2001 From: forest Date: Thu, 2 Sep 2021 12:00:48 -0500 Subject: [PATCH 12/12] better error handling when the btcpay server goes down --- capsulflask/__init__.py | 8 ++++++-- capsulflask/payment.py | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/capsulflask/__init__.py b/capsulflask/__init__.py index 55643bb..c5de152 100644 --- a/capsulflask/__init__.py +++ b/capsulflask/__init__.py @@ -142,8 +142,12 @@ app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNA app.config['BTCPAY_ENABLED'] = False if app.config['BTCPAY_URL'] != "": try: - app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY']) - app.config['BTCPAY_ENABLED'] = True + response = requests.get(app.config['BTCPAY_URL']) + if response.status_code == 200: + app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY']) + app.config['BTCPAY_ENABLED'] = True + else: + app.logger.warning(f"Can't reach BTCPAY_URL {app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.") except: app.logger.warning("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info())) diff --git a/capsulflask/payment.py b/capsulflask/payment.py index 3c41cd9..a2e104e 100644 --- a/capsulflask/payment.py +++ b/capsulflask/payment.py @@ -58,14 +58,19 @@ def btcpay_payment(): dollars = result[1] if len(errors) == 0: - invoice = current_app.config['BTCPAY_CLIENT'].create_invoice(dict( - price=float(dollars), - currency="USD", - itemDesc="Capsul Cloud Compute", - transactionSpeed="high", - redirectURL=f"{current_app.config['BASE_URL']}/console/account-balance", - notificationURL=f"{current_app.config['BASE_URL']}/payment/btcpay/webhook" - )) + try: + invoice = current_app.config['BTCPAY_CLIENT'].create_invoice(dict( + price=float(dollars), + currency="USD", + itemDesc="Capsul Cloud Compute", + transactionSpeed="high", + redirectURL=f"{current_app.config['BASE_URL']}/console/account-balance", + notificationURL=f"{current_app.config['BASE_URL']}/payment/btcpay/webhook" + )) + except: + current_app.logger.error(f"An error occurred while attempting to reach BTCPay Server: {my_exec_info_message(sys.exc_info())}") + flash("An error occurred while attempting to reach BTCPay Server.") + return redirect(url_for("console.account_balance")) current_app.logger.info(f"created btcpay invoice: {invoice}") -- 2.40.1