Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
chore(entity): changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Sevcik committed Jul 1, 2021
1 parent 14dc725 commit da62461
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 200 deletions.
2 changes: 1 addition & 1 deletion test/components/test_components_generation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import yaml

from zoo.repos.components_yaml import generate, validate
from zoo.repos.entities_yaml import generate, validate
from zoo.repos.models import Repository
from zoo.services.models import Environment, Service

Expand Down
12 changes: 6 additions & 6 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
from zoo.auditing.runner import CheckContext
from zoo.factories import (
ApiTokenFactory,
BaseComponentFactory,
ComponentBaseFactory,
ComponentLibraryFactory,
ComponentServiceFactory,
DependencyFactory,
DependencyUsageFactory,
EnvironmentFactory,
GroupFactory,
InfraNodeFactory,
IssueFactory,
KindFactory,
LibraryComponentFactory,
LibraryFactory,
LinkFactory,
RepositoryFactory,
ServiceComponentFactory,
ServiceFactory,
TierFactory,
UserFactory,
Expand All @@ -45,9 +45,9 @@
register(DependencyUsageFactory)
register(KindFactory)
register(InfraNodeFactory)
register(BaseComponentFactory)
register(LibraryComponentFactory)
register(ServiceComponentFactory)
register(ComponentBaseFactory)
register(ComponentLibraryFactory)
register(ComponentServiceFactory)
register(LibraryFactory)
register(GroupFactory)

Expand Down
8 changes: 3 additions & 5 deletions zoo/base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"zoo.auditing.apps.AuditingConfig",
"zoo.checklists.apps.ChecklistsConfig",
"zoo.datacenters.apps.DatacentersConfig",
"zoo.components.apps.ComponentsConfig",
"zoo.instance.apps.InstanceConfig",
"zoo.libraries.apps.LibrariesConfig",
"zoo.globalsearch.apps.GlobalSearchConfig",
Expand All @@ -114,6 +113,7 @@
"zoo.repos.apps.ReposConfig",
"zoo.resources.apps.ResourcesConfig",
"zoo.services.apps.ServicesConfig",
"zoo.entities.apps.EntitiesConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down Expand Up @@ -248,10 +248,6 @@
ZOO_AUDITING_CHECKS = env("ZOO_AUDITING_CHECKS")
ZOO_AUDITING_DROP_ISSUES = env("ZOO_AUDITING_DROP_ISSUES")

ZOO_YAML_FILE = env("ZOO_YAML_FILE")
ZOO_YAML_DEFAULT_REF = env("ZOO_YAML_DEFAULT_REF")

ZOO_ALLOWED_COMPONENTS = ""
AWS_CONFIG = env("AWS_CONFIG")
AWS_CONFIG_FILE = env("AWS_CONFIG_FILE")
AWS_CREDENTIALS = env("AWS_SHARED_CREDENTIALS")
Expand All @@ -275,3 +271,5 @@
MEILI_MASTER_KEY = env("MEILI_MASTER_KEY")
MEILI_HOST = env("MEILI_HOST")
logs.configure_structlog(DEBUG)

ZOO_ALLOWED_COMPONENT_TYPES = ["service", "library"]
5 changes: 0 additions & 5 deletions zoo/components/apps.py

This file was deleted.

33 changes: 0 additions & 33 deletions zoo/components/builder.py

This file was deleted.

File renamed without changes.
5 changes: 5 additions & 0 deletions zoo/entities/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class EntitiesConfig(AppConfig):
name = "zoo.entities"
41 changes: 41 additions & 0 deletions zoo/entities/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from zoo.entities.models import Entity, Group


class EntityBuilder:
def entity(self, data):
if data["kind"] == "component":
if data["spec"]["type"] == "service":
self._build_service(data)
elif data["spec"]["spec"] == "library":
self._build_library(data)
else:
self._build_base_component(data)
else:
return NotImplemented

@staticmethod
def _build_base_component(data):
group, _ = Group.objects.update_or_create(
product_owner=data["metadata"]["group"]["product_owner"],
project_owner=data["metadata"]["group"]["project_owner"],
maintainers=data["metadata"]["group"]["maintainers"],
)
obj, _ = Entity.objects.update_or_create(
name=data["metadata"]["name"],
kind=data["kind"],
owner=data["metadata"]["owner"],
type=data["spec"]["type"],
defaults={
"group": group,
"description": data["metadata"]["description"],
"tags": data["metadata"]["tags"],
"links": "",
},
)
return obj

def _build_service(self, data):
base_component = self._build_base_component(data)

def _build_library(self, data):
self._build_base_component(data)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.19 on 2021-06-17 00:10
# Generated by Django 2.2.19 on 2021-07-01 11:30

import django.contrib.postgres.fields
import django.db.models.deletion
Expand All @@ -10,14 +10,14 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
("libraries", "0004_auto_20210617_0010"),
("repos", "0007_endpoint"),
("services", "0027_auto_20210617_0010"),
("services", "0028_auto_20210701_1130"),
("libraries", "0004_auto_20210701_1130"),
("repos", "0008_repositoryenvironment"),
]

