clear-skies-cortex 2.0.2__py3-none-any.whl → 2.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {clear_skies_cortex-2.0.2.dist-info → clear_skies_cortex-2.0.4.dist-info}/METADATA +2 -2
- clear_skies_cortex-2.0.4.dist-info/RECORD +28 -0
- clearskies_cortex/backends/cortex_backend.py +173 -37
- clearskies_cortex/backends/cortex_team_relationship_backend.py +20 -13
- clearskies_cortex/columns/string_list.py +49 -5
- clearskies_cortex/dataclasses.py +177 -7
- clearskies_cortex/defaults/default_cortex_auth.py +46 -0
- clearskies_cortex/defaults/default_cortex_url.py +38 -0
- clearskies_cortex/models/cortex_catalog_entity.py +158 -1
- clearskies_cortex/models/cortex_catalog_entity_domain.py +29 -1
- clearskies_cortex/models/cortex_catalog_entity_group.py +26 -1
- clearskies_cortex/models/cortex_catalog_entity_scorecard.py +50 -1
- clearskies_cortex/models/cortex_catalog_entity_service.py +35 -1
- clearskies_cortex/models/cortex_catalog_entity_team.py +30 -1
- clearskies_cortex/models/cortex_catalog_entity_types.py +38 -1
- clearskies_cortex/models/cortex_entity_relationships.py +40 -1
- clearskies_cortex/models/cortex_model.py +24 -1
- clearskies_cortex/models/cortex_scorecard.py +42 -1
- clearskies_cortex/models/cortex_team.py +98 -1
- clearskies_cortex/models/cortex_team_category_tree.py +41 -1
- clearskies_cortex/models/cortex_team_department.py +37 -1
- clear_skies_cortex-2.0.2.dist-info/RECORD +0 -28
- {clear_skies_cortex-2.0.2.dist-info → clear_skies_cortex-2.0.4.dist-info}/WHEEL +0 -0
- {clear_skies_cortex-2.0.2.dist-info → clear_skies_cortex-2.0.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,7 +2,53 @@ import clearskies
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class DefaultCortexAuth(clearskies.di.AdditionalConfigAutoImport):
|
|
5
|
+
"""
|
|
6
|
+
Default authentication provider for Cortex API.
|
|
7
|
+
|
|
8
|
+
This class provides automatic configuration for Cortex API authentication using
|
|
9
|
+
the clearskies dependency injection system. It is auto-imported when the clearskies_cortex
|
|
10
|
+
package is used, making authentication configuration seamless.
|
|
11
|
+
|
|
12
|
+
The authentication can be configured in two ways:
|
|
13
|
+
|
|
14
|
+
1. **Secret Path (recommended for production)**: Set the `CORTEX_AUTH_SECRET_PATH` environment
|
|
15
|
+
variable to point to a secret manager path containing the API key.
|
|
16
|
+
|
|
17
|
+
2. **Direct Environment Key**: Set the `CORTEX_AUTH_KEY` environment variable directly
|
|
18
|
+
with the Cortex API key.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import clearskies
|
|
22
|
+
from clearskies_cortex.models import CortexTeam
|
|
23
|
+
|
|
24
|
+
# The authentication is automatically configured via environment variables
|
|
25
|
+
# Option 1: Using secret path
|
|
26
|
+
# export CORTEX_AUTH_SECRET_PATH=/path/to/secret
|
|
27
|
+
|
|
28
|
+
# Option 2: Using direct key
|
|
29
|
+
# export CORTEX_AUTH_KEY=your-api-key
|
|
30
|
+
|
|
31
|
+
# Then use models normally - auth is handled automatically
|
|
32
|
+
teams = CortexTeam()
|
|
33
|
+
for team in teams:
|
|
34
|
+
print(team.get_name())
|
|
35
|
+
```
|
|
36
|
+
"""
|
|
37
|
+
|
|
5
38
|
def provide_cortex_auth(self, environment: clearskies.Environment):
|
|
39
|
+
"""
|
|
40
|
+
Provide the Cortex authentication configuration.
|
|
41
|
+
|
|
42
|
+
Checks for `CORTEX_AUTH_SECRET_PATH` first, falling back to `CORTEX_AUTH_KEY`
|
|
43
|
+
if not set. Returns a SecretBearer authentication instance configured for
|
|
44
|
+
the Cortex API.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
environment: The clearskies Environment instance for accessing env variables.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
A SecretBearer authentication instance configured for Cortex API.
|
|
51
|
+
"""
|
|
6
52
|
if environment.get("CORTEX_AUTH_SECRET_PATH", True):
|
|
7
53
|
secret_key = environment.get("CORTEX_AUTH_SECRET_PATH")
|
|
8
54
|
return clearskies.authentication.SecretBearer(secret_key=secret_key, header_prefix="Bearer ")
|
|
@@ -2,6 +2,44 @@ import clearskies
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class DefaultCortexUrl(clearskies.di.AdditionalConfigAutoImport):
|
|
5
|
+
"""
|
|
6
|
+
Default URL provider for Cortex API.
|
|
7
|
+
|
|
8
|
+
This class provides automatic configuration for the Cortex API base URL using
|
|
9
|
+
the clearskies dependency injection system. It is auto-imported when the clearskies_cortex
|
|
10
|
+
package is used, making URL configuration seamless.
|
|
11
|
+
|
|
12
|
+
The URL can be configured via the `CORTEX_URL` environment variable. If not set,
|
|
13
|
+
it defaults to the standard Cortex API endpoint: `https://api.getcortexapp.com/api/v1/`
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import clearskies
|
|
17
|
+
from clearskies_cortex.models import CortexTeam
|
|
18
|
+
|
|
19
|
+
# The URL is automatically configured via environment variable
|
|
20
|
+
# export CORTEX_URL=https://custom-cortex-instance.example.com/api/v1/
|
|
21
|
+
|
|
22
|
+
# Or use the default Cortex API URL by not setting the variable
|
|
23
|
+
|
|
24
|
+
# Then use models normally - URL is handled automatically
|
|
25
|
+
teams = CortexTeam()
|
|
26
|
+
for team in teams:
|
|
27
|
+
print(team.get_name())
|
|
28
|
+
```
|
|
29
|
+
"""
|
|
30
|
+
|
|
5
31
|
def provide_cortex_url(self, environment: clearskies.Environment) -> str:
|
|
32
|
+
"""
|
|
33
|
+
Provide the Cortex API base URL.
|
|
34
|
+
|
|
35
|
+
Checks for `CORTEX_URL` environment variable, falling back to the default
|
|
36
|
+
Cortex API URL if not set.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
environment: The clearskies Environment instance for accessing env variables.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The Cortex API base URL string.
|
|
43
|
+
"""
|
|
6
44
|
cortex_url = environment.get("CORTEX_URL", True)
|
|
7
45
|
return cortex_url if cortex_url else "https://api.getcortexapp.com/api/v1/"
|
|
@@ -17,7 +17,34 @@ from clearskies_cortex.models import (
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class CortexCatalogEntity(Model):
|
|
20
|
-
"""
|
|
20
|
+
"""
|
|
21
|
+
Model for Cortex catalog entities.
|
|
22
|
+
|
|
23
|
+
This model represents entities in the Cortex catalog, which can include services, domains,
|
|
24
|
+
teams, and other entity types. It provides access to entity metadata, ownership information,
|
|
25
|
+
hierarchy data, and associated scorecards.
|
|
26
|
+
|
|
27
|
+
The model connects to the Cortex catalog API endpoint and supports various search parameters
|
|
28
|
+
for filtering entities.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from clearskies_cortex.models import CortexCatalogEntity
|
|
32
|
+
|
|
33
|
+
# Fetch all entities
|
|
34
|
+
entities = CortexCatalogEntity()
|
|
35
|
+
for entity in entities:
|
|
36
|
+
print(f"Entity: {entity.name} ({entity.type})")
|
|
37
|
+
|
|
38
|
+
# Find a specific entity by tag
|
|
39
|
+
entity = entities.find("tag=my-service")
|
|
40
|
+
print(entity.description)
|
|
41
|
+
|
|
42
|
+
# Access parsed hierarchy data
|
|
43
|
+
hierarchy = entity.parse_hierarchy()
|
|
44
|
+
if hierarchy.parents:
|
|
45
|
+
print(f"Parent: {hierarchy.parents[0].tag}")
|
|
46
|
+
```
|
|
47
|
+
"""
|
|
21
48
|
|
|
22
49
|
id_column_name: str = "tag"
|
|
23
50
|
|
|
@@ -28,42 +55,172 @@ class CortexCatalogEntity(Model):
|
|
|
28
55
|
"""Return the slug of the api endpoint for this model."""
|
|
29
56
|
return "catalog"
|
|
30
57
|
|
|
58
|
+
"""
|
|
59
|
+
The unique identifier for the entity.
|
|
60
|
+
"""
|
|
31
61
|
id = String()
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
The unique tag identifier for the entity (e.g., "my-service").
|
|
65
|
+
|
|
66
|
+
This is the primary identifier used to reference entities in the Cortex catalog.
|
|
67
|
+
"""
|
|
32
68
|
tag = String()
|
|
69
|
+
|
|
70
|
+
"""
|
|
71
|
+
List of groups the entity belongs to.
|
|
72
|
+
|
|
73
|
+
Groups are key-value pairs formatted as "key:value" strings. Use `parse_groups()`
|
|
74
|
+
to convert to a dictionary.
|
|
75
|
+
"""
|
|
33
76
|
groups = StringList("groups")
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
JSON object containing owner information for the entity.
|
|
80
|
+
|
|
81
|
+
Contains team and user ownership data. Use `parse_owners()` to convert to a typed dataclass.
|
|
82
|
+
"""
|
|
34
83
|
owners = Json()
|
|
84
|
+
|
|
85
|
+
"""
|
|
86
|
+
JSON object containing ownership configuration.
|
|
87
|
+
"""
|
|
35
88
|
ownership = Json()
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
JSON object containing version 2 owner information.
|
|
92
|
+
"""
|
|
36
93
|
owners_v2 = Json()
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
Human-readable description of the entity.
|
|
97
|
+
"""
|
|
37
98
|
description = String()
|
|
99
|
+
|
|
100
|
+
"""
|
|
101
|
+
JSON object containing Git repository information.
|
|
102
|
+
|
|
103
|
+
Includes repository URLs, default branch, and other Git-related metadata.
|
|
104
|
+
"""
|
|
38
105
|
git = Json()
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
JSON object containing hierarchy information.
|
|
109
|
+
|
|
110
|
+
Contains parent and child relationships. Use `parse_hierarchy()` to convert to a typed dataclass.
|
|
111
|
+
"""
|
|
39
112
|
hierarchy = Json()
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
Timestamp of when the entity was last updated.
|
|
116
|
+
"""
|
|
40
117
|
last_updated = Datetime()
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
Whether the entity is archived.
|
|
121
|
+
"""
|
|
41
122
|
is_archived = Boolean()
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
JSON object containing external links associated with the entity.
|
|
126
|
+
"""
|
|
42
127
|
links = Json()
|
|
128
|
+
|
|
129
|
+
"""
|
|
130
|
+
JSON object containing member information for team entities.
|
|
131
|
+
"""
|
|
43
132
|
members = Json()
|
|
133
|
+
|
|
134
|
+
"""
|
|
135
|
+
JSON object containing custom metadata for the entity.
|
|
136
|
+
"""
|
|
44
137
|
metadata = Json()
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
JSON object containing Slack channel configurations.
|
|
141
|
+
"""
|
|
45
142
|
slack_channels = Json()
|
|
143
|
+
|
|
144
|
+
"""
|
|
145
|
+
Human-readable name of the entity.
|
|
146
|
+
"""
|
|
46
147
|
name = String()
|
|
148
|
+
|
|
149
|
+
"""
|
|
150
|
+
The type of entity (e.g., "service", "domain", "team").
|
|
151
|
+
"""
|
|
47
152
|
type = String()
|
|
153
|
+
|
|
154
|
+
"""
|
|
155
|
+
Related scorecards for this entity.
|
|
156
|
+
|
|
157
|
+
HasMany relationship to CortexCatalogEntityScorecard.
|
|
158
|
+
"""
|
|
48
159
|
scorecards = HasMany(
|
|
49
160
|
cortex_catalog_entity_scorecard.CortexCatalogEntityScorecard,
|
|
50
161
|
foreign_column_name="entity_tag",
|
|
51
162
|
)
|
|
163
|
+
|
|
164
|
+
"""
|
|
165
|
+
Related groups for this entity.
|
|
166
|
+
|
|
167
|
+
HasMany relationship to CortexCatalogEntityGroup.
|
|
168
|
+
"""
|
|
52
169
|
group_models = HasMany(
|
|
53
170
|
cortex_catalog_entity_group.CortexCatalogEntityGroup,
|
|
54
171
|
foreign_column_name="entity_tag",
|
|
55
172
|
)
|
|
56
173
|
|
|
57
174
|
# search columns
|
|
175
|
+
|
|
176
|
+
"""
|
|
177
|
+
Search parameter: Filter by hierarchy depth level.
|
|
178
|
+
"""
|
|
58
179
|
hierarchy_depth = String(is_searchable=True, is_temporary=True)
|
|
180
|
+
|
|
181
|
+
"""
|
|
182
|
+
Search parameter: Filter by Git repository URLs.
|
|
183
|
+
"""
|
|
59
184
|
git_repositories = StringList(is_searchable=True, is_temporary=True)
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
Search parameter: Filter by entity types (e.g., "service", "domain").
|
|
188
|
+
"""
|
|
60
189
|
types = StringList(is_searchable=True, is_temporary=True)
|
|
190
|
+
|
|
191
|
+
"""
|
|
192
|
+
Search parameter: Free-text search query.
|
|
193
|
+
"""
|
|
61
194
|
query = String(is_searchable=True, is_temporary=True)
|
|
195
|
+
|
|
196
|
+
"""
|
|
197
|
+
Search parameter: Include archived entities in results.
|
|
198
|
+
"""
|
|
62
199
|
include_archived = Boolean(is_searchable=True, is_temporary=True)
|
|
200
|
+
|
|
201
|
+
"""
|
|
202
|
+
Search parameter: Include metadata in response.
|
|
203
|
+
"""
|
|
63
204
|
include_metadata = Boolean(is_searchable=True, is_temporary=True)
|
|
205
|
+
|
|
206
|
+
"""
|
|
207
|
+
Search parameter: Include links in response.
|
|
208
|
+
"""
|
|
64
209
|
include_links = Boolean(is_searchable=True, is_temporary=True)
|
|
210
|
+
|
|
211
|
+
"""
|
|
212
|
+
Search parameter: Include owner information in response.
|
|
213
|
+
"""
|
|
65
214
|
include_owners = Boolean(is_searchable=True)
|
|
215
|
+
|
|
216
|
+
"""
|
|
217
|
+
Search parameter: Include nested fields in response (e.g., "team:members").
|
|
218
|
+
"""
|
|
66
219
|
include_nested_fields = StringList(is_searchable=True, is_temporary=True)
|
|
220
|
+
|
|
221
|
+
"""
|
|
222
|
+
Search parameter: Include hierarchy fields in response (e.g., "groups").
|
|
223
|
+
"""
|
|
67
224
|
include_hierarchy_fields = StringList(is_searchable=True, is_temporary=True)
|
|
68
225
|
|
|
69
226
|
def parse_hierarchy(self) -> dataclasses.ServiceEntityHierarchy:
|
|
@@ -7,7 +7,35 @@ from clearskies_cortex.models import cortex_catalog_entity
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CortexCatalogEntityDomain(cortex_catalog_entity.CortexCatalogEntity):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Model for Cortex domain entities.
|
|
12
|
+
|
|
13
|
+
This model extends CortexCatalogEntity to specifically handle domain-type entities
|
|
14
|
+
in the Cortex catalog. Domains represent logical groupings of services and can be
|
|
15
|
+
organized hierarchically.
|
|
16
|
+
|
|
17
|
+
The model automatically filters for domain entities and includes nested fields for
|
|
18
|
+
team members, owners, metadata, and hierarchy groups.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from clearskies_cortex.models import CortexCatalogEntityDomain
|
|
22
|
+
|
|
23
|
+
# Fetch all domains
|
|
24
|
+
domains = CortexCatalogEntityDomain()
|
|
25
|
+
for domain in domains.get_final_query():
|
|
26
|
+
print(f"Domain: {domain.name}")
|
|
27
|
+
|
|
28
|
+
# Get the top-level domain for a given domain
|
|
29
|
+
domain = domains.find("tag=my-domain")
|
|
30
|
+
top_level = domain.get_top_level_domain()
|
|
31
|
+
print(f"Top-level domain: {top_level.name}")
|
|
32
|
+
|
|
33
|
+
# Get the immediate parent domain
|
|
34
|
+
parent = domain.get_parent()
|
|
35
|
+
if parent.exists():
|
|
36
|
+
print(f"Parent domain: {parent.name}")
|
|
37
|
+
```
|
|
38
|
+
"""
|
|
11
39
|
|
|
12
40
|
def get_final_query(self) -> Query:
|
|
13
41
|
return (
|
|
@@ -7,7 +7,25 @@ from clearskies_cortex.backends import CortexBackend
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CortexCatalogEntityGroup(Model):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Model for Cortex entity groups.
|
|
12
|
+
|
|
13
|
+
This model represents groups associated with a specific catalog entity in Cortex.
|
|
14
|
+
Groups are used to categorize and organize entities with key-value pairs.
|
|
15
|
+
|
|
16
|
+
The model connects to the Cortex API endpoint `catalog/{entity_tag}/groups` to fetch
|
|
17
|
+
group information for a specific entity.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from clearskies_cortex.models import CortexCatalogEntityGroup
|
|
21
|
+
|
|
22
|
+
# Fetch groups for a specific entity
|
|
23
|
+
groups = CortexCatalogEntityGroup()
|
|
24
|
+
entity_groups = groups.where("entity_tag=my-service")
|
|
25
|
+
for group in entity_groups:
|
|
26
|
+
print(f"Group tag: {group.tag}")
|
|
27
|
+
```
|
|
28
|
+
"""
|
|
11
29
|
|
|
12
30
|
id_column_name: str = "entity_tag"
|
|
13
31
|
|
|
@@ -18,5 +36,12 @@ class CortexCatalogEntityGroup(Model):
|
|
|
18
36
|
"""Return the slug of the api endpoint for this model."""
|
|
19
37
|
return "catalog/{entity_tag}/groups"
|
|
20
38
|
|
|
39
|
+
"""
|
|
40
|
+
The tag identifier of the parent entity this group belongs to.
|
|
41
|
+
"""
|
|
21
42
|
entity_tag = String()
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
JSON object containing the group tag information.
|
|
46
|
+
"""
|
|
22
47
|
tag = Json()
|
|
@@ -8,7 +8,27 @@ from clearskies_cortex.backends import CortexBackend
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class CortexCatalogEntityScorecard(Model):
|
|
11
|
-
"""
|
|
11
|
+
"""
|
|
12
|
+
Model for Cortex entity scorecards.
|
|
13
|
+
|
|
14
|
+
This model represents scorecard data associated with a specific catalog entity in Cortex.
|
|
15
|
+
Scorecards track compliance, quality, and other metrics for entities based on defined rules.
|
|
16
|
+
|
|
17
|
+
The model connects to the Cortex API endpoint `catalog/:entity_tag/scorecards` to fetch
|
|
18
|
+
scorecard scores and ladder level information for a specific entity.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from clearskies_cortex.models import CortexCatalogEntityScorecard
|
|
22
|
+
|
|
23
|
+
# Fetch scorecards for a specific entity
|
|
24
|
+
scorecards = CortexCatalogEntityScorecard()
|
|
25
|
+
entity_scorecards = scorecards.where("entity_tag=my-service")
|
|
26
|
+
for scorecard in entity_scorecards:
|
|
27
|
+
print(f"Scorecard: {scorecard.score_card_name}")
|
|
28
|
+
print(f"Score: {scorecard.score}/{scorecard.total_possible_score}")
|
|
29
|
+
print(f"Percentage: {scorecard.score_percentage}%")
|
|
30
|
+
```
|
|
31
|
+
"""
|
|
12
32
|
|
|
13
33
|
id_column_name: str = "scorecard_id"
|
|
14
34
|
|
|
@@ -19,12 +39,41 @@ class CortexCatalogEntityScorecard(Model):
|
|
|
19
39
|
"""Return the slug of the api endpoint for this model."""
|
|
20
40
|
return "catalog/:entity_tag/scorecards"
|
|
21
41
|
|
|
42
|
+
"""
|
|
43
|
+
The unique identifier for the scorecard.
|
|
44
|
+
"""
|
|
22
45
|
scorecard_id = Integer()
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
The tag identifier of the entity this scorecard belongs to.
|
|
49
|
+
"""
|
|
23
50
|
entity_tag = String()
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
JSON object containing ladder level information.
|
|
54
|
+
|
|
55
|
+
Ladder levels define maturity stages for the scorecard (e.g., Bronze, Silver, Gold).
|
|
56
|
+
"""
|
|
24
57
|
ladder_levels = Json()
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
The current score achieved by the entity for this scorecard.
|
|
61
|
+
"""
|
|
25
62
|
score = Integer()
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
The score as a percentage of the total possible score.
|
|
66
|
+
"""
|
|
26
67
|
score_percentage = Float()
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
The human-readable name of the scorecard.
|
|
71
|
+
"""
|
|
27
72
|
score_card_name = String()
|
|
73
|
+
|
|
74
|
+
"""
|
|
75
|
+
The maximum possible score for this scorecard.
|
|
76
|
+
"""
|
|
28
77
|
total_possible_score = Integer()
|
|
29
78
|
|
|
30
79
|
def get_score_card_tag_name(self) -> str:
|
|
@@ -16,7 +16,41 @@ from clearskies_cortex.models import (
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class CortexCatalogEntityService(cortex_catalog_entity.CortexCatalogEntity):
|
|
19
|
-
"""
|
|
19
|
+
"""
|
|
20
|
+
Model for Cortex service entities.
|
|
21
|
+
|
|
22
|
+
This model extends CortexCatalogEntity to specifically handle service-type entities
|
|
23
|
+
in the Cortex catalog. Services represent individual applications, microservices, or
|
|
24
|
+
other software components tracked in Cortex.
|
|
25
|
+
|
|
26
|
+
The model automatically filters for service entities and includes nested fields for
|
|
27
|
+
team members, owners, metadata, and hierarchy groups. It also provides methods to
|
|
28
|
+
navigate team and domain relationships.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from clearskies_cortex.models import CortexCatalogEntityService
|
|
32
|
+
|
|
33
|
+
# Fetch all services
|
|
34
|
+
services = CortexCatalogEntityService()
|
|
35
|
+
for service in services.get_final_query():
|
|
36
|
+
print(f"Service: {service.name}")
|
|
37
|
+
|
|
38
|
+
# Get the owning team for a service
|
|
39
|
+
service = services.find("tag=my-service")
|
|
40
|
+
team = service.get_team()
|
|
41
|
+
if team.exists():
|
|
42
|
+
print(f"Owned by team: {team.get_name()}")
|
|
43
|
+
|
|
44
|
+
# Get the top-level team in the hierarchy
|
|
45
|
+
top_team = service.get_top_level_team()
|
|
46
|
+
print(f"Top-level team: {top_team.get_name()}")
|
|
47
|
+
|
|
48
|
+
# Get the parent domain for a service
|
|
49
|
+
parent_domain = service.get_parent_domain()
|
|
50
|
+
if parent_domain.exists():
|
|
51
|
+
print(f"Parent domain: {parent_domain.name}")
|
|
52
|
+
```
|
|
53
|
+
"""
|
|
20
54
|
|
|
21
55
|
backend = CortexBackend()
|
|
22
56
|
|
|
@@ -7,7 +7,36 @@ from clearskies_cortex.models import cortex_catalog_entity
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CortexCatalogEntityTeam(cortex_catalog_entity.CortexCatalogEntity):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Model for Cortex team entities.
|
|
12
|
+
|
|
13
|
+
This model extends CortexCatalogEntity to specifically handle team-type entities
|
|
14
|
+
in the Cortex catalog. Teams represent organizational units that own and manage
|
|
15
|
+
services and other entities.
|
|
16
|
+
|
|
17
|
+
The model automatically filters for team entities and includes nested fields for
|
|
18
|
+
team members, owners, metadata, and hierarchy groups. It provides methods to
|
|
19
|
+
navigate the team hierarchy.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from clearskies_cortex.models import CortexCatalogEntityTeam
|
|
23
|
+
|
|
24
|
+
# Fetch all team entities
|
|
25
|
+
teams = CortexCatalogEntityTeam()
|
|
26
|
+
for team in teams.get_final_query():
|
|
27
|
+
print(f"Team: {team.name}")
|
|
28
|
+
|
|
29
|
+
# Get the top-level team in the hierarchy
|
|
30
|
+
team = teams.find("tag=my-team")
|
|
31
|
+
top_team = team.get_top_level_team()
|
|
32
|
+
print(f"Top-level team: {top_team.name}")
|
|
33
|
+
|
|
34
|
+
# Get the immediate parent team
|
|
35
|
+
parent = team.get_parent()
|
|
36
|
+
if parent.exists():
|
|
37
|
+
print(f"Parent team: {parent.name}")
|
|
38
|
+
```
|
|
39
|
+
"""
|
|
11
40
|
|
|
12
41
|
def get_final_query(self) -> Query:
|
|
13
42
|
return (
|
|
@@ -7,7 +7,25 @@ from clearskies_cortex.backends import CortexBackend
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CortexCatalogEntityType(Model):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Model for Cortex entity type definitions.
|
|
12
|
+
|
|
13
|
+
This model represents the available entity types in the Cortex catalog. Entity types
|
|
14
|
+
define the schema and structure for different kinds of entities (e.g., service, domain, team).
|
|
15
|
+
|
|
16
|
+
The model connects to the Cortex API endpoint `catalog/definitions` to fetch
|
|
17
|
+
entity type definitions.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from clearskies_cortex.models import CortexCatalogEntityType
|
|
21
|
+
|
|
22
|
+
# Fetch all entity type definitions
|
|
23
|
+
entity_types = CortexCatalogEntityType()
|
|
24
|
+
for entity_type in entity_types:
|
|
25
|
+
print(f"Type: {entity_type.name}")
|
|
26
|
+
print(f"Description: {entity_type.description}")
|
|
27
|
+
```
|
|
28
|
+
"""
|
|
11
29
|
|
|
12
30
|
id_column_name: str = "type"
|
|
13
31
|
|
|
@@ -18,8 +36,27 @@ class CortexCatalogEntityType(Model):
|
|
|
18
36
|
"""Return the slug of the api endpoint for this model."""
|
|
19
37
|
return "catalog/definitions"
|
|
20
38
|
|
|
39
|
+
"""
|
|
40
|
+
The human-readable name of the entity type.
|
|
41
|
+
"""
|
|
21
42
|
name = String()
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
A description of what this entity type represents.
|
|
46
|
+
"""
|
|
22
47
|
description = String()
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
JSON object containing the schema definition for this entity type.
|
|
51
|
+
"""
|
|
23
52
|
schema = Json()
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
The source of the entity type definition (e.g., "builtin", "custom").
|
|
56
|
+
"""
|
|
24
57
|
source = String()
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
The unique type identifier (e.g., "service", "domain", "team").
|
|
61
|
+
"""
|
|
25
62
|
type = String()
|
|
@@ -7,7 +7,27 @@ from clearskies_cortex.backends import CortexBackend
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CortexCatalogEntityRelationship(Model):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Model for Cortex entity relationships.
|
|
12
|
+
|
|
13
|
+
This model represents relationships between entities in the Cortex catalog.
|
|
14
|
+
Relationships define connections between entities such as dependencies,
|
|
15
|
+
ownership, or custom relationship types.
|
|
16
|
+
|
|
17
|
+
The model connects to the Cortex API endpoint
|
|
18
|
+
`catalog/:tag/relationships/:relationship_type_tag/destinations` to fetch
|
|
19
|
+
relationship destination entities.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from clearskies_cortex.models import CortexCatalogEntityRelationship
|
|
23
|
+
|
|
24
|
+
# Fetch relationship destinations for an entity
|
|
25
|
+
relationships = CortexCatalogEntityRelationship()
|
|
26
|
+
destinations = relationships.where("tag=my-service").where("relationship_type_tag=depends-on")
|
|
27
|
+
for dest in destinations:
|
|
28
|
+
print(f"Depends on: {dest.name} ({dest.type})")
|
|
29
|
+
```
|
|
30
|
+
"""
|
|
11
31
|
|
|
12
32
|
id_column_name: str = "tag"
|
|
13
33
|
|
|
@@ -18,8 +38,27 @@ class CortexCatalogEntityRelationship(Model):
|
|
|
18
38
|
"""Return the slug of the api endpoint for this model."""
|
|
19
39
|
return "catalog/:tag/relationships/:relationship_type_tag/destinations"
|
|
20
40
|
|
|
41
|
+
"""
|
|
42
|
+
The unique identifier for the relationship destination entity.
|
|
43
|
+
"""
|
|
21
44
|
id = String()
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
The tag identifier of the relationship destination entity.
|
|
48
|
+
"""
|
|
22
49
|
tag = String()
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
A description of the relationship destination entity.
|
|
53
|
+
"""
|
|
23
54
|
description = String()
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
The human-readable name of the relationship destination entity.
|
|
58
|
+
"""
|
|
24
59
|
name = String()
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
The type of the relationship destination entity (e.g., "service", "domain").
|
|
63
|
+
"""
|
|
25
64
|
type = String()
|
|
@@ -4,6 +4,29 @@ from clearskies_cortex.backends import CortexBackend
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class CortexModel(Model):
|
|
7
|
-
"""
|
|
7
|
+
"""
|
|
8
|
+
Base model for Cortex API integration.
|
|
9
|
+
|
|
10
|
+
This is the foundational model class for all Cortex-related models. It pre-configures
|
|
11
|
+
the CortexBackend for API communication with the Cortex platform.
|
|
12
|
+
|
|
13
|
+
Extend this class to create models that interact with the Cortex API:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from clearskies_cortex.models import CortexModel
|
|
17
|
+
from clearskies.columns import String, Json
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MyCustomCortexModel(CortexModel):
|
|
21
|
+
id_column_name = "my_id"
|
|
22
|
+
|
|
23
|
+
my_id = String()
|
|
24
|
+
data = Json()
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def destination_name(cls):
|
|
28
|
+
return "my-endpoint"
|
|
29
|
+
```
|
|
30
|
+
"""
|
|
8
31
|
|
|
9
32
|
backend = CortexBackend()
|