4
4
import time
5
5
from collections import defaultdict
6
6
from itertools import takewhile
7
- from typing import Any , Dict , List , Callable , Tuple , Optional
7
+ from typing import Any , Callable , Dict , List , Optional , Tuple
8
8
9
9
import requests
10
10
import urllib3
18
18
# This list is used as filter: only providers listed here get exported
19
19
providers = [
20
20
"aws" ,
21
+ "azure" ,
21
22
"gcp" ,
22
23
]
23
24
# This list is used to filter out unsupported providers from base kind diagrams
24
25
unsupported_providers = [
25
- "azure" ,
26
26
"digitalocean" ,
27
27
"dockerhub" ,
28
28
"github" ,
36
36
]
37
37
urllib3 .disable_warnings (InsecureRequestWarning )
38
38
39
- base_kinds = ["access_key" , "account" , "autoscaling_group" , "bucket" , "certificate" , "database" , "dns_record" ,
40
- "dns_record_set" , "dns_zone" , "endpoint" , "firewall" , "gateway" , "group" , "health_check" , "instance" ,
41
- "instance_profile" , "instance_type" , "ip_address" , "keypair" , "load_balancer" ,
42
- "managed_kubernetes_cluster_provider" , "network" , "network_acl" , "network_interface" , "network_share" ,
43
- "organizational_root" , "organizational_unit" , "peering_connection" , "policy" , "region" , "role" ,
44
- "routing_table" , "security_group" , "serverless_function" , "snapshot" , "stack" , "subnet" , "tunnel" , "type" ,
45
- "user" , "volume" , "volume_type" , "zone" ]
39
+ base_kinds = [
40
+ "access_key" ,
41
+ "account" ,
42
+ "autoscaling_group" ,
43
+ "bucket" ,
44
+ "certificate" ,
45
+ "database" ,
46
+ "dns_record" ,
47
+ "dns_record_set" ,
48
+ "dns_zone" ,
49
+ "endpoint" ,
50
+ "firewall" ,
51
+ "gateway" ,
52
+ "group" ,
53
+ "health_check" ,
54
+ "instance" ,
55
+ "instance_profile" ,
56
+ "instance_type" ,
57
+ "ip_address" ,
58
+ "keypair" ,
59
+ "load_balancer" ,
60
+ "managed_kubernetes_cluster_provider" ,
61
+ "network" ,
62
+ "network_acl" ,
63
+ "network_interface" ,
64
+ "network_share" ,
65
+ "organizational_root" ,
66
+ "organizational_unit" ,
67
+ "peering_connection" ,
68
+ "policy" ,
69
+ "region" ,
70
+ "role" ,
71
+ "routing_table" ,
72
+ "security_group" ,
73
+ "serverless_function" ,
74
+ "snapshot" ,
75
+ "stack" ,
76
+ "subnet" ,
77
+ "tunnel" ,
78
+ "type" ,
79
+ "user" ,
80
+ "volume" ,
81
+ "volume_type" ,
82
+ "zone" ,
83
+ ]
46
84
47
85
48
86
def get_url (url : str , params : dict = None ) -> Response :
@@ -62,20 +100,26 @@ def get_kinds() -> Tuple[Dict[str, Any], Dict[str, List[Any]]]:
62
100
all_kinds : Dict [str , Any ] = {}
63
101
for kind in get_url (f"{ core } /graph/fix/model" ).json ():
64
102
all_kinds [kind ["fqn" ]] = kind
65
- groups = [a for a in providers if kind ["fqn" ].startswith (f"{ a } _" ) and kind .get ("aggregate_root" , False )]
103
+ groups = [
104
+ a
105
+ for a in providers
106
+ if kind ["fqn" ].startswith (f"{ a } _" ) and kind .get ("aggregate_root" , False )
107
+ ]
66
108
if groups :
67
109
kinds [groups [0 ]].append (kind )
68
110
69
111
return all_kinds , kinds
70
112
71
113
72
- def write_md (provider : str ,
73
- kinds : list ,
74
- properties : Callable [[str ], Dict [str , str ]],
75
- relationship : Optional [Callable [[str ], Dict [str , str ]]] = None ) -> None :
114
+ def write_md (
115
+ provider : str ,
116
+ kinds : list ,
117
+ properties : Callable [[str ], Dict [str , str ]],
118
+ relationship : Optional [Callable [[str ], Dict [str , str ]]] = None ,
119
+ ) -> None :
76
120
if os .path .exists (f"./{ provider } .mdx" ):
77
121
# in case the file exists, read the header section until the first h2 (##)
78
- with ( open (f"./{ provider } .mdx" , "r+" ) ) as file :
122
+ with open (f"./{ provider } .mdx" , "r+" ) as file :
79
123
lines = takewhile (lambda ll : not ll .startswith ("## " ), file .readlines ())
80
124
else :
81
125
# provider file does not exist, create default header
@@ -91,19 +135,35 @@ def write_md(provider: str,
91
135
for name in sorted (a ["fqn" ] for a in kinds ):
92
136
file .write (f"## `{ name } `\n \n " )
93
137
file .write (f"<ZoomPanPinch>\n \n " )
94
- file .write (f'```kroki imgType="plantuml" imgAlt="Diagram of { name } data model"\n ' )
95
- img_str = get_url (f"{ core } /graph/fix/model/uml" , params = properties (name )).text
96
- img_str = re .sub (rf"class\s+({ '|' .join (unsupported_providers )} )\w+\s+{{\s+}}\s+" , "" , img_str )
97
- img_str = re .sub (rf"\w+\s+<\|---\s+({ '|' .join (unsupported_providers )} )\w+\s+" , "" , img_str )
138
+ file .write (
139
+ f'```kroki imgType="plantuml" imgAlt="Diagram of { name } data model"\n '
140
+ )
141
+ img_str = get_url (
142
+ f"{ core } /graph/fix/model/uml" , params = properties (name )
143
+ ).text
144
+ img_str = re .sub (
145
+ rf"class\s+({ '|' .join (unsupported_providers )} )\w+\s+{{\s+}}\s+" ,
146
+ "" ,
147
+ img_str ,
148
+ )
149
+ img_str = re .sub (
150
+ rf"\w+\s+<\|---\s+({ '|' .join (unsupported_providers )} )\w+\s+" ,
151
+ "" ,
152
+ img_str ,
153
+ )
98
154
file .write (re .sub (r"\n+" , "\n " , img_str ).strip ())
99
155
file .write ("\n ```\n \n " )
100
156
file .write ("</ZoomPanPinch>\n " )
101
157
if relationship is not None :
102
- file .write (f"<details>\n <summary>Relationships to other resources</summary>\n <div>\n " )
158
+ file .write (
159
+ f"<details>\n <summary>Relationships to other resources</summary>\n <div>\n "
160
+ )
103
161
file .write (
104
162
f'<ZoomPanPinch>\n \n ```kroki imgType="plantuml" imgAlt="Diagram of { name } resource relationships"\n '
105
163
)
106
- img_str = get_url (f"{ core } /graph/fix/model/uml" , params = relationship (name )).text
164
+ img_str = get_url (
165
+ f"{ core } /graph/fix/model/uml" , params = relationship (name )
166
+ ).text
107
167
file .write (re .sub (r"\n+" , "\n " , img_str ).strip ())
108
168
file .write (f"\n ```\n \n </ZoomPanPinch>\n </div>\n </details>\n " )
109
169
file .write ("\n " )
@@ -156,11 +216,17 @@ def show_base_diagram(name: str) -> Dict[str, str]:
156
216
157
217
all_kinds , kinds = load_valid_kinds ()
158
218
print (f"Create base kinds" )
159
- write_md ("base-kinds" , [all_kinds [bk ] for bk in base_kinds if bk in all_kinds ], show_base_diagram )
219
+ write_md (
220
+ "base-kinds" ,
221
+ [all_kinds [bk ] for bk in base_kinds if bk in all_kinds ],
222
+ show_base_diagram ,
223
+ )
160
224
for provider in providers :
161
225
if len (kinds .get (provider , [])) > 0 :
162
226
print ("---------------------------" )
163
- print (f"Create provider file: { provider } with { len (kinds [provider ])} service kinds" )
227
+ print (
228
+ f"Create provider file: { provider } with { len (kinds [provider ])} service kinds"
229
+ )
164
230
write_md (provider , kinds [provider ], class_diagram , relationship_diagram )
165
231
166
232
0 commit comments