feat: payment check before creation and save gitea passwd in DB
parent
beb4b29c49
commit
871a05ddd3
|
@ -0,0 +1,37 @@
|
||||||
|
# Generated by Django 4.0.3 on 2022-06-25 10:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("dash", "0006_auto_20220619_0800"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="InstanceCreated",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("creted", models.BooleanField(default=False)),
|
||||||
|
(
|
||||||
|
"instance",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.PROTECT, to="dash.instance"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.0.3 on 2022-06-25 12:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('infrastructure', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='instancecreated',
|
||||||
|
name='gitea_password',
|
||||||
|
field=models.CharField(default=None, max_length=32, verbose_name='Name of this configuration'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,3 +1,27 @@
|
||||||
|
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
from dash.models import Instance
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceCreated(models.Model):
|
||||||
|
instance = models.ForeignKey(Instance, on_delete=models.PROTECT)
|
||||||
|
gitea_password = models.CharField(
|
||||||
|
"Name of this configuration",
|
||||||
|
default=None,
|
||||||
|
max_length=32,
|
||||||
|
)
|
||||||
|
creted = models.BooleanField(default=False)
|
||||||
|
|
|
@ -39,9 +39,10 @@ class InfraUtilTest(TestCase):
|
||||||
"INFRA": {
|
"INFRA": {
|
||||||
"HOSTEA_REPO": {
|
"HOSTEA_REPO": {
|
||||||
"PATH": "/tmp/hostea/dashboard/test_path_util/repo/",
|
"PATH": "/tmp/hostea/dashboard/test_path_util/repo/",
|
||||||
"REMOTE": "git@gitea.hostea.org:Hostea/payments.git",
|
"REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test",
|
||||||
"SSH_KEY": "/src/atm/.ssh/id",
|
"SSH_KEY": "/src/atm/.ssh/aravinth",
|
||||||
}
|
},
|
||||||
|
"HOSTEA_DOMAIN": "hostea.org",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -74,3 +75,30 @@ class InfraUtilTest(TestCase):
|
||||||
base.joinpath(f"inventory/hosts-scripts/{subdomain}-host.sh"),
|
base.joinpath(f"inventory/hosts-scripts/{subdomain}-host.sh"),
|
||||||
infra._hostscript_path(subdomain=subdomain),
|
infra._hostscript_path(subdomain=subdomain),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
HOSTEA={
|
||||||
|
"INFRA": {
|
||||||
|
"HOSTEA_REPO": {
|
||||||
|
"PATH": "/tmp/hostea/dashboard/test_add_vm/repo/",
|
||||||
|
"REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test",
|
||||||
|
"SSH_KEY": "/src/atm/.ssh/aravinth",
|
||||||
|
},
|
||||||
|
"HOSTEA_DOMAIN": "hostea.org",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def test_add_vm(self):
|
||||||
|
infra = Infra()
|
||||||
|
c = Client()
|
||||||
|
login_util(self, c, "accounts.home")
|
||||||
|
subdomain = "add_vm"
|
||||||
|
|
||||||
|
base = infra.repo_path
|
||||||
|
|
||||||
|
create_instance_util(
|
||||||
|
t=self, c=c, instance_name=subdomain, config=self.instance_config[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
instance = Instance.objects.get(name=subdomain)
|
||||||
|
woodpecker_agent_secret = infra.add_vm(instance=instance)
|
||||||
|
|
|
@ -23,8 +23,10 @@ from django.urls import reverse
|
||||||
|
|
||||||
from accounts.decorators import confirm_access
|
from accounts.decorators import confirm_access
|
||||||
from dash.models import Instance
|
from dash.models import Instance
|
||||||
|
from billing.utils import payment_fullfilled
|
||||||
|
|
||||||
from .utils import Infra
|
from .utils import Infra
|
||||||
|
from .models import InstanceCreated
|
||||||
|
|
||||||
|
|
||||||
def default_ctx(title: str, username: str):
|
def default_ctx(title: str, username: str):
|
||||||
|
@ -44,9 +46,16 @@ def create_instance(request, instance_name: str):
|
||||||
Dashboard homepage view
|
Dashboard homepage view
|
||||||
"""
|
"""
|
||||||
instance = get_object_or_404(Instance, name=instance_name, owned_by=request.user)
|
instance = get_object_or_404(Instance, name=instance_name, owned_by=request.user)
|
||||||
|
if not payment_fullfilled(instance=instance):
|
||||||
|
return redirect(reverse("billing.invoice.generate", args=(instance_name,)))
|
||||||
|
|
||||||
infra = Infra()
|
infra = Infra()
|
||||||
infra.add_vm(instance=instance)
|
if not InstanceCreated.objects.filter(instance=instance).exists():
|
||||||
# TODO: push isn't implemented yet
|
instance = InstanceCreated.objects.create(instance=instance, created=True)
|
||||||
|
instance.save()
|
||||||
|
gitea_password = infra.add_vm(instance=instance)
|
||||||
|
instance.gitea_password = gitea_password
|
||||||
|
instance.save()
|
||||||
|
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue