Skip to content

Commit 23106cc

Browse files
committed
Split core schema into multiple files
1 parent 6b333ec commit 23106cc

File tree

3 files changed

+332
-307
lines changed

3 files changed

+332
-307
lines changed

backend/infrahub/core/schema/definitions/core.py renamed to backend/infrahub/core/schema/definitions/core/__init__.py

Lines changed: 6 additions & 307 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from infrahub.core.constants import (
44
DEFAULT_KIND_MAX_LENGTH,
55
DEFAULT_KIND_MIN_LENGTH,
6-
NAMESPACE_REGEX,
76
AccountStatus,
87
AccountType,
98
AllowOverrideType,
@@ -17,15 +16,15 @@
1716
PermissionAction,
1817
PermissionDecision,
1918
RelationshipDeleteBehavior,
20-
RepositoryInternalStatus,
21-
RepositoryOperationalStatus,
22-
RepositorySyncStatus,
2319
Severity,
2420
ValidatorConclusion,
2521
ValidatorState,
2622
)
2723
from infrahub.proposed_change.constants import ProposedChangeState
2824

25+
from .menu import generic_menu_item, menu_item
26+
from .repository import core_generic_repository, core_read_only_repository, core_repository
27+
2928
core_profile_schema_definition: dict[str, Any] = {
3029
"name": "Profile",
3130
"namespace": "Core",
@@ -54,49 +53,6 @@
5453
],
5554
}
5655

57-
# -----------------------------------------------
58-
# Menu Items
59-
# -----------------------------------------------
60-
generic_menu_item: dict[str, Any] = {
61-
"name": "Menu",
62-
"namespace": "Core",
63-
"include_in_menu": False,
64-
"description": "Element of the Menu",
65-
"label": "Menu",
66-
"hierarchical": True,
67-
"human_friendly_id": ["namespace__value", "name__value"],
68-
"display_labels": ["label__value"],
69-
"generate_profile": False,
70-
"attributes": [
71-
{"name": "namespace", "kind": "Text", "regex": NAMESPACE_REGEX, "order_weight": 1000},
72-
{"name": "name", "kind": "Text", "order_weight": 1000},
73-
{"name": "label", "kind": "Text", "optional": True, "order_weight": 2000},
74-
{"name": "kind", "kind": "Text", "optional": True, "order_weight": 2500},
75-
{"name": "path", "kind": "Text", "optional": True, "order_weight": 2500},
76-
{"name": "description", "kind": "Text", "optional": True, "order_weight": 3000},
77-
{"name": "icon", "kind": "Text", "optional": True, "order_weight": 4000},
78-
{"name": "protected", "kind": "Boolean", "default_value": False, "read_only": True, "order_weight": 5000},
79-
{"name": "order_weight", "kind": "Number", "default_value": 2000, "order_weight": 6000},
80-
{"name": "required_permissions", "kind": "List", "optional": True, "order_weight": 7000},
81-
{
82-
"name": "section",
83-
"kind": "Text",
84-
"enum": ["object", "internal"],
85-
"default_value": "object",
86-
"order_weight": 8000,
87-
},
88-
],
89-
}
90-
91-
menu_item: dict[str, Any] = {
92-
"name": "MenuItem",
93-
"namespace": "Core",
94-
"include_in_menu": False,
95-
"description": "Menu Item",
96-
"label": "Menu Item",
97-
"inherit_from": ["CoreMenu"],
98-
"generate_profile": False,
99-
}
10056

