Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
89 changes: 46 additions & 43 deletions management/main.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
package main

import (
"fyp-api-gateway/management/auth"
"fyp-api-gateway/management/handler"
"log/slog"
"net/http"
)

func main() {
mux := http.NewServeMux()

// frontend routes
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
//mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// http.Redirect(w, r, "/", http.StatusSeeOther)
//})
mux.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/auth.html")
})
mux.HandleFunc("/config", auth.RequireSession(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/config.html")
}))
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
})

// account initialisation routes
mux.HandleFunc("/api/signup", auth.Signup)
mux.HandleFunc("/api/login", auth.Login)
mux.HandleFunc("/file/gateway", auth.RequireSession(handler.Gateway))

// config routes
mux.HandleFunc("/file/upload", handler.HandleNewConfig)
mux.HandleFunc("/file/findings", handler.RecvFindings)
mux.HandleFunc("/file/retrieve", handler.Findings)
mux.HandleFunc("/file/accept", handler.HandleAcceptChanges)

err := http.ListenAndServe(":81", mux)
if err != nil {
slog.Error("could not start management plane", "error", err)
}
}
package main

import (
"fyp-api-gateway/management/auth"
"fyp-api-gateway/management/handler"
"log/slog"
"net/http"
)

func main() {
mux := http.NewServeMux()

// frontend routes
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
//mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// http.Redirect(w, r, "/", http.StatusSeeOther)
//})
mux.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/auth.html")
})
mux.HandleFunc("/config", auth.RequireSession(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/config.html")
}))
mux.HandleFunc("/docs", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/docs.html")
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
})

// account initialisation routes
mux.HandleFunc("/api/signup", auth.Signup)
mux.HandleFunc("/api/login", auth.Login)
mux.HandleFunc("/file/gateway", auth.RequireSession(handler.Gateway))

// config routes
mux.HandleFunc("/file/upload", handler.HandleNewConfig)
mux.HandleFunc("/file/findings", handler.RecvFindings)
mux.HandleFunc("/file/retrieve", handler.Findings)
mux.HandleFunc("/file/accept", handler.HandleAcceptChanges)

err := http.ListenAndServe(":81", mux)
if err != nil {
slog.Error("could not start management plane", "error", err)
}
}
3 changes: 2 additions & 1 deletion management/static/auth.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<title>API Gateway - Login</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/static/styles.css" />
</head>
Expand All @@ -12,6 +12,7 @@
<a href="/auth">Signup/Login</a>
<a href="/config">Config File</a>
<a href="http://localhost:3000">Dashboard</a>
<a href="/docs">Docs</a>
</nav>
</header>

Expand Down
3 changes: 2 additions & 1 deletion management/static/config.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>API Gateway Management</title>
<title>API Gateway - Config</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/static/styles.css" />
</head>
Expand All @@ -12,6 +12,7 @@
<a href="/auth">Signup/Login</a>
<a href="/config">Config File</a>
<a href="http://localhost:3000">Dashboard</a>
<a href="/docs">Docs</a>
</nav>
</header>

Expand Down
59 changes: 59 additions & 0 deletions management/static/docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>API Gateway</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/static/styles.css" />
</head>
<body>
<header>
<nav>
<a href="/">Home</a>
<a href="/auth">Signup/Login</a>
<a href="/config">Config File</a>
<a href="http://localhost:3000">Dashboard</a>
<a href="/docs">Docs</a>
</nav>
</header>

<main id="docs">
<h1>Docs</h1>
<p>The API Gateway for Micro-services is a system that allows developers of distributed systems to aggregate their micro-service
API endpoints under a single point of entry. It facilitates consistent application of security policies across groups of endpoints,
routes traffic to the correct API endpoints, and gives detailed feedback on the behaviour of changes to a developers gateway
configuration.

The gateway provides a suite of core features, including request routing, Basic Auth authentication, rate limiting, logging and
observability through a Grafana dashboard. A management UI was developed to allow developers to configure routes and policies
associated with their micro-services. A key difference between this API Gateway and existing solutions is how the gateway handles
errors using semantics analysis. Changes are analysed by the system and presented to the user as feedback on how the changes are
expected to affect the system, as well as what errors are likely to occur.
</p>

<h2>Gateway Config File</h2>
<code>
connections:
routes:
- path:
url:
rate-limit:
zone:
rate:
auth:
</code>
<p>Below is an explanation of each part of the gateway configuration file</p>
<ul>
<li><code>connections</code>: defines the root of the yaml file</li>
<li><code>routes</code>: defines a set of routes to a micro-service</li>
<li><code>path</code>: the name of the microservice as references by the API Gateway. Should not include a leading "/". If added, it will be removed and replaced with the owner's username.</li>
<li><code>url</code>: the public URL to the micro-service the API Gateway will route to e.g. api.example.com</li>
<li><code>rate-limit</code>: defines the values set by the user for rate limiting</li>
<li><ul>
<li><code>zone</code>: The amount of memory you wish to allocate to your rate limit queue. Default is 10MB. Upper and Lower bounds have been added.</li>
<li><code>rate</code>: The number of requests per sec allowed by the system to your micro-service. Default is 5r/s. Upper and Lower bounds have been added.</li>
</ul></li>
<li><code>auth</code>: a boolean value that determines whether the owner would like the micro-service to enforce Basic Auth.</li>
</ul>
</main>
</body>
</html>
1 change: 1 addition & 0 deletions management/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<a href="/auth">Signup/Login</a>
<a href="/config">Config File</a>
<a href="http://localhost:3000">Dashboard</a>
<a href="/docs">Docs</a>
</nav>
</header>

Expand Down
39 changes: 39 additions & 0 deletions management/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,42 @@ aside section:nth-child(3) {
.modal-list li.error::before { content: '✕'; }
.modal-list li.warning { background: var(--warn-bg); color: var(--warn); }
.modal-list li.warning::before { content: '!'; font-weight: 700; }

/* Docs */
#docs h1{
font-size: 3em;
margin-bottom: 0.5em;
}

#docs p{
margin-bottom: 2em;
}

code{
font-family: 'Courier New', monospace;
font-size: 0.875em;
background: #f5f5f5;
padding: 0.1em 0.3em;
border-radius: 2px;
}

pre, code:not(li code) {
display: block;
background: #f5f5f5;
padding: 1rem 1.25rem;
margin: 1rem 0;
white-space: pre;
overflow-x: auto;
line-height: 1.6;
border-left: 3px solid #ddd;
}

ul {
padding-left: 1.5rem;
margin: 0 0 1.25rem;
}

li {
margin-bottom: 0.4rem;
color: #333;
}
Loading
Loading