Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit e714536

Browse files
committed
Add client side program documentation
1 parent 6677fb0 commit e714536

9 files changed

+153
-8
lines changed
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SecureDB Client Side Program Reference
2+
3+
## `SecureDB.set_api_url(api_url)`
4+
5+
Sets the URL of the SecureDB API endpoint. Typically, the value of `api_url` is `http://<db-server-ip-address>:4999/api/database` (substitute `<db-server-ip-address>` with the IP address of the server where SecureDB is running).
6+
7+
### Parameters
8+
9+
- `api_url`: The full, absolute URL of the SecureDB API endpoint.
10+
11+
## `SecureDB.set_api_key(api_key)`
12+
13+
Sets the API key to authenticate requests sent to the SecureDB API endpoint.
14+
15+
### Parameters
16+
17+
- `api_key`: The API key to authenticate requests sent to the SecureDB API endpoint. Specify the API key as a string of 32 hex digits.
18+
19+
## `SecureDB.create(model, object_)`
20+
21+
Sends a POST request to the SecureDB API endpoint to create an object. This method will return the created object if you need to access fields that are only available after committing (such as the primary key).
22+
23+
### Parameters
24+
25+
- `model`: The model you want to create, specified as a string.
26+
- `object_`: The object that you want to commit to SecureDB.
27+
28+
## `SecureDB.retrieve(model, filter_)`
29+
30+
Sends a GET request to the SecureDB API endpoint to retrieve the list of filtered object(s). This method will return a list of filtered, deserialized SQLAlchemy object(s).
31+
32+
### Parameters
33+
34+
- `model`: The model you want to query, specified as a string.
35+
- `filter_`: The filter to apply on the query.
36+
37+
## `SecureDB.update(model, filter_, values)`
38+
39+
Sends a PATCH request to the SecureDB API endpoint to update the first filtered object with the specified values.
40+
41+
### Parameters
42+
43+
- `model`: The model you want to query, specified as a string.
44+
- `filter_`: The filter to apply on the query.
45+
- `values`: The fields you want to update, specified as a dictionary (the key(s) are the name of the field(s) you want to update, and the value(s) are the new value(s) to be assigned to the corresponding field(s)).
46+
47+
## `SecureDB.delete(model, filter_)`
48+
49+
Sends a DELETE request to the SecureDB API endpoint to delete the first filtered object.
50+
51+
### Parameters
52+
53+
- `model`: The model you want to query, specified as a string.
54+
- `filter_`: The filter to apply on the query.

app.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
api_key_management_blueprint,
2121
backup_blueprint,
2222
dashboard_blueprint,
23+
documentation_blueprint,
2324
encryption_blueprint,
2425
encryption_key_management_blueprint,
2526
onboarding_blueprint,
@@ -66,6 +67,7 @@
6667
)
6768
app.register_blueprint(backup_blueprint.backup_blueprint)
6869
app.register_blueprint(dashboard_blueprint.dashboard_blueprint)
70+
app.register_blueprint(documentation_blueprint.documentation_blueprint)
6971
app.register_blueprint(encryption_blueprint.encryption_blueprint)
7072
app.register_blueprint(
7173
encryption_key_management_blueprint.encryption_key_management_blueprint

blueprints/documentation_blueprint.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Blueprint, abort, render_template
2+
from markdown import markdown
3+
4+
from helper_functions import required_permissions
5+
6+
documentation_blueprint = Blueprint("doc", __name__)
7+
8+
9+
@documentation_blueprint.route("/doc/")
10+
@required_permissions("view_api_documentation")
11+
def doc_index():
12+
return render_template("documentation-index.html")
13+
14+
15+
@documentation_blueprint.route("/doc/secure-db-client-side-program")
16+
@required_permissions("view_api_documentation")
17+
def secure_db_client_side_program_doc():
18+
try:
19+
file = open("SecureDB Client Side Program Reference.md")
20+
except FileNotFoundError:
21+
abort(404)
22+
23+
file_contents = file.read()
24+
file.close()
25+
return render_template(
26+
"documentation-template.html",
27+
title="SecureDB Client Side Program Documentation",
28+
content=markdown(file_contents),
29+
)

blueprints/encryption_blueprint.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ def upload_field():
120120
field = form.field.data
121121

122122
if request.method == "POST":
123-
client_class = client_db.session.query(eval(f'{model}'))
123+
client_class = client_db.session.query(eval(f"{model}"))
124124
for client in client_class:
125125
try:
126126
setattr(
127-
client,
128-
field,
129-
encrypt(
130-
str(getattr(client, field)), constants.ENCRYPTION_KEY
131-
).hex(),
132-
)
127+
client,
128+
field,
129+
encrypt(
130+
str(getattr(client, field)), constants.ENCRYPTION_KEY
131+
).hex(),
132+
)
133133
client_db.session.commit()
134134
flash("Encrypted!", "success")
135135
except AttributeError:

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ itsdangerous==1.1.0
2828
Jinja2==2.11.2
2929
jsonschema==3.2.0
3030
lazy-object-proxy==1.4.3
31+
Markdown==3.3.3
3132
MarkupSafe==1.1.1
3233
marshmallow==3.9.1
3334
mccabe==0.6.1