10157
core_models: dict[str, Any] = {
10258
"generics": [
@@ -418,201 +374,7 @@
418374
},
419375
],
420376
},
421-
{
422-
"name": "GenericRepository",
423-
"namespace": "Core",
424-
"label": "Git Repository",
425-
"description": "A Git Repository integrated with Infrahub",
426-
"include_in_menu": False,
427-
"default_filter": "name__value",
428-
"order_by": ["name__value"],
429-
"display_labels": ["name__value"],
430-
"icon": "mdi:source-repository",
431-
"branch": BranchSupportType.AGNOSTIC.value,
432-
"uniqueness_constraints": [["name__value"], ["location__value"]],
433-
"documentation": "/topics/repository",
434-
"attributes": [
435-
{
436-
"name": "name",
437-
"regex": "^[^/]*$",
438-
"kind": "Text",
439-
"unique": True,
440-
"branch": BranchSupportType.AGNOSTIC.value,
441-
"order_weight": 1000,
442-
"allow_override": AllowOverrideType.NONE,
443-
},
444-
{
445-
"name": "description",
446-
"kind": "Text",
447-
"optional": True,
448-
"branch": BranchSupportType.AGNOSTIC.value,
449-
"order_weight": 2000,
450-
"allow_override": AllowOverrideType.NONE,
451-
},
452-
{
453-
"name": "location",
454-
"kind": "Text",
455-
"unique": True,
456-
"branch": BranchSupportType.AGNOSTIC.value,
457-
"order_weight": 3000,
458-
"allow_override": AllowOverrideType.NONE,
459-
},
460-
{
461-
"name": "internal_status",
462-
"kind": "Dropdown",
463-
"choices": [
464-
{
465-
"name": RepositoryInternalStatus.STAGING.value,
466-
"label": "Staging",
467-
"description": "Repository was recently added to this branch.",
468-
"color": "#fef08a",
469-
},
470-
{
471-
"name": RepositoryInternalStatus.ACTIVE.value,
472-
"label": "Active",
473-
"description": "Repository is actively being synced for this branch",
474-
"color": "#86efac",
475-
},
476-
{
477-
"name": RepositoryInternalStatus.INACTIVE.value,
478-
"label": "Inactive",
479-
"description": "Repository is not active on this branch.",
480-
"color": "#e5e7eb",
481-
},
482-
],
483-
"default_value": "inactive",
484-
"optional": False,
485-
"branch": BranchSupportType.LOCAL.value,
486-
"order_weight": 7000,
487-
"allow_override": AllowOverrideType.NONE,
488-
},
489-
{
490-
"name": "operational_status",
491-
"kind": "Dropdown",
492-
"choices": [
493-
{
494-
"name": RepositoryOperationalStatus.UNKNOWN.value,
495-
"label": "Unknown",
496-
"description": "Status of the repository is unknown and mostlikely because it hasn't been synced yet",
497-
"color": "#9ca3af",
498-
},
499-
{
500-
"name": RepositoryOperationalStatus.ONLINE.value,
501-
"label": "Online",
502-
"description": "Repository connection is working",
503-
"color": "#86efac",
504-
},
505-
{
506-
"name": RepositoryOperationalStatus.ERROR_CRED.value,
507-
"label": "Credential Error",
508-
"description": "Repository can't be synced due to some credential error(s)",
509-
"color": "#f87171",
510-
},
511-
{
512-
"name": RepositoryOperationalStatus.ERROR_CONNECTION.value,
513-
"label": "Connectivity Error",
514-
"description": "Repository can't be synced due to some connectivity error(s)",
515-
"color": "#f87171",
516-
},
517-
{
518-
"name": RepositoryOperationalStatus.ERROR.value,
519-
"label": "Error",
520-
"description": "Repository can't be synced due to an unknown error",
521-
"color": "#ef4444",
522-
},
523-
],
524-
"optional": False,
525-
"branch": BranchSupportType.AGNOSTIC.value,
526-
"default_value": RepositoryOperationalStatus.UNKNOWN.value,
527-
"order_weight": 5000,
528-
},
529-
{
530-
"name": "sync_status",
531-
"kind": "Dropdown",
532-
"choices": [
533-
{
534-
"name": RepositorySyncStatus.UNKNOWN.value,
535-
"label": "Unknown",
536-
"description": "Status of the repository is unknown and mostlikely because it hasn't been synced yet",
537-
"color": "#9ca3af",
538-
},
539-
{
540-
"name": RepositorySyncStatus.ERROR_IMPORT.value,
541-
"label": "Import Error",
542-
"description": "Repository import error observed",
543-
"color": "#f87171",
544-
},
545-
{
546-
"name": RepositorySyncStatus.IN_SYNC.value,
547-
"label": "In Sync",
548-
"description": "The repository is syncing correctly",
549-
"color": "#60a5fa",
550-
},
551-
{
552-
"name": RepositorySyncStatus.SYNCING.value,
553-
"label": "Syncing",
554-
"description": "A sync job is currently running against the repository.",
555-
"color": "#a855f7",
556-
},
557-
],
558-
"optional": False,
559-
"branch": BranchSupportType.LOCAL.value,
560-
"default_value": RepositorySyncStatus.UNKNOWN.value,
561-
"order_weight": 6000,
562-
},
563-
],
564-
"relationships": [
565-
{
566-
"name": "credential",
567-
"peer": InfrahubKind.CREDENTIAL,
568-
"identifier": "gitrepository__credential",
569-
"kind": "Attribute",
570-
"optional": True,
571-
"cardinality": "one",
572-
"order_weight": 4000,
573-
},
574-
{
575-
"name": "tags",
576-
"peer": InfrahubKind.TAG,
577-
"kind": "Attribute",
578-
"optional": True,
579-
"cardinality": "many",
580-
"order_weight": 8000,
581-
},
582-
{
583-
"name": "transformations",
584-
"peer": InfrahubKind.TRANSFORM,
585-
"identifier": "repository__transformation",
586-
"optional": True,
587-
"cardinality": "many",
588-
"order_weight": 10000,
589-
},
590-
{
591-
"name": "queries",
592-
"peer": InfrahubKind.GRAPHQLQUERY,
593-
"identifier": "graphql_query__repository",
594-
"optional": True,
595-
"cardinality": "many",
596-
"order_weight": 9000,
597-
},
598-
{
599-
"name": "checks",
600-
"peer": InfrahubKind.CHECKDEFINITION,
601-
"identifier": "check_definition__repository",
602-
"optional": True,
603-
"cardinality": "many",
604-
"order_weight": 11000,
605-
},
606-
{
607-
"name": "generators",
608-
"peer": InfrahubKind.GENERATORDEFINITION,
609-
"identifier": "generator_definition__repository",
610-
"optional": True,
611-
"cardinality": "many",
612-
"order_weight": 12000,
613-
},
614-
],
615-
},
377+
core_generic_repository,
616378
{
617379
"name": "IPNamespace",
618380
"namespace": "Builtin",
@@ -1336,71 +1098,8 @@
13361098
},
13371099
],
13381100
},
1339-
{
1340-
"name": "Repository",
1341-
"namespace": "Core",
1342-
"description": "A Git Repository integrated with Infrahub",
1343-
"include_in_menu": False,
1344-
"icon": "mdi:source-repository",
1345-
"label": "Repository",
1346-
"default_filter": "name__value",
1347-
"order_by": ["name__value"],
1348-
"display_labels": ["name__value"],
1349-
"generate_profile": False,
1350-
"branch": BranchSupportType.AGNOSTIC.value,
1351-
"inherit_from": [
1352-
InfrahubKind.LINEAGEOWNER,
1353-
InfrahubKind.LINEAGESOURCE,
1354-
InfrahubKind.GENERICREPOSITORY,
1355-
InfrahubKind.TASKTARGET,
1356-
],
1357-
"documentation": "/topics/repository",
1358-
"attributes": [
1359-
{"name": "default_branch", "kind": "Text", "default_value": "main", "order_weight": 6000},
1360-
{
1361-
"name": "commit",
1362-
"kind": "Text",
1363-
"optional": True,
1364-
"branch": BranchSupportType.LOCAL.value,
1365-
"order_weight": 7000,
1366-
},
1367-
],
1368-
},
1369-
{
1370-
"name": "ReadOnlyRepository",
1371-
"namespace": "Core",
1372-
"description": "A Git Repository integrated with Infrahub, Git-side will not be updated",
1373-
"include_in_menu": False,
1374-
"label": "Read-Only Repository",
1375-
"default_filter": "name__value",
1376-
"order_by": ["name__value"],
1377-
"display_labels": ["name__value"],
1378-
"generate_profile": False,
1379-
"branch": BranchSupportType.AGNOSTIC.value,
1380-
"inherit_from": [
1381-
InfrahubKind.LINEAGEOWNER,
1382-
InfrahubKind.LINEAGESOURCE,
1383-
InfrahubKind.GENERICREPOSITORY,
1384-
InfrahubKind.TASKTARGET,
1385-
],
1386-
"documentation": "/topics/repository",
1387-
"attributes": [
1388-
{
1389-
"name": "ref",
1390-
"kind": "Text",
1391-
"default_value": "main",
1392-
"branch": BranchSupportType.AWARE.value,
1393-
"order_weight": 6000,
1394-
},
1395-
{
1396-
"name": "commit",
1397-
"kind": "Text",
1398-
"optional": True,
1399-
"branch": BranchSupportType.AWARE.value,
1400-
"order_weight": 7000,
1401-
},
1402-
],
1403-
},
1101+
core_repository.model_dump(),
1102+
core_read_only_repository,
14041103
{
14051104
"name": "TransformJinja2",
14061105
"namespace": "Core",

0 commit comments

Comments
 (0)