operations = [
migrations.CreateModel(
name="Component",
name="Entity",
fields=[
(
"id",
Expand Down Expand Up @@ -97,28 +97,28 @@ class Migration(migrations.Migration):
),
("url", models.URLField()),
(
"component",
"entity",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="links",
related_query_name="link",
to="components.Component",
to="entities.Entity",
),
),
],
),
migrations.AddField(
model_name="component",
model_name="entity",
name="group",
field=models.OneToOneField(
on_delete=django.db.models.deletion.PROTECT,
related_name="components",
related_query_name="component",
to="components.Group",
to="entities.Group",
),
),
migrations.AddField(
model_name="component",
model_name="entity",
name="library",
field=models.OneToOneField(
blank=True,
Expand All @@ -128,7 +128,7 @@ class Migration(migrations.Migration):
),
),
migrations.AddField(
model_name="component",
model_name="entity",
name="service",
field=models.OneToOneField(
blank=True,
Expand All @@ -138,12 +138,12 @@ class Migration(migrations.Migration):
),
),
migrations.AddField(
model_name="component",
model_name="entity",
name="source",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="components",
related_query_name="component",
related_name="entities",
related_query_name="entity",
to="repos.Repository",
),
),
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions zoo/components/models.py → zoo/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ class Link(models.Model):
help_text="https://fomantic-ui.com/elements/icon.html",
)
url = models.URLField()
component = models.ForeignKey(
"components.Component",
entity = models.ForeignKey(
"entities.Entity",
related_name="links",
related_query_name="link",
on_delete=models.PROTECT,
)


class Component(models.Model):
class Entity(models.Model):
name = models.CharField(max_length=100)
type = models.CharField(max_length=32)
description = models.CharField(max_length=255, null=True, blank=True)
kind = models.CharField(max_length=16)
owner = models.CharField(max_length=50)
group = models.OneToOneField(
"components.Group",
"entities.Group",
related_name="components",
related_query_name="component",
on_delete=models.PROTECT,
Expand All @@ -50,8 +50,8 @@ class Component(models.Model):
)
source = models.ForeignKey(
"repos.Repository",
related_name="components",
related_query_name="component",
related_name="entities",
related_query_name="entity",
on_delete=models.PROTECT,
)
service = models.OneToOneField(
Expand Down
14 changes: 7 additions & 7 deletions zoo/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from zoo.api.models import ApiToken
from zoo.auditing.check_discovery import Kind
from zoo.auditing.models import Issue
from zoo.components.models import Component, Group, Link
from zoo.datacenters.models import InfraNode
from zoo.entities.models import Entity, Group, Link
from zoo.libraries.models import Library
from zoo.repos.models import Repository, RepositoryEnvironment
from zoo.services.constants import Lifecycle
Expand Down Expand Up @@ -182,9 +182,9 @@ class Meta:
repository = SubFactory(RepositoryFactory)


class BaseComponentFactory(Factory):
class ComponentBaseFactory(Factory):
class Meta:
model = Component
model = Entity

name = Faker("domain_word")
type = Faker("domain_word")
Expand All @@ -197,9 +197,9 @@ class Meta:
group = SubFactory(GroupFactory)


class ServiceComponentFactory(Factory):
class ComponentServiceFactory(Factory):
class Meta:
model = Component
model = Entity

name = Faker("domain_word")
type = Faker("domain_word")
Expand All @@ -212,9 +212,9 @@ class Meta:
group = SubFactory(GroupFactory)


class LibraryComponentFactory(Factory):
class ComponentLibraryFactory(Factory):
class Meta:
model = Component
model = Entity

name = Faker("domain_word")
type = Faker("domain_word")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.19 on 2021-06-17 00:10
# Generated by Django 2.2.19 on 2021-07-01 11:30

from django.db import migrations

Expand Down
Loading

0 comments on commit da62461

Please sign in to comment.