Skip to content

Commit 037ac1f

Browse files
committed
API specification
This commit implements the API specification. The specification can be read easily on http://kairo.eti.br/ownca-rest-api/ or running the local HTTP API locally, after merge it will be available on http://github.io/ownca-rest-api/ as well. ``` pipenv shell pipenv install flask run ``` This commit has no functional implementation, and the idea is to review the API specification until it gets ready and then create the issues related to the implementation. Signed-off-by: Kairo de Araujo <[email protected]>
1 parent 91cd222 commit 037ac1f

34 files changed

+1669
-9
lines changed

.github/workflows/lint.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
name: CI
1+
name: Lint
22

33
on:
4-
push:
5-
branches: [ main ]
4+
workflow_dispatch:
65
pull_request:
76
branches: [ main ]
87

9-
workflow_dispatch:
10-
118
jobs:
129
build:
1310
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-versions: [ "3.9", "3.10", ]
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ matrix.python-versions }}
20+
21+
- name: Install tox and coverage
22+
run: pip install tox tox-gh-actions
1723

18-
- name: Run a one-line script
19-
run: echo TBD
24+
- name: Run Python tests
25+
run: tox -e lint

Pipfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
flask = "*"
8+
flask-restx = "*"
9+
10+
[dev-packages]
11+
mypy = "*"
12+
black = "==21.12b0"
13+
isort = "*"
14+
flake8 = "*"
15+
coverage = "*"
16+
pytest = "*"
17+
18+
[requires]
19+
python_version = "3.9"

Pipfile.lock

Lines changed: 446 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# ownca-rest-api
2-
OwnCA Rest API
2+
OwnCA REST API
3+
4+
---
5+
**NOTE**
6+
7+
This project still not functional. Please wait for the first functional release (0.0.1)
8+
9+
---
10+
11+
The goal of this project is provide a REST API for OwnCA, including a Docker
12+
Image ready to use on Docker hub.
13+

app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask_restx import Api
2+
3+
from src import __version__, app
4+
from src.api.v1.ca import ns as ca_v1
5+
from src.api.v1.commom_models import api_models_namespace
6+
7+
api = Api(
8+
app,
9+
version=__version__.version,
10+
title="OwnCA REST API",
11+
description="OwnCA REST API",
12+
)
13+
14+
api.add_namespace(api_models_namespace)
15+
api.add_namespace(ca_v1, path="/api/v1/ca")

docs/dist/favicon-16x16.png

665 Bytes
Loading

docs/dist/favicon-32x32.png

628 Bytes
Loading

docs/dist/oauth2-redirect.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<title>Swagger UI: OAuth2 Redirect</title>
5+
</head>
6+
<body>
7+
</body>
8+
</html>
9+
<script>
10+
'use strict';
11+
function run () {
12+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
13+
var sentState = oauth2.state;
14+
var redirectUrl = oauth2.redirectUrl;
15+
var isValid, qp, arr;
16+
17+
if (/code|token|error/.test(window.location.hash)) {
18+
qp = window.location.hash.substring(1);
19+
} else {
20+
qp = location.search.substring(1);
21+
}
22+
23+
arr = qp.split("&")
24+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
25+
qp = qp ? JSON.parse('{' + arr.join() + '}',
26+
function (key, value) {
27+
return key === "" ? value : decodeURIComponent(value)
28+
}
29+
) : {}
30+
31+
isValid = qp.state === sentState
32+
33+
if ((
34+
oauth2.auth.schema.get("flow") === "accessCode"||
35+
oauth2.auth.schema.get("flow") === "authorizationCode"
36+
) && !oauth2.auth.code) {
37+
if (!isValid) {
38+
oauth2.errCb({
39+
authId: oauth2.auth.name,
40+
source: "auth",
41+
level: "warning",
42+
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
43+
});
44+
}
45+
46+
if (qp.code) {
47+
delete oauth2.state;
48+
oauth2.auth.code = qp.code;
49+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
50+
} else {
51+
let oauthErrorMsg
52+
if (qp.error) {
53+
oauthErrorMsg = "["+qp.error+"]: " +
54+
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
55+
(qp.error_uri ? "More info: "+qp.error_uri : "");
56+
}
57+
58+
oauth2.errCb({
59+
authId: oauth2.auth.name,
60+
source: "auth",
61+
level: "error",
62+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
63+
});
64+
}
65+
} else {
66+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
67+
}
68+
window.close();
69+
}
70+
71+
window.addEventListener('DOMContentLoaded', function () {
72+
run();
73+
});
74+
</script>

docs/dist/swagger-ui-bundle.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-bundle.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-es-bundle-core.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-es-bundle-core.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-es-bundle.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-es-bundle.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-standalone-preset.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui-standalone-preset.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/swagger-ui.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Swagger UI</title>
7+
<link rel="stylesheet" type="text/css" href="dist/swagger-ui.css" >
8+
<link rel="icon" type="image/png" href="dist/favicon-32x32.png" sizes="32x32" />
9+
<link rel="icon" type="image/png" href="dist/favicon-16x16.png" sizes="16x16" />
10+
<style>
11+
html
12+
{
13+
box-sizing: border-box;
14+
overflow: -moz-scrollbars-vertical;
15+
overflow-y: scroll;
16+
}
17+
18+
*,
19+
*:before,
20+
*:after
21+
{
22+
box-sizing: inherit;
23+
}
24+
25+
body
26+
{
27+
margin:0;
28+
background: #fafafa;
29+
}
30+
</style>
31+
</head>
32+
33+
<body>
34+
<div id="swagger-ui"></div>
35+
36+
<script src="dist/swagger-ui-bundle.js" charset="UTF-8"> </script>
37+
<script src="dist/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
38+
<script>
39+
window.onload = function() {
40+
// Begin Swagger UI call region
41+
const ui = SwaggerUIBundle({
42+
url: "swagger.json",
43+
dom_id: '#swagger-ui',
44+
deepLinking: true,
45+
presets: [
46+
SwaggerUIBundle.presets.apis,
47+
SwaggerUIStandalonePreset
48+
],
49+
plugins: [
50+
SwaggerUIBundle.plugins.DownloadUrl
51+
],
52+
layout: "StandaloneLayout"
53+
})
54+
// End Swagger UI call region
55+
56+
window.ui = ui
57+
}
58+
</script>
59+
</body>
60+
</html>

0 commit comments

Comments
 (0)