Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocGenerator - Search UI integration #1691

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/DocGenerator/DocGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import re
import json
import yaml
import ast
from lib.Config import Config
from lib.CodeParser import CodeParser
from lib.Sanity import Sanity
from lib.Utils import clean_folder
from lib.IndexData import IndexData
import warnings
import logging
import argparse
Expand All @@ -26,7 +26,7 @@
class DocGenerator:
"""
brief: Main class of DocGenerator tool.
It´s in charge of walk every test file, and every group file to dump the parsed documentation
It´s in charge of walk every test file, and every group file to dump the parsed documentation.
"""
def __init__(self, config):
self.conf = config
Expand All @@ -41,7 +41,7 @@ def __init__(self, config):

def is_valid_folder(self, path):
"""
brief: Checks if a path should be ignored because its in the ignore list.
brief: Checks if a path should be ignored because it is in the ignore list.
args:
- "path (str): Folder location to be controlled"
returns: "boolean: False if the path should be ignored. True otherwise."
Expand Down Expand Up @@ -158,7 +158,7 @@ def create_test(self, path, group_id):

def parse_folder(self, path, group_id):
"""
brief: Search in a specific folder to parse possible group files and each test file
brief: Search in a specific folder to parse possible group files and each test file.
args:
- "path (string): The path of the folder to be parsed."
- "group_id (string): The id of the group where the new elements belong."
Expand Down Expand Up @@ -207,6 +207,8 @@ def start_logging(folder, debug_level=logging.INFO):
parser.add_argument('-v', help="Print version", action='store_true', dest="version")
parser.add_argument('-t', help="Test configuration", action='store_true', dest='test_config')
parser.add_argument('-d', help="Enable debug messages.", action='count', dest='debug_level')
parser.add_argument('-i', help="Indexes the data to elasticsearch.", dest='index_name')
parser.add_argument('-l', help="Indexes the data and launch the application.", dest='launch_app')
args = parser.parse_args()

if args.debug_level:
Expand All @@ -221,6 +223,14 @@ def start_logging(folder, debug_level=logging.INFO):
elif args.sanity:
sanity = Sanity(Config(CONFIG_PATH))
sanity.run()
elif args.index_name:
indexData=IndexData(args.index_name, Config(CONFIG_PATH))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: Use white spaces around "="

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

indexData.run()
elif args.launch_app:
indexData=IndexData(args.launch_app, Config(CONFIG_PATH))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

indexData.run()
os.chdir("Search-UI")
os.system("ELASTICSEARCH_HOST=http://localhost:9200 npm start")
else:
docs = DocGenerator(Config(CONFIG_PATH))
docs.run()
24 changes: 24 additions & 0 deletions docs/DocGenerator/Search-UI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/netlify-lambda
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
39 changes: 39 additions & 0 deletions docs/DocGenerator/Search-UI/functions/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This is a Netlify Function that proxies our Elasticsearch instance.
*/
import fetch from "node-fetch";
import https from "https";
import http from "http";

// Don't do this in production, this is in place to aid with demo environments which have self-signed certificates.
const httpsAgent = new https.Agent({
rejectUnauthorized: false
});

const httpAgent = new http.Agent();

exports.handler = function(event, context, callback) {
const host = process.env.ELASTICSEARCH_HOST;
const agent = host.startsWith("http:") ? httpAgent : httpsAgent;

fetch(`${host}/qa-doc/_search`, {
method: "POST",
headers: { "content-type": "application/json" },
body: event.body,
agent
})
.then(response => response.text().then(body => [response, body]))
.then(([response, body]) => {
callback(null, {
statusCode: response.status,
body: body
});
})
.catch(e => {
console.error(e);
callback(null, {
statusCode: 500,
body: `An error occurred: ${e}`
});
});
};
4 changes: 4 additions & 0 deletions docs/DocGenerator/Search-UI/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
functions = "netlify-lambda"
publish = "build/"
command = "npm run build"
Loading