Skip to content

Commit 6d46f19

Browse files
- Essentially working.
1 parent 975d19b commit 6d46f19

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

docs/walkthroughs/get-google-vms.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ First, create a google service account key using the GCP Console, per [the GCP d
55

66
Then, do this in bash:
77

8-
```bash setup stackql-shell
8+
```bash setup stackql-shell credentials-path=cicd/keys/testing/google-credentials.json app-root-path=./test/tmp/.get-google-vms.stackql
99

10-
export GOOGLE_CREDENTIALS="$(cat cicd/keys/testing/google-credentials.json)";
10+
export GOOGLE_CREDENTIALS="$(cat <credentials-path>)";
1111

12-
stackql shell --approot=./test/tmp/.get-google-vms.stackql
12+
stackql shell --approot=<app-root-path>
1313
```
1414

1515
## Method
1616

1717
Do this in the `stackql` shell, replacing `<project>` with your GCP project name:
1818

19-
```sql stackql-shell input required project=ryuki-it-sandbox-01
19+
```sql stackql-shell input required project=ryuki-it-sandbox-01 region=australia-southeast1-a
2020

2121
registry pull google;
2222

@@ -25,8 +25,8 @@ select
2525
id
2626
FROM google.compute.instances
2727
WHERE
28-
project = 'ryuki-it-sandbox-01'
29-
AND zone = 'australia-southeast1-a'
28+
project = '<project>'
29+
AND zone = '<region>'
3030
;
3131

3232
```
@@ -51,8 +51,8 @@ goodbye
5151

5252
## Cleanup
5353

54-
```bash teardown best-effort
54+
```bash teardown best-effort app-root-path=./test/tmp/.get-google-vms.stackql
5555

56-
rm -rf ./test/tmp/.get-google-vms.stackql
56+
rm -rf <app-root-path>
5757

5858
```

test/python/markdown_testing/markdown_testing.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class ASTNode(object):
2525
def __init__(self, node: dict):
2626
self.node = node
2727
self.children = []
28+
self._local_vars = {}
29+
for candidate in self._get_annotations():
30+
split_list = candidate.split("=", 1)
31+
if len(split_list) == 2:
32+
self._local_vars[split_list[0]] = split_list[1]
2833
if 'children' in node:
2934
for child in node['children']:
3035
self.children.append(ASTNode(child))
@@ -39,7 +44,7 @@ def is_executable(self) -> bool:
3944
return self.get_type() == 'block_code'
4045

4146
def _get_annotations(self) -> List[str]:
42-
return self.node.get('attrs').get('info', '').split(' ')
47+
return self.node.get('attrs', {}).get('info', '').split(' ')
4348

4449
def is_stackql_shell_invocation(self) -> bool:
4550
return self._STACKQL_SHELL_INVOCATION in self._get_annotations()
@@ -55,22 +60,38 @@ def is_teardown(self) -> bool:
5560

5661
def get_execution_language(self) -> str:
5762
return self.node.get('lang', '')
63+
64+
def expand(self) -> str:
65+
return self.get_text().replace("<", "{").replace(">", "}").format(**self._local_vars)
5866

5967
def __str__(self):
6068
return json.dumps(self.node, indent=2)
6169

6270
def __repr__(self):
6371
return self.__str__()
72+
73+
74+
class MdAST(object):
75+
76+
def __init__(self, ast: List[ASTNode]):
77+
self._ast: List[ASTNode] = ast
78+
79+
def get_ordered(self) -> List[ASTNode]:
80+
return self._ast
81+
82+
def expand(self, node: ASTNode) -> str:
83+
return node.expand()
84+
85+
6486

6587
class MdParser(object):
6688

67-
def parse_markdown_file(self, file_path: str, lang=None) -> List[ASTNode]:
89+
def parse_markdown_file(self, file_path: str, lang=None) -> MdAST:
6890
markdown: mistune.Markdown = mistune.create_markdown(renderer='ast')
6991
with open(file_path, 'r') as f:
7092
txt = f.read()
7193
raw_list: List[dict] = markdown(txt)
72-
return [ASTNode(node) for node in raw_list]
73-
94+
return MdAST([ASTNode(node) for node in raw_list])
7495

7596
class WorkloadDTO(object):
7697

@@ -119,23 +140,23 @@ def orchestrate(self, file_path: str) -> WorkloadDTO:
119140
setup_str: str = f'cd {_REPOSITORY_ROOT_PATH};\n'
120141
in_session_commands: List[str] = []
121142
teardown_str: str = f'cd {_REPOSITORY_ROOT_PATH};\n'
122-
for node in ast:
143+
for node in ast.get_ordered():
123144
if node.is_executable():
124145
if node.is_setup():
125146
if setup_count < self._max_setup_blocks:
126-
setup_str += f'{node.get_text()}'
147+
setup_str += ast.expand(node)
127148
setup_count += 1
128149
else:
129150
raise KeyError(f'Maximum setup blocks exceeded: {self._max_setup_blocks}')
130151
elif node.is_teardown():
131152
if teardown_count < self._max_teardown_blocks:
132-
teardown_str += f'{node.get_text()}'
153+
teardown_str += ast.expand(node)
133154
teardown_count += 1
134155
else:
135156
raise KeyError(f'Maximum teardown blocks exceeded: {self._max_teardown_blocks}')
136157
elif node.is_stackql_shell_invocation():
137158
if invocation_count < self._max_invocations_blocks:
138-
all_commands: str = node.get_text().split('\n\n')
159+
all_commands: str = ast.expand(node).split('\n\n')
139160
in_session_commands += all_commands
140161
invocation_count += 1
141162
else:

0 commit comments

Comments
 (0)