adds swagger ui
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Marvin Steadfast 2021-05-14 09:48:45 +02:00
parent 71aa7282b5
commit 8e9b7d5e3e
21 changed files with 313 additions and 9 deletions

View File

@ -1,10 +1,34 @@
//nolint:gochecknoglobals,golint,stylecheck
package web
import "embed"
import (
"embed"
"io/fs"
"net/http"
"github.com/rs/zerolog/log"
)
//go:embed files
var Files embed.FS
var files embed.FS
var Files = sub(files, "files")
//go:embed templates
var Templates embed.FS
//go:embed swagger-ui
var swaggerUI embed.FS
var SwaggerUI = sub(swaggerUI, "swagger-ui")
func sub(f embed.FS, dir string) http.FileSystem {
fsys, err := fs.Sub(f, dir)
if err != nil {
log.Error().Err(err).Str("dir", dir).Msg("could not sub into dir")
return nil
}
return http.FS(fsys)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

View File

@ -0,0 +1,62 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link
rel="icon"
type="image/png"
href="./favicon-32x32.png"
sizes="32x32"
/>
<link
rel="icon"
type="image/png"
href="./favicon-16x16.png"
sizes="16x16"
/>
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"></script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script>
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./schnutibox.swagger.json",
dom_id: "#swagger-ui",
deepLinking: true,
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
layout: "StandaloneLayout",
});
// End Swagger UI call region
window.ui = ui;
};
</script>
</body>
</html>

View File

@ -0,0 +1,75 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
window.addEventListener('DOMContentLoaded', function () {
run();
});
</script>
</body>
</html>

View File

@ -0,0 +1,106 @@
{
"swagger": "2.0",
"info": {
"title": "schnutibox.proto",
"version": "version not set"
},
"tags": [
{
"name": "IdentifierService"
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/v1/identify": {
"post": {
"operationId": "IdentifierService_Identify",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1IdentifyResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1IdentifyRequest"
}
}
],
"tags": [
"IdentifierService"
]
}
}
},
"definitions": {
"protobufAny": {
"type": "object",
"properties": {
"typeUrl": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"rpcStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
},
"v1IdentifyRequest": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"v1IdentifyResponse": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"uris": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,8 @@
<meta charset=utf-8>
<title>schnutibox</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="/static/files/normalize.css">
<link rel="stylesheet" href="/static/files/milligram.css">
<link rel="stylesheet" href="/static/normalize.css">
<link rel="stylesheet" href="/static/milligram.css">
</head>
<body>
<div class="container">

View File

@ -12,3 +12,7 @@ plugins:
- name: grpc-gateway
out: pkg/api/v1
opt: paths=source_relative
- name: openapiv2
# out: api/openapiv2
out: assets/web/swagger-ui

View File

@ -99,15 +99,23 @@ func Run(command *cobra.Command, args []string) {
// Define http handlers.
mux := http.NewServeMux()
mux.Handle("/", logginghandler.Handler(http.HandlerFunc(root)))
mux.Handle("/log", logginghandler.Handler(http.HandlerFunc(sselog.LogHandler)))
mux.Handle("/", http.HandlerFunc(root))
mux.Handle("/log", http.HandlerFunc(sselog.LogHandler))
mux.Handle(
"/static/",
logginghandler.Handler(
http.StripPrefix("/static/", http.FileServer(http.FS(assets.Files))),
),
http.StripPrefix("/static/", http.FileServer(assets.Files)),
)
mux.Handle(
"/swagger-ui/",
http.StripPrefix("/swagger-ui/", http.FileServer(assets.SwaggerUI)),
)
mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/api/", http.StripPrefix("/api", gw(grpcServer, lh)))
// Serving http.