mrok 0.2.2__py3-none-any.whl → 0.3.0__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.
- mrok/cli/commands/admin/list/instances.py +24 -4
- mrok/cli/commands/admin/register/extensions.py +2 -2
- mrok/cli/commands/admin/register/instances.py +3 -3
- mrok/cli/commands/admin/unregister/extensions.py +2 -2
- mrok/cli/commands/admin/unregister/instances.py +2 -2
- mrok/controller/app.py +8 -2
- mrok/controller/routes/extensions.py +30 -14
- mrok/controller/routes/instances.py +5 -1
- mrok/controller/schemas.py +13 -1
- mrok/ziti/api.py +1 -1
- mrok/ziti/identities.py +50 -20
- mrok/ziti/services.py +8 -8
- {mrok-0.2.2.dist-info → mrok-0.3.0.dist-info}/METADATA +1 -1
- {mrok-0.2.2.dist-info → mrok-0.3.0.dist-info}/RECORD +17 -17
- {mrok-0.2.2.dist-info → mrok-0.3.0.dist-info}/WHEEL +1 -1
- {mrok-0.2.2.dist-info → mrok-0.3.0.dist-info}/entry_points.txt +0 -0
- {mrok-0.2.2.dist-info → mrok-0.3.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -21,7 +21,11 @@ from mrok.ziti.constants import (
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
async def get_instances(
|
|
24
|
-
settings: Settings,
|
|
24
|
+
settings: Settings,
|
|
25
|
+
detailed: bool,
|
|
26
|
+
extension: str | None = None,
|
|
27
|
+
tags: list[str] | None = None,
|
|
28
|
+
online_only: bool = False,
|
|
25
29
|
) -> list[dict]:
|
|
26
30
|
async with ZitiManagementAPI(settings) as api:
|
|
27
31
|
tags = tags or []
|
|
@@ -29,6 +33,9 @@ async def get_instances(
|
|
|
29
33
|
identities = [
|
|
30
34
|
identity async for identity in api.identities(params={"filter": tags_to_filter(tags)})
|
|
31
35
|
]
|
|
36
|
+
if online_only:
|
|
37
|
+
identities = list(filter(lambda i: i["hasEdgeRouterConnection"], identities))
|
|
38
|
+
|
|
32
39
|
if detailed or extension:
|
|
33
40
|
for identity in identities:
|
|
34
41
|
identity["services"] = [
|
|
@@ -60,10 +67,11 @@ async def get_instances(
|
|
|
60
67
|
def render_tsv(instances: list[dict], detailed: bool) -> None:
|
|
61
68
|
console = get_console()
|
|
62
69
|
if detailed:
|
|
63
|
-
console.print("id\tname\tservices\tpolicies\ttags\tcreated\tupdated")
|
|
70
|
+
console.print("id\tname\tstatus\tservices\tpolicies\ttags\tcreated\tupdated")
|
|
64
71
|
for instance in instances:
|
|
65
72
|
console.print(
|
|
66
73
|
f"{instance['id']}\t{instance['name']}\t"
|
|
74
|
+
f"{'online' if instance['hasEdgeRouterConnection'] else 'offline'}\t"
|
|
67
75
|
f"{extract_names(instance['services'], ', ')}\t"
|
|
68
76
|
f"{extract_names(instance['policies'], ', ')}\t"
|
|
69
77
|
f"{format_tags(instance['tags'], ', ')}\t"
|
|
@@ -71,10 +79,11 @@ def render_tsv(instances: list[dict], detailed: bool) -> None:
|
|
|
71
79
|
f"{format_timestamp(instance['updatedAt'])}"
|
|
72
80
|
)
|
|
73
81
|
else:
|
|
74
|
-
console.print("id\tname\ttags\tcreated")
|
|
82
|
+
console.print("id\tname\tstatus\ttags\tcreated")
|
|
75
83
|
for instance in instances:
|
|
76
84
|
console.print(
|
|
77
85
|
f"{instance['id']}\t{instance['name']}\t"
|
|
86
|
+
f"{'online' if instance['hasEdgeRouterConnection'] else 'offline'}\t"
|
|
78
87
|
f"{format_tags(instance['tags'], ', ')}\t"
|
|
79
88
|
f"{format_timestamp(instance['createdAt'])}\t"
|
|
80
89
|
)
|
|
@@ -90,6 +99,7 @@ def render_table(instances: list[dict], detailed: bool) -> None:
|
|
|
90
99
|
)
|
|
91
100
|
table.add_column("Id", style="green")
|
|
92
101
|
table.add_column("Name", style="bold cyan")
|
|
102
|
+
table.add_column("Status", justify="center")
|
|
93
103
|
if detailed:
|
|
94
104
|
table.add_column("Associated services")
|
|
95
105
|
table.add_column("Associated service policies")
|
|
@@ -102,6 +112,7 @@ def render_table(instances: list[dict], detailed: bool) -> None:
|
|
|
102
112
|
row = [
|
|
103
113
|
instance["id"],
|
|
104
114
|
instance["name"],
|
|
115
|
+
"🟢" if instance["hasEdgeRouterConnection"] else "⚪",
|
|
105
116
|
]
|
|
106
117
|
if detailed:
|
|
107
118
|
row += [
|
|
@@ -142,6 +153,15 @@ def register(app: typer.Typer) -> None:
|
|
|
142
153
|
show_default=True,
|
|
143
154
|
),
|
|
144
155
|
] = None,
|
|
156
|
+
online_only: Annotated[
|
|
157
|
+
bool,
|
|
158
|
+
typer.Option(
|
|
159
|
+
"--online-only",
|
|
160
|
+
"-o",
|
|
161
|
+
help="Show only connected instances",
|
|
162
|
+
show_default=True,
|
|
163
|
+
),
|
|
164
|
+
] = False,
|
|
145
165
|
detailed: bool = typer.Option(
|
|
146
166
|
False,
|
|
147
167
|
"--detailed",
|
|
@@ -155,7 +175,7 @@ def register(app: typer.Typer) -> None:
|
|
|
155
175
|
),
|
|
156
176
|
):
|
|
157
177
|
"""List instances in OpenZiti (identities)."""
|
|
158
|
-
instances = asyncio.run(get_instances(ctx.obj, detailed, extension, tags))
|
|
178
|
+
instances = asyncio.run(get_instances(ctx.obj, detailed, extension, tags, online_only))
|
|
159
179
|
|
|
160
180
|
if len(instances) == 0:
|
|
161
181
|
get_console().print("No instances found.")
|
|
@@ -8,14 +8,14 @@ from rich import print
|
|
|
8
8
|
from mrok.cli.commands.admin.utils import parse_tags
|
|
9
9
|
from mrok.conf import Settings
|
|
10
10
|
from mrok.ziti.api import ZitiManagementAPI
|
|
11
|
-
from mrok.ziti.services import
|
|
11
|
+
from mrok.ziti.services import register_service
|
|
12
12
|
|
|
13
13
|
RE_EXTENSION_ID = re.compile(r"(?i)EXT-\d{4}-\d{4}")
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
async def do_register(settings: Settings, extension_id: str, tags: list[str] | None):
|
|
17
17
|
async with ZitiManagementAPI(settings) as api:
|
|
18
|
-
await
|
|
18
|
+
await register_service(settings, api, extension_id, tags=parse_tags(tags))
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def validate_extension_id(extension_id: str) -> str:
|
|
@@ -9,7 +9,7 @@ import typer
|
|
|
9
9
|
from mrok.cli.commands.admin.utils import parse_tags
|
|
10
10
|
from mrok.conf import Settings
|
|
11
11
|
from mrok.ziti.api import ZitiClientAPI, ZitiManagementAPI
|
|
12
|
-
from mrok.ziti.identities import
|
|
12
|
+
from mrok.ziti.identities import register_identity
|
|
13
13
|
|
|
14
14
|
RE_EXTENSION_ID = re.compile(r"(?i)EXT-\d{4}-\d{4}")
|
|
15
15
|
|
|
@@ -18,8 +18,8 @@ async def do_register(
|
|
|
18
18
|
settings: Settings, extension_id: str, instance_id: str, tags: list[str] | None
|
|
19
19
|
):
|
|
20
20
|
async with ZitiManagementAPI(settings) as mgmt_api, ZitiClientAPI(settings) as client_api:
|
|
21
|
-
return await
|
|
22
|
-
mgmt_api, client_api, extension_id, instance_id, tags=parse_tags(tags)
|
|
21
|
+
return await register_identity(
|
|
22
|
+
settings, mgmt_api, client_api, extension_id, instance_id, tags=parse_tags(tags)
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
|
|
@@ -5,14 +5,14 @@ import typer
|
|
|
5
5
|
|
|
6
6
|
from mrok.conf import Settings
|
|
7
7
|
from mrok.ziti.api import ZitiManagementAPI
|
|
8
|
-
from mrok.ziti.services import
|
|
8
|
+
from mrok.ziti.services import unregister_service
|
|
9
9
|
|
|
10
10
|
RE_EXTENSION_ID = re.compile(r"(?i)EXT-\d{4}-\d{4}")
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
async def do_unregister(settings: Settings, extension_id: str):
|
|
14
14
|
async with ZitiManagementAPI(settings) as api:
|
|
15
|
-
await
|
|
15
|
+
await unregister_service(settings, api, extension_id)
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def validate_extension_id(extension_id: str):
|
|
@@ -5,14 +5,14 @@ import typer
|
|
|
5
5
|
|
|
6
6
|
from mrok.conf import Settings
|
|
7
7
|
from mrok.ziti.api import ZitiManagementAPI
|
|
8
|
-
from mrok.ziti.identities import
|
|
8
|
+
from mrok.ziti.identities import unregister_identity
|
|
9
9
|
|
|
10
10
|
RE_EXTENSION_ID = re.compile(r"(?i)EXT-\d{4}-\d{4}")
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
async def do_unregister(settings: Settings, extension_id: str, instance_id: str):
|
|
14
14
|
async with ZitiManagementAPI(settings) as api:
|
|
15
|
-
await
|
|
15
|
+
await unregister_identity(settings, api, extension_id, instance_id)
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def validate_extension_id(extension_id: str):
|
mrok/controller/app.py
CHANGED
|
@@ -51,9 +51,15 @@ def setup_app():
|
|
|
51
51
|
|
|
52
52
|
# TODO: Add healthcheck
|
|
53
53
|
app.include_router(
|
|
54
|
-
extensions_router,
|
|
54
|
+
extensions_router,
|
|
55
|
+
prefix="/extensions",
|
|
56
|
+
dependencies=[Depends(authenticate)],
|
|
57
|
+
)
|
|
58
|
+
app.include_router(
|
|
59
|
+
instances_router,
|
|
60
|
+
prefix="/instances",
|
|
61
|
+
dependencies=[Depends(authenticate)],
|
|
55
62
|
)
|
|
56
|
-
app.include_router(instances_router, prefix="/instances", dependencies=[Depends(authenticate)])
|
|
57
63
|
|
|
58
64
|
settings = get_settings()
|
|
59
65
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import Annotated
|
|
2
|
+
from typing import Annotated, Literal
|
|
3
3
|
|
|
4
4
|
from fastapi import APIRouter, Body, HTTPException, status
|
|
5
5
|
|
|
@@ -14,8 +14,8 @@ from mrok.ziti.errors import (
|
|
|
14
14
|
ServiceAlreadyRegisteredError,
|
|
15
15
|
ServiceNotFoundError,
|
|
16
16
|
)
|
|
17
|
-
from mrok.ziti.identities import
|
|
18
|
-
from mrok.ziti.services import
|
|
17
|
+
from mrok.ziti.identities import register_identity, unregister_identity
|
|
18
|
+
from mrok.ziti.services import register_service, unregister_service
|
|
19
19
|
|
|
20
20
|
logger = logging.getLogger("mrok.controller")
|
|
21
21
|
|
|
@@ -83,7 +83,7 @@ async def create_extension(
|
|
|
83
83
|
],
|
|
84
84
|
):
|
|
85
85
|
try:
|
|
86
|
-
service = await
|
|
86
|
+
service = await register_service(settings, mgmt_api, data.extension.id, data.tags)
|
|
87
87
|
return ExtensionRead(
|
|
88
88
|
id=service["id"],
|
|
89
89
|
name=service["name"],
|
|
@@ -116,8 +116,26 @@ async def create_extension(
|
|
|
116
116
|
async def get_extension_by_id_or_extension_id(
|
|
117
117
|
mgmt_api: ZitiManagementAPI,
|
|
118
118
|
id_or_extension_id: str,
|
|
119
|
+
with_instances: Literal["none", "online", "offline"] = "none",
|
|
119
120
|
):
|
|
120
|
-
|
|
121
|
+
extension = await fetch_extension_or_404(mgmt_api, id_or_extension_id)
|
|
122
|
+
|
|
123
|
+
if with_instances == "none":
|
|
124
|
+
return ExtensionRead(**extension)
|
|
125
|
+
|
|
126
|
+
instances = list(
|
|
127
|
+
filter(
|
|
128
|
+
lambda ir: ir.status == with_instances,
|
|
129
|
+
[
|
|
130
|
+
InstanceRead(**identity)
|
|
131
|
+
async for identity in mgmt_api.identities(
|
|
132
|
+
{"filter": f'tags.{MROK_SERVICE_TAG_NAME} = "{extension["name"]}"'}
|
|
133
|
+
)
|
|
134
|
+
],
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
return ExtensionRead(**extension, instances=instances)
|
|
121
139
|
|
|
122
140
|
|
|
123
141
|
@router.delete(
|
|
@@ -131,7 +149,7 @@ async def delete_instance_by_id_or_extension_id(
|
|
|
131
149
|
id_or_extension_id: str,
|
|
132
150
|
):
|
|
133
151
|
try:
|
|
134
|
-
await
|
|
152
|
+
await unregister_service(settings, mgmt_api, id_or_extension_id)
|
|
135
153
|
except ServiceNotFoundError:
|
|
136
154
|
raise HTTPException(
|
|
137
155
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
@@ -185,6 +203,7 @@ async def get_extensions(
|
|
|
185
203
|
tags=["Instances"],
|
|
186
204
|
)
|
|
187
205
|
async def create_extension_instances(
|
|
206
|
+
settings: AppSettings,
|
|
188
207
|
mgmt_api: ZitiManagementAPI,
|
|
189
208
|
client_api: ZitiClientAPI,
|
|
190
209
|
id_or_extension_id: str,
|
|
@@ -205,8 +224,8 @@ async def create_extension_instances(
|
|
|
205
224
|
],
|
|
206
225
|
):
|
|
207
226
|
service = await fetch_extension_or_404(mgmt_api, id_or_extension_id)
|
|
208
|
-
identity, identity_file = await
|
|
209
|
-
mgmt_api, client_api, service["name"], data.instance.id, data.tags
|
|
227
|
+
identity, identity_file = await register_identity(
|
|
228
|
+
settings, mgmt_api, client_api, service["name"], data.instance.id, data.tags
|
|
210
229
|
)
|
|
211
230
|
return InstanceRead(
|
|
212
231
|
id=identity["id"],
|
|
@@ -272,11 +291,7 @@ async def get_instance_by_id_or_instance_id(
|
|
|
272
291
|
id_or_instance_id: str,
|
|
273
292
|
):
|
|
274
293
|
identity = await fetch_instance_or_404(mgmt_api, id_or_extension_id, id_or_instance_id)
|
|
275
|
-
return InstanceRead(
|
|
276
|
-
id=identity["id"],
|
|
277
|
-
name=identity["name"],
|
|
278
|
-
tags=identity["tags"],
|
|
279
|
-
)
|
|
294
|
+
return InstanceRead(**identity)
|
|
280
295
|
|
|
281
296
|
|
|
282
297
|
@router.delete(
|
|
@@ -285,10 +300,11 @@ async def get_instance_by_id_or_instance_id(
|
|
|
285
300
|
tags=["Instances"],
|
|
286
301
|
)
|
|
287
302
|
async def delete_instance_by_id_or_instance_id(
|
|
303
|
+
settings: AppSettings,
|
|
288
304
|
mgmt_api: ZitiManagementAPI,
|
|
289
305
|
id_or_extension_id: str,
|
|
290
306
|
id_or_instance_id: str,
|
|
291
307
|
):
|
|
292
308
|
identity = await fetch_instance_or_404(mgmt_api, id_or_extension_id, id_or_instance_id)
|
|
293
309
|
instance_id, extension_id = identity["name"].split(".")
|
|
294
|
-
await
|
|
310
|
+
await unregister_identity(settings, mgmt_api, extension_id, instance_id)
|
|
@@ -6,6 +6,7 @@ from mrok.controller.dependencies import ZitiManagementAPI
|
|
|
6
6
|
from mrok.controller.openapi import examples
|
|
7
7
|
from mrok.controller.pagination import LimitOffsetPage, paginate
|
|
8
8
|
from mrok.controller.schemas import InstanceRead
|
|
9
|
+
from mrok.ziti.constants import MROK_IDENTITY_TYPE_TAG_NAME, MROK_IDENTITY_TYPE_TAG_VALUE_INSTANCE
|
|
9
10
|
|
|
10
11
|
logger = logging.getLogger("mrok.controller")
|
|
11
12
|
|
|
@@ -68,4 +69,7 @@ async def get_instance_by_id_or_instance_id(
|
|
|
68
69
|
async def get_instances(
|
|
69
70
|
mgmt_api: ZitiManagementAPI,
|
|
70
71
|
):
|
|
71
|
-
|
|
72
|
+
params = {
|
|
73
|
+
"filter": f'tags.{MROK_IDENTITY_TYPE_TAG_NAME}="{MROK_IDENTITY_TYPE_TAG_VALUE_INSTANCE}"'
|
|
74
|
+
}
|
|
75
|
+
return await paginate(mgmt_api, "/identities", InstanceRead, extra_params=params)
|
mrok/controller/schemas.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Annotated, Any, Literal
|
|
2
4
|
|
|
3
5
|
from pydantic import (
|
|
4
6
|
BaseModel,
|
|
@@ -34,6 +36,7 @@ class ExtensionBase(BaseSchema):
|
|
|
34
36
|
|
|
35
37
|
class ExtensionRead(BaseSchema, IdSchema):
|
|
36
38
|
name: str
|
|
39
|
+
instances: list[InstanceRead] | None = None
|
|
37
40
|
|
|
38
41
|
@computed_field
|
|
39
42
|
def extension(self) -> dict:
|
|
@@ -51,6 +54,11 @@ class InstanceBase(BaseSchema):
|
|
|
51
54
|
class InstanceRead(BaseSchema, IdSchema):
|
|
52
55
|
name: str
|
|
53
56
|
identity: dict[str, Any] | None = None
|
|
57
|
+
has_edge_router_connection: bool | None = Field(
|
|
58
|
+
False,
|
|
59
|
+
alias="hasEdgeRouterConnection",
|
|
60
|
+
exclude=True,
|
|
61
|
+
)
|
|
54
62
|
|
|
55
63
|
@computed_field
|
|
56
64
|
def instance(self) -> dict:
|
|
@@ -62,6 +70,10 @@ class InstanceRead(BaseSchema, IdSchema):
|
|
|
62
70
|
_, extension_id = self.name.split(".", 1)
|
|
63
71
|
return {"id": extension_id.upper()}
|
|
64
72
|
|
|
73
|
+
@computed_field
|
|
74
|
+
def status(self) -> Literal["online", "offline"]:
|
|
75
|
+
return "online" if bool(self.has_edge_router_connection) else "offline"
|
|
76
|
+
|
|
65
77
|
|
|
66
78
|
class InstanceCreate(InstanceBase):
|
|
67
79
|
pass
|
mrok/ziti/api.py
CHANGED
|
@@ -397,7 +397,7 @@ class ZitiManagementAPI(BaseZitiAPI):
|
|
|
397
397
|
async def search_config_type(self, id_or_name: str) -> dict[str, Any] | None:
|
|
398
398
|
return await self.search_by_id_or_name("/config-types", id_or_name)
|
|
399
399
|
|
|
400
|
-
async def delete_config_type(self, config_type_id: str) ->
|
|
400
|
+
async def delete_config_type(self, config_type_id: str) -> None:
|
|
401
401
|
return await self.delete("/config-types", config_type_id)
|
|
402
402
|
|
|
403
403
|
async def get_identity(self, identity_id: str) -> dict[str, Any]:
|
mrok/ziti/identities.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import copy
|
|
1
2
|
import logging
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
4
5
|
import jwt
|
|
5
6
|
|
|
7
|
+
from mrok.conf import Settings
|
|
6
8
|
from mrok.ziti import pki
|
|
7
9
|
from mrok.ziti.api import TagsType, ZitiClientAPI, ZitiManagementAPI
|
|
8
10
|
from mrok.ziti.constants import (
|
|
@@ -16,31 +18,37 @@ from mrok.ziti.errors import (
|
|
|
16
18
|
ServiceNotFoundError,
|
|
17
19
|
UserIdentityNotFoundError,
|
|
18
20
|
)
|
|
21
|
+
from mrok.ziti.services import register_service, unregister_service
|
|
19
22
|
|
|
20
23
|
logger = logging.getLogger("mrok.ziti")
|
|
21
24
|
|
|
22
25
|
|
|
23
|
-
async def
|
|
26
|
+
async def register_identity(
|
|
27
|
+
settings: Settings,
|
|
24
28
|
mgmt_api: ZitiManagementAPI,
|
|
25
29
|
client_api: ZitiClientAPI,
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
service_external_id: str,
|
|
31
|
+
identity_external_id: str,
|
|
28
32
|
tags: TagsType | None = None,
|
|
29
33
|
):
|
|
30
|
-
service_name =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
service_name = service_external_id.lower()
|
|
35
|
+
identity_tags = copy.copy(tags or {})
|
|
36
|
+
identity_tags[MROK_SERVICE_TAG_NAME] = service_name
|
|
37
|
+
identity_tags[MROK_IDENTITY_TYPE_TAG_NAME] = MROK_IDENTITY_TYPE_TAG_VALUE_INSTANCE
|
|
34
38
|
service = await mgmt_api.search_service(service_name)
|
|
35
39
|
if not service:
|
|
36
|
-
raise ServiceNotFoundError(f"A service with name `{
|
|
40
|
+
raise ServiceNotFoundError(f"A service with name `{service_external_id}` does not exists.")
|
|
37
41
|
|
|
38
|
-
identity_name = f"{
|
|
42
|
+
identity_name = f"{identity_external_id.lower()}.{service_name}"
|
|
39
43
|
service_policy_name = f"{identity_name}:bind"
|
|
44
|
+
self_service_policy_name = f"self.{service_policy_name}"
|
|
40
45
|
|
|
41
46
|
identity = await mgmt_api.search_identity(identity_name)
|
|
42
47
|
if identity:
|
|
43
48
|
service_policy = await mgmt_api.search_service_policy(service_policy_name)
|
|
49
|
+
if service_policy:
|
|
50
|
+
await mgmt_api.delete_service_policy(service_policy["id"])
|
|
51
|
+
service_policy = await mgmt_api.search_service_policy(self_service_policy_name)
|
|
44
52
|
if service_policy:
|
|
45
53
|
await mgmt_api.delete_service_policy(service_policy["id"])
|
|
46
54
|
router_policy = await mgmt_api.search_router_policy(identity_name)
|
|
@@ -48,7 +56,7 @@ async def register_instance(
|
|
|
48
56
|
await mgmt_api.delete_router_policy(router_policy["id"])
|
|
49
57
|
await mgmt_api.delete_identity(identity["id"])
|
|
50
58
|
|
|
51
|
-
identity_id = await mgmt_api.create_user_identity(identity_name, tags=
|
|
59
|
+
identity_id = await mgmt_api.create_user_identity(identity_name, tags=identity_tags)
|
|
52
60
|
identity = await mgmt_api.get_identity(identity_id)
|
|
53
61
|
|
|
54
62
|
identity_json = await _enroll_identity(
|
|
@@ -58,33 +66,55 @@ async def register_instance(
|
|
|
58
66
|
identity,
|
|
59
67
|
mrok={
|
|
60
68
|
"identity": identity_name,
|
|
61
|
-
"extension":
|
|
62
|
-
"instance":
|
|
69
|
+
"extension": service_external_id,
|
|
70
|
+
"instance": identity_external_id,
|
|
71
|
+
"domain": settings.proxy.domain,
|
|
72
|
+
"tags": identity_tags,
|
|
63
73
|
},
|
|
64
74
|
)
|
|
65
75
|
|
|
76
|
+
self_service = await mgmt_api.search_service(identity_name)
|
|
77
|
+
if not self_service:
|
|
78
|
+
self_service = await register_service(settings, mgmt_api, identity_name, tags)
|
|
79
|
+
|
|
66
80
|
await mgmt_api.create_bind_service_policy(service_policy_name, service["id"], identity_id)
|
|
81
|
+
await mgmt_api.create_bind_service_policy(
|
|
82
|
+
self_service_policy_name,
|
|
83
|
+
self_service["id"],
|
|
84
|
+
identity_id,
|
|
85
|
+
)
|
|
67
86
|
await mgmt_api.create_router_policy(identity_name, identity_id)
|
|
68
87
|
|
|
69
88
|
return identity, identity_json
|
|
70
89
|
|
|
71
90
|
|
|
72
|
-
async def
|
|
91
|
+
async def unregister_identity(
|
|
92
|
+
settings: Settings,
|
|
73
93
|
mgmt_api: ZitiManagementAPI,
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
service_external_id: str,
|
|
95
|
+
identity_external_id: str,
|
|
76
96
|
):
|
|
77
|
-
service_name =
|
|
97
|
+
service_name = service_external_id.lower()
|
|
78
98
|
service = await mgmt_api.search_service(service_name)
|
|
79
99
|
if not service:
|
|
80
|
-
raise ServiceNotFoundError(f"A service with name `{
|
|
100
|
+
raise ServiceNotFoundError(f"A service with name `{service_external_id}` does not exists.")
|
|
81
101
|
|
|
82
|
-
identity_name = f"{
|
|
102
|
+
identity_name = f"{identity_external_id.lower()}.{service_name}"
|
|
83
103
|
service_policy_name = f"{identity_name}:bind"
|
|
84
104
|
|
|
85
105
|
identity = await mgmt_api.search_identity(identity_name)
|
|
86
106
|
if not identity:
|
|
87
|
-
raise UserIdentityNotFoundError(f"
|
|
107
|
+
raise UserIdentityNotFoundError(f"Identity `{identity_external_id}` not found.")
|
|
108
|
+
|
|
109
|
+
self_service_policy_name = f"self.{service_policy_name}"
|
|
110
|
+
|
|
111
|
+
service_policy = await mgmt_api.search_service_policy(self_service_policy_name)
|
|
112
|
+
if service_policy:
|
|
113
|
+
await mgmt_api.delete_service_policy(service_policy["id"])
|
|
114
|
+
|
|
115
|
+
self_service = await mgmt_api.search_service(identity_name)
|
|
116
|
+
if self_service:
|
|
117
|
+
await unregister_service(settings, mgmt_api, identity_name)
|
|
88
118
|
|
|
89
119
|
service_policy = await mgmt_api.search_service_policy(service_policy_name)
|
|
90
120
|
if service_policy:
|
|
@@ -120,7 +150,7 @@ async def _enroll_identity(
|
|
|
120
150
|
client_api: ZitiClientAPI,
|
|
121
151
|
identity_id: str,
|
|
122
152
|
identity: dict[str, Any] | None = None,
|
|
123
|
-
mrok: dict[str, str] | None = None,
|
|
153
|
+
mrok: dict[str, str | dict] | None = None,
|
|
124
154
|
):
|
|
125
155
|
if identity is None:
|
|
126
156
|
identity = await mgmt_api.get_identity(identity_id)
|
mrok/ziti/services.py
CHANGED
|
@@ -13,10 +13,10 @@ from mrok.ziti.errors import (
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
async def
|
|
17
|
-
settings: Settings, mgmt_api: ZitiManagementAPI,
|
|
16
|
+
async def register_service(
|
|
17
|
+
settings: Settings, mgmt_api: ZitiManagementAPI, external_id: str, tags: TagsType | None
|
|
18
18
|
) -> dict[str, Any]:
|
|
19
|
-
service_name =
|
|
19
|
+
service_name = external_id.lower()
|
|
20
20
|
registered = False
|
|
21
21
|
proxy_identity = await mgmt_api.search_identity(settings.proxy.identity)
|
|
22
22
|
if not proxy_identity:
|
|
@@ -58,17 +58,17 @@ async def register_extension(
|
|
|
58
58
|
await mgmt_api.create_service_router_policy(service_name, service_id, tags=tags)
|
|
59
59
|
registered = True
|
|
60
60
|
if not registered:
|
|
61
|
-
raise ServiceAlreadyRegisteredError(f"
|
|
61
|
+
raise ServiceAlreadyRegisteredError(f"Service `{external_id}` already registered.")
|
|
62
62
|
return service
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
async def
|
|
66
|
-
settings: Settings, mgmt_api: ZitiManagementAPI,
|
|
65
|
+
async def unregister_service(
|
|
66
|
+
settings: Settings, mgmt_api: ZitiManagementAPI, external_id: str
|
|
67
67
|
) -> None:
|
|
68
|
-
service_name =
|
|
68
|
+
service_name = external_id.lower()
|
|
69
69
|
service = await mgmt_api.search_service(service_name)
|
|
70
70
|
if not service:
|
|
71
|
-
raise ServiceNotFoundError(f"
|
|
71
|
+
raise ServiceNotFoundError(f"Service `{external_id}` not found.")
|
|
72
72
|
|
|
73
73
|
router_policy = await mgmt_api.search_service_router_policy(service_name)
|
|
74
74
|
if router_policy:
|
|
@@ -16,13 +16,13 @@ mrok/cli/commands/admin/bootstrap.py,sha256=iOnHctYajgcHrG_Idjn5Y7VVSaWYRIhdgqKS
|
|
|
16
16
|
mrok/cli/commands/admin/utils.py,sha256=wQ-qQJGFyhikMJY_CWT-G6sTEIZb-LUdj1AUZisLPBw,1363
|
|
17
17
|
mrok/cli/commands/admin/list/__init__.py,sha256=kjCMcpn1gopcrQaaHxfFh8Kyngldepnle8R2br5dJ_0,195
|
|
18
18
|
mrok/cli/commands/admin/list/extensions.py,sha256=16fhDB5ucL8su2WQnSaQ1E6MhgC4vkP9-nuHAcPpzyE,4405
|
|
19
|
-
mrok/cli/commands/admin/list/instances.py,sha256=
|
|
19
|
+
mrok/cli/commands/admin/list/instances.py,sha256=kaqeyidwUxgYqfaHXqp2m76rm5h2ErBsYyZcNeaBRwY,5912
|
|
20
20
|
mrok/cli/commands/admin/register/__init__.py,sha256=5Jb_bc2L47MEpQIrOcquzduTFWQ01Jd1U1MpqaR-Ekw,209
|
|
21
|
-
mrok/cli/commands/admin/register/extensions.py,sha256=
|
|
22
|
-
mrok/cli/commands/admin/register/instances.py,sha256=
|
|
21
|
+
mrok/cli/commands/admin/register/extensions.py,sha256=p1qX5gSQX1IGpOQjO2MJzbc09v1ebdFuPo94QzJErKk,1485
|
|
22
|
+
mrok/cli/commands/admin/register/instances.py,sha256=XB6uAchc7Rm8uAu7o3-oHaN_rS8CCIBf0QKWZGW86fI,1940
|
|
23
23
|
mrok/cli/commands/admin/unregister/__init__.py,sha256=-GjjCPX1pISbWmJK6GpKO3ijGsDQb21URjU1hNu99O4,215
|
|
24
|
-
mrok/cli/commands/admin/unregister/extensions.py,sha256=
|
|
25
|
-
mrok/cli/commands/admin/unregister/instances.py,sha256
|
|
24
|
+
mrok/cli/commands/admin/unregister/extensions.py,sha256=GR3Iwzeksk_R0GkgmCSG7iHRcUrI7ABqDi25Gbes64Y,1016
|
|
25
|
+
mrok/cli/commands/admin/unregister/instances.py,sha256=-28wL8pTXTWHVHtw93y8-dqi-Dlf0OZOnlBCKOyGo80,1138
|
|
26
26
|
mrok/cli/commands/agent/__init__.py,sha256=Jr9RDSDdRPjbVJ7NhzgjRD-jtr5hD2vvKzDe7XsLnVo,140
|
|
27
27
|
mrok/cli/commands/agent/run/__init__.py,sha256=E_IJCl3BfMffqFASe8gzJwhhQgt5bQfjhuyekVwdEBA,164
|
|
28
28
|
mrok/cli/commands/agent/run/asgi.py,sha256=aqwu_h9WyCDI2Ts8D4zTvawCETNmcke7cX3zIUyRww4,1265
|
|
@@ -31,10 +31,10 @@ mrok/cli/commands/controller/__init__.py,sha256=2xw-YVN0akiLiuGUU3XbYyZZ0ugOjQ6X
|
|
|
31
31
|
mrok/cli/commands/controller/openapi.py,sha256=QLjVao9UkB2vBaGkFi_q_jrlg4Np4ldMRwDIJsrJ7A8,1175
|
|
32
32
|
mrok/cli/commands/controller/run.py,sha256=osyjssb81xNMYZLPb6dfPR4W_BQlCxKDfvl-BIhG_1A,2460
|
|
33
33
|
mrok/controller/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
mrok/controller/app.py,sha256=
|
|
34
|
+
mrok/controller/app.py,sha256=XxCIB7N1YE52vSYfvGW2UPgEEOZ9jxDMe2l9D2SfXi8,1866
|
|
35
35
|
mrok/controller/auth.py,sha256=Kg94W8yNMs6TvUmLRYv1QeUjDy4qlGZ-_6OHa4KH1zg,2648
|
|
36
36
|
mrok/controller/pagination.py,sha256=raYpYa34q8Ckl4BXBOEdpWlKkFj6z7e6QLWr2HT7dzI,2187
|
|
37
|
-
mrok/controller/schemas.py,sha256=
|
|
37
|
+
mrok/controller/schemas.py,sha256=AaF8_bEwZTHM02apVEBAzlUb2t71zoxYaG-VHtPNeMk,1705
|
|
38
38
|
mrok/controller/dependencies/__init__.py,sha256=voewk6gjkA0OarL6HFmfT_RLqBns0Fpl-VIqK5xVAEI,202
|
|
39
39
|
mrok/controller/dependencies/conf.py,sha256=2Pa8fxJHkZ29q6UL-w6hUP_wr7WnNELfw5LlzWg1Tec,162
|
|
40
40
|
mrok/controller/dependencies/ziti.py,sha256=fYoxeJb4s6p2_3gxbExbFSRabjpvp_gZMBb3ocXZV3Y,702
|
|
@@ -42,8 +42,8 @@ mrok/controller/openapi/__init__.py,sha256=U1dw45w76CcoQagyqg_FXdMuJF3qJZZM6wG8T
|
|
|
42
42
|
mrok/controller/openapi/examples.py,sha256=ZI0BP7L6sI0z7Mq1I3uc2UrweGpzpPeGSIuf1bUKkgg,1419
|
|
43
43
|
mrok/controller/openapi/utils.py,sha256=Kn55ISAWlMJNwrJTum7iFrBvJvr81To76pCK8W-s79Q,1114
|
|
44
44
|
mrok/controller/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
45
|
-
mrok/controller/routes/extensions.py,sha256=
|
|
46
|
-
mrok/controller/routes/instances.py,sha256=
|
|
45
|
+
mrok/controller/routes/extensions.py,sha256=zoY4sNz_BIZcbly6WXM7Rbpn2jmB89njS_0xdJkoKfs,9192
|
|
46
|
+
mrok/controller/routes/instances.py,sha256=v-fn_F6JHbDZ4YUNCIZzClgHp6aC1Eu5HB7k7qBG5pk,2202
|
|
47
47
|
mrok/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
48
|
mrok/http/config.py,sha256=k8mjvD3ninJn-v1t-co-GSa3upm4b70bWyk3fwdcOh8,2161
|
|
49
49
|
mrok/http/forwarder.py,sha256=mo-Z8B8Zg6kdDX-lWEiptRv-9kJU9cEdmg6gt6eF0cc,11374
|
|
@@ -52,15 +52,15 @@ mrok/http/master.py,sha256=TwU78yE_GQecogBs_PDpl3gY7_jWYNIRNaAXRzi0rvY,4152
|
|
|
52
52
|
mrok/http/protocol.py,sha256=ap8jbLUvgbAH81ZJZCBkQiYR7mkV_eL3rpfwEkoE8sU,392
|
|
53
53
|
mrok/http/server.py,sha256=Mj7C85fc-DXp-WTBWaOd7ag808oliLmFBH5bf-G2FHg,370
|
|
54
54
|
mrok/ziti/__init__.py,sha256=20OWMiexRhOovZOX19zlX87-V78QyWnEnSZfyAftUdE,263
|
|
55
|
-
mrok/ziti/api.py,sha256=
|
|
55
|
+
mrok/ziti/api.py,sha256=KvGiT9d4oSgC3JbFWLDQyuHcLX2HuZJoJ8nHmWtCDkY,16154
|
|
56
56
|
mrok/ziti/bootstrap.py,sha256=QIDhlkIxPW2QRuumFq2D1WDbD003P5f3z24pAUsyeBI,2696
|
|
57
57
|
mrok/ziti/constants.py,sha256=Urq1X3bCBQZfw8NbnEa1pqmY4oq1wmzkwPfzam3kbTw,339
|
|
58
58
|
mrok/ziti/errors.py,sha256=yYCbVDwktnR0AYduqtynIjo73K3HOhIrwA_vQimvEd4,368
|
|
59
|
-
mrok/ziti/identities.py,sha256=
|
|
59
|
+
mrok/ziti/identities.py,sha256=1BcwfqAJHMBhc3vRaf0aLaIkoHskj5Xe2Lsq2lO9Vs8,6735
|
|
60
60
|
mrok/ziti/pki.py,sha256=o2tySqHC8-7bvFuI2Tqxg9vX6H6ZSxWxfP_9x29e19M,1954
|
|
61
|
-
mrok/ziti/services.py,sha256=
|
|
62
|
-
mrok-0.
|
|
63
|
-
mrok-0.
|
|
64
|
-
mrok-0.
|
|
65
|
-
mrok-0.
|
|
66
|
-
mrok-0.
|
|
61
|
+
mrok/ziti/services.py,sha256=zR1PEBYwXVou20iJK4euh0ZZFAo9UB8PZk8f6SDmiUE,3194
|
|
62
|
+
mrok-0.3.0.dist-info/METADATA,sha256=5d5NEs5U_FXyVXXoZXhZgZUkdQl5N_EbFPjkDJ79whM,15546
|
|
63
|
+
mrok-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
64
|
+
mrok-0.3.0.dist-info/entry_points.txt,sha256=tloXwvU1uJicBJR2h-8HoVclPgwJWDwuREMHN8Zq-nU,38
|
|
65
|
+
mrok-0.3.0.dist-info/licenses/LICENSE.txt,sha256=6PaICaoA3yNsZKLv5G6OKqSfLSoX7MakYqTDgJoTCBs,11346
|
|
66
|
+
mrok-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|