From 9494991176ba67f64da63fd9d8bdfa85612e3dff Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 16 Dec 2020 20:45:07 -0500 Subject: [PATCH] Add API key type for accessing statistics --- cmd/server/assets/apikeys/index.html | 3 +- cmd/server/assets/apikeys/new.html | 17 +-- cmd/server/assets/apikeys/show.html | 216 ++++++++++++++------------- docs/api.md | 18 ++- internal/routes/adminapi.go | 33 ++-- pkg/controller/apikey/create.go | 1 + pkg/controller/middleware/apikey.go | 2 +- pkg/database/authorized_app.go | 9 +- pkg/database/authorized_app_test.go | 2 + tools/seed/main.go | 6 +- 10 files changed, 165 insertions(+), 142 deletions(-) diff --git a/cmd/server/assets/apikeys/index.html b/cmd/server/assets/apikeys/index.html index dd2d8c19a..313835523 100644 --- a/cmd/server/assets/apikeys/index.html +++ b/cmd/server/assets/apikeys/index.html @@ -75,8 +75,9 @@ {{.APIKeyPreview}} - {{if .IsAdminType}}Admin{{end}} + {{if .IsAdminType}}Admin{{end}} {{if .IsDeviceType}}Device{{end}} + {{if .IsStatsType}}Stats{{end}} {{if $canWrite}} diff --git a/cmd/server/assets/apikeys/new.html b/cmd/server/assets/apikeys/new.html index 994b846fc..daa5bf101 100644 --- a/cmd/server/assets/apikeys/new.html +++ b/cmd/server/assets/apikeys/new.html @@ -28,25 +28,18 @@

New API key

- {{if $authApp.ErrorsFor "name"}} -
- {{joinStrings ($authApp.ErrorsFor "name") ", "}} -
- {{end}} + {{template "errorable" $authApp.ErrorsFor "name"}}
- {{if $authApp.ErrorsFor "type"}} -
- {{joinStrings ($authApp.ErrorsFor "type") ", "}} -
- {{end}} + {{template "errorable" $authApp.ErrorsFor "type"}}
diff --git a/cmd/server/assets/apikeys/show.html b/cmd/server/assets/apikeys/show.html index f9a9452db..e1a597ed0 100644 --- a/cmd/server/assets/apikeys/show.html +++ b/cmd/server/assets/apikeys/show.html @@ -26,17 +26,17 @@

{{$authApp.Name}} API key

{{if $apiKey}} -
-
API key
-
- +
+
API key
+
+ - + +
-
{{end}}
@@ -61,6 +61,8 @@

{{$authApp.Name}} API key

Device (can verify codes) {{else if $authApp.IsAdminType}} Admin (can issue codes) + {{else if $authApp.IsStatsType}} + Stats (can view stats) {{else}} Unknown {{end}} @@ -68,111 +70,113 @@

{{$authApp.Name}} API key

-
-
- - Statistics -
-
-
-

Loading chart...

+ {{if $authApp.IsAdminType}} +
+
+ + Statistics
+
+
+

Loading chart...

+
+
+ + + This data is refreshed every 30 minutes. + Learn more + + + Export as: + CSV + JSON + +
- - - This data is refreshed every 30 minutes. - Learn more - - - Export as: - CSV - JSON - - -
-