Skip to content

Commit 42be0f0

Browse files
committed
chore: update and add static route tests
1 parent 733708a commit 42be0f0

File tree

14 files changed

+1472
-515
lines changed

14 files changed

+1472
-515
lines changed

riocli/project/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from munch import Munch, unmunchify
1616
from rapyuta_io_sdk_v2 import Client
1717
from rapyuta_io_sdk_v2.exceptions import HttpNotFoundError
18-
from typing_extensions import Any, override
18+
from typing_extensions import override
1919
from waiting import wait
2020

2121
from riocli.auth.util import find_project_guid
22-
from riocli.config import Configuration
22+
from riocli.config import Configuration, new_v2_client
2323
from riocli.constants import ApplyResult
24-
from riocli.exceptions import ProjectNotFound
24+
from riocli.exceptions import ProjectNotFound, ResourceNotFound
2525
from riocli.model import Model
2626

2727
PROJECT_READY_TIMEOUT = 150
@@ -73,7 +73,7 @@ def apply(
7373
# will return BadRequest error.
7474
guid = self._get_guid(v2_client, config)
7575

76-
client.update_project(project_guid=guid, body=project)
76+
v2_client.update_project(project_guid=guid, body=project)
7777
wait(
7878
self._is_ready,
7979
timeout_seconds=retry_count * retry_interval,

riocli/static_route/delete.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@
5252
type=int,
5353
default=10,
5454
)
55+
@click.pass_context
5556
@click.argument("route-name-or-regex", type=str, default="")
5657
@with_spinner(text="Deleting static route...")
5758
def delete_static_route(
59+
ctx: click.Context,
5860
route_name_or_regex: str,
5961
force: bool,
6062
delete_all: bool = False,

riocli/static_route/model.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from rapyuta_io_sdk_v2 import Client
1616
from typing_extensions import override
1717

18-
from riocli import static_route
18+
from riocli.config.config import Configuration
1919
from riocli.model import Model
2020

2121

@@ -24,21 +24,24 @@ def __init__(self, *args, **kwargs):
2424
super().__init__(*args, **kwargs)
2525
self.update(*args, **kwargs)
2626

27-
def apply(self, *args, **kwargs) -> ApplyResult:
28-
client = new_v2_client()
29-
30-
static_route = unmunchify(self)
31-
3227
@override
33-
def delete_object(self, v2_client: Client, *args, **kwargs) -> None:
34-
_ = v2_client.delete_static_route(self.metadata.name)
28+
def create_object(self, v2_client: Client, *args, **kwargs) -> Munch | None:
29+
return v2_client.create_staticroute(body=unmunchify(self)) # pyright:ignore[reportArgumentType]
3530

36-
def delete(self, *args, **kwargs) -> None:
37-
client = new_v2_client()
31+
@override
32+
def update_object(self, v2_client: Client, *args, **kwargs) -> Munch | None:
33+
return v2_client.update_staticroute(
34+
name=self.metadata.name, body=unmunchify(self)
35+
) # pyright:ignore[reportArgumentType]
3836

39-
short_id = Configuration().organization_short_id
37+
@override
38+
def delete_object(
39+
self, v2_client: Client, config: Configuration, *args, **kwargs
40+
) -> None:
41+
_ = v2_client.delete_staticroute(
42+
name=f"{self.metadata.name}-{config.organization_short_id}"
43+
)
4044

41-
try:
42-
client.delete_staticroute(f"{self.metadata.name}-{short_id}")
43-
except HttpNotFoundError:
44-
raise ResourceNotFound
45+
@override
46+
def list_dependencies(self) -> list[str] | None:
47+
return None
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: user-route-test
6+
region: jp
7+
labels:
8+
app: boundary-test
9+
spec:
10+
sourceIPRange:
11+
- 192.168.100.1
12+
---
13+
apiVersion: api.rapyuta.io/v2
14+
kind: StaticRoute
15+
metadata:
16+
name: user-routes
17+
region: jp
18+
labels:
19+
app: boundary-test
20+
spec:
21+
sourceIPRange:
22+
- 192.168.101.1
23+
---
24+
apiVersion: api.rapyuta.io/v2
25+
kind: StaticRoute
26+
metadata:
27+
name: my-user-route-1
28+
region: jp
29+
labels:
30+
app: boundary-test
31+
spec:
32+
sourceIPRange:
33+
- 192.168.102.1
34+
---
35+
apiVersion: api.rapyuta.io/v2
36+
kind: StaticRoute
37+
metadata:
38+
name: test-route-boundary
39+
region: jp
40+
labels:
41+
app: boundary-test
42+
spec:
43+
sourceIPRange:
44+
- 192.168.103.1
45+
---
46+
apiVersion: api.rapyuta.io/v2
47+
kind: StaticRoute
48+
metadata:
49+
name: boundary-test-route
50+
region: jp
51+
labels:
52+
app: boundary-test
53+
spec:
54+
sourceIPRange:
55+
- 192.168.104.1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: managed-route-2
6+
region: jp
7+
labels:
8+
app: managed-test-2
9+
spec:
10+
sourceIPRange:
11+
- 192.168.4.0/24
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
apiVersion: "api.rapyuta.io/v2"
3+
kind: "Role"
4+
metadata:
5+
name: "staticroute-viewer"
6+
labels:
7+
persona: developer
8+
spec:
9+
description: "Role to view static routes with name test-route.*"
10+
rules:
11+
12+
- resource: "staticroute"
13+
instances:
14+
- '^test-route.*'
15+
actions:
16+
- get
17+
- create
18+
19+
- resource: "staticroute"
20+
actions:
21+
- list
22+
---
23+
apiVersion: "api.rapyuta.io/v2"
24+
kind: "Role"
25+
metadata:
26+
name: "staticroute-creator"
27+
labels:
28+
persona: developer
29+
spec:
30+
description: "Role to create static routes with name user-route.*"
31+
rules:
32+
33+
- resource: "staticroute"
34+
instances:
35+
- '^user-route.*'
36+
actions:
37+
- create
38+
- get
39+
40+
- resource: "staticroute"
41+
actions:
42+
- list
43+
---
44+
apiVersion: "api.rapyuta.io/v2"
45+
kind: "Role"
46+
metadata:
47+
name: "staticroute-manager"
48+
labels:
49+
persona: admin
50+
spec:
51+
description: "Role to fully manage static routes with name managed-route.*"
52+
rules:
53+
54+
- resource: "staticroute"
55+
instances:
56+
- '^managed-route.*'
57+
actions:
58+
- create
59+
- get
60+
- update
61+
- delete
62+
63+
- resource: "staticroute"
64+
actions:
65+
- list
66+
---
67+
apiVersion: "api.rapyuta.io/v2"
68+
kind: "Role"
69+
metadata:
70+
name: "staticroute-readonly"
71+
labels:
72+
persona: viewer
73+
spec:
74+
description: "Role to only view all network static routes"
75+
rules:
76+
77+
- resource: "staticroute"
78+
instances:
79+
- ".*network.*"
80+
actions:
81+
- get
82+
83+
- resource: "staticroute"
84+
actions:
85+
- list
86+
---
87+
apiVersion: "api.rapyuta.io/v2"
88+
kind: "Role"
89+
metadata:
90+
name: "staticroute-deleter"
91+
labels:
92+
persona: cleanup
93+
spec:
94+
description: "Role to delete temp static routes only"
95+
rules:
96+
97+
- resource: "staticroute"
98+
instances:
99+
- '^temp-route.*'
100+
actions:
101+
- delete
102+
- get
103+
104+
- resource: "staticroute"
105+
actions:
106+
- list
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: test-route-4
6+
region: jp
7+
labels:
8+
app: test
9+
spec:
10+
sourceIPRange:
11+
- 192.168.10.0/24
12+
---
13+
apiVersion: api.rapyuta.io/v2
14+
kind: StaticRoute
15+
metadata:
16+
name: random-route
17+
region: jp
18+
labels:
19+
app: random
20+
spec:
21+
sourceIPRange:
22+
- 192.168.20.0/24
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: test-route-1
6+
region: jp
7+
labels:
8+
app: test
9+
spec:
10+
sourceIPRange:
11+
- 192.168.5.0/24
12+
---
13+
apiVersion: api.rapyuta.io/v2
14+
kind: StaticRoute
15+
metadata:
16+
name: test-route-2
17+
region: jp
18+
labels:
19+
app: test
20+
spec:
21+
sourceIPRange:
22+
- 192.168.6.0/24
23+
---
24+
apiVersion: api.rapyuta.io/v2
25+
kind: StaticRoute
26+
metadata:
27+
name: unauthorized-route
28+
region: jp
29+
labels:
30+
app: unauthorized
31+
spec:
32+
sourceIPRange:
33+
- 192.168.99.0/24
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: user-route-1
6+
region: jp
7+
labels:
8+
app: user-test
9+
spec:
10+
sourceIPRange:
11+
- 192.168.1.0/24
12+
---
13+
apiVersion: api.rapyuta.io/v2
14+
kind: StaticRoute
15+
metadata:
16+
name: managed-route-1
17+
region: jp
18+
labels:
19+
app: managed-test
20+
spec:
21+
sourceIPRange:
22+
- 192.168.2.0/24
23+
---
24+
apiVersion: api.rapyuta.io/v2
25+
kind: StaticRoute
26+
metadata:
27+
name: temp-route-1
28+
region: jp
29+
labels:
30+
app: temp-test
31+
spec:
32+
sourceIPRange:
33+
- 192.168.3.0/24
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: api.rapyuta.io/v2
3+
kind: StaticRoute
4+
metadata:
5+
name: network-gateway-route
6+
region: jp
7+
labels:
8+
app: network-test
9+
spec:
10+
sourceIPRange:
11+
- 10.0.0.0/8
12+
---
13+
apiVersion: api.rapyuta.io/v2
14+
kind: StaticRoute
15+
metadata:
16+
name: internal-network-route
17+
region: jp
18+
labels:
19+
app: network-test
20+
spec:
21+
sourceIPRange:
22+
- 172.16.0.0/12

0 commit comments

Comments
 (0)