static/js/docSearch.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let docLinks = document.querySelectorAll(".doc-link");
2+
3+
document.getElementById("visible-doc-links-count").innerText = docLinks.length;
4+
document.getElementById("total-doc-links-count").innerText = docLinks.length;
5+
6+
document
7+
.getElementById("doc-search-input")
8+
.addEventListener("keyup", function (e) {
9+
let currentSearchTerm = this.value.toLowerCase();
10+
let visibleDocLinksCount = docLinks.length;
11+
docLinks.forEach((docLink) => {
12+
if (docLink.textContent.toLowerCase().includes(currentSearchTerm)) {
13+
docLink.style.display = "block";
14+
} else {
15+
docLink.style.display = "none";
16+
visibleDocLinksCount -= 1;
17+
}
18+
19+
document.getElementById(
20+
"visible-doc-links-count"
21+
).innerText = visibleDocLinksCount;
22+
});
23+
});

templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
data-toggle="dropdown">Monitoring API</a>
4747
<div class="dropdown-menu">
4848
{% if "view_api_documentation" in current_user_permissions %}
49-
<a class="dropdown-item" href="/api/doc/">API Documentation</a>
49+
<a class="dropdown-item" href="/doc/">Documentation</a>
5050
{% endif %}
5151
{% if "manage_api_keys" in current_user_permissions %}
5252
<a class="dropdown-item" href="/api/key-management">API Key

templates/documentation-index.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% extends "base.html" %}
2+
{% block title %}SecureDB Documentation{% endblock %}
3+
{% block content %}
4+
<h1>SecureDB Documentation</h1>
5+
<input id="doc-search-input" class="form-control mb-md-3" type="text"
6+
placeholder="Search for documentation..." autocomplete="off" />
7+
<p class="text-muted">Showing <span id="visible-doc-links-count"></span> of
8+
<span id="total-doc-links-count"></span> Documentation Links</p>
9+
<div class="row">
10+
<div class="doc-link col-12 col-sm-6 mt-3 mt-md-0">
11+
<div class="card">
12+
<div class="card-body">
13+
<h5 class="card-title">SecureDB API</h5>
14+
<p class="card-text text-secondary">Documentation for the SecureDB API</p>
15+
<a href="/api/doc/" class="btn btn-primary stretched-link">View</a>
16+
</div>
17+
</div>
18+
</div>
19+
<div class="doc-link col-12 col-sm-6 mt-3 mt-md-0">
20+
<div class="card">
21+
<div class="card-body">
22+
<h5 class="card-title">SecureDB Client Side Program</h5>
23+
<p class="card-text text-secondary">Documentation for the SecureDB Client Side Program</p>
24+
<a href="/doc/secure-db-client-side-program"
25+
class="btn btn-primary stretched-link">View</a>
26+
</div>
27+
</div>
28+
</div>
29+
</div>
30+
<script src="/static/js/docSearch.js"></script>
31+
{% endblock %}

templates/documentation-template.html

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "base.html" %}
2+
{% block title %}{{ title }}{% endblock %}
3+
{% block content %}
4+
{{ content | safe }}
5+
{% endblock %}

0 commit comments

Comments
 (0)