Skip to content

Commit 08519ca

Browse files
authored
Merge pull request Azure#15 from kairu-ms/web
React frontend and Flask backend to list all specs
2 parents 3ac9852 + 1b828b7 commit 08519ca

28 files changed

+39085
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ __pycache__/
120120
# C extensions
121121
*.so
122122

123+
/src/backend/flask_my_extension.egg-info/
124+
/aazdev

install.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
py -3.9 -m venv aazdev
2+
./aazdev/Scripts/Activate
3+
4+
cd ./src/web
5+
npm install
6+
npm run build
7+
8+
cd ../backend
9+
pip install -r ./requirements.txt
10+
pip install -e .

src/backend/app.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from flask import Flask, request
2+
from swagger.view.specs import load_specs, get_specs_for_module
3+
import webbrowser
4+
from threading import Timer
5+
import click
6+
from flask.cli import FlaskGroup
7+
8+
def open_browser():
9+
webbrowser.open_new('http://127.0.0.1:5000/')
10+
11+
def create_app():
12+
app = Flask(__name__, static_folder='../web/build', static_url_path='/')
13+
# other setup
14+
15+
@app.route('/', defaults={'path': ''})
16+
@app.route('/<string:path>')
17+
@app.route('/<path:path>')
18+
def index(path):
19+
if '.' in path:
20+
return app.send_static_file(path)
21+
return app.send_static_file('index.html')
22+
23+
@app.route("/specifications")
24+
def get_specs():
25+
return load_specs('specs.json')
26+
27+
@app.route("/specification")
28+
def get_specs_for():
29+
return get_specs_for_module(request.args.get('name'))
30+
31+
Timer(1, open_browser).start()
32+
return app
33+
34+
@click.group(cls=FlaskGroup, create_app=create_app)
35+
def cli():
36+
"""Management script for the aazdev application."""

src/backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ inflect~=5.3.0
77
msrestazure~=0.6.4
88
knack~=0.9.0
99
lxml~=4.6.4
10+
flask~=2.0.2

src/backend/setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='flask-my-extension',
5+
entry_points={
6+
'console_scripts': [
7+
'aazdev=app:cli'
8+
],
9+
},
10+
)

src/backend/swagger/view/specs.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from ..model.specs import SwaggerSpecs
2+
import os
3+
import json
4+
5+
from utils.config import SWAGGER_PATH
6+
7+
def get_module_map(modules, module_name=None):
8+
module_map = {}
9+
for module in modules:
10+
if module_name and module.name != module_name:
11+
continue
12+
module_map[module.name] = []
13+
for resource_provider in module.get_resource_providers():
14+
for resource_id, version_map in resource_provider.get_resource_map().items():
15+
module_map[module.name].append({resource_id: [k.version for k in version_map.keys()]})
16+
return module_map
17+
18+
19+
def generate_specs():
20+
specs = SwaggerSpecs(folder_path=SWAGGER_PATH)
21+
mgmt_plane_modules = specs.get_mgmt_plane_modules()
22+
data_plane_modules = specs.get_data_plane_modules()
23+
24+
mgmt_plane_map = get_module_map(mgmt_plane_modules)
25+
data_plane_map = get_module_map(data_plane_modules)
26+
return {"mgmt":mgmt_plane_map, "data": data_plane_map}
27+
28+
def save_specs(filename):
29+
data = generate_specs()
30+
with open(filename, 'w') as outfile:
31+
json.dump(data, outfile)
32+
return data
33+
34+
def load_specs(filename):
35+
if not os.path.isfile(filename):
36+
return save_specs(filename)
37+
with open(filename, 'r') as infile:
38+
return json.load(infile)
39+
40+
def get_specs_for_module(module_name):
41+
specs = SwaggerSpecs(folder_path=SWAGGER_PATH)
42+
mgmt_plane_modules = specs.get_mgmt_plane_modules()
43+
data_plane_modules = specs.get_data_plane_modules()
44+
45+
mgmt_plane_map = get_module_map(mgmt_plane_modules, module_name)
46+
data_plane_map = get_module_map(data_plane_modules, module_name)
47+
return {"mgmt":mgmt_plane_map, "data": data_plane_map}

src/web/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

src/web/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

0 commit comments

Comments
 (0)