From f7bbdaa4b32635c3ab79aa2408b922db466da5d9 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sat, 18 May 2024 22:07:24 -0500 Subject: [PATCH] Filling out docs some more --- go.mod | 8 +- internal/darkstorm_backend/README.md | 78 +++++++++++++++++--- internal/darkstorm_backend/crash.go | 13 +++- internal/darkstorm_backend/darkstorm_test.go | 9 +++ 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 3b03944..4c16ab9 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/CalebQ42/darkstorm-server go 1.22.3 -require golang.org/x/crypto v0.23.0 - require ( - github.com/google/uuid v1.6.0 // indirect - golang.org/x/sys v0.20.0 // indirect + github.com/google/uuid v1.6.0 + golang.org/x/crypto v0.23.0 ) + +require golang.org/x/sys v0.20.0 // indirect diff --git a/internal/darkstorm_backend/README.md b/internal/darkstorm_backend/README.md index 35e8bbf..10d99db 100644 --- a/internal/darkstorm_backend/README.md +++ b/internal/darkstorm_backend/README.md @@ -8,8 +8,8 @@ This is a purposefully "simple" application backend made specifically for _my_ a ```json { - appName: "app name", - key: "API Key", + id: "API Key", + appID: "appID", death: -1, // unix timestamp when the key is no longer valid. -1 means there is not expected expiration (that can change in the future) perm: { user: true, // create and login users @@ -22,6 +22,8 @@ This is a purposefully "simple" application backend made specifically for _my_ a ### User +Users are stored per backend and not per app. + ```json { id: "UUID", @@ -36,18 +38,46 @@ This is a purposefully "simple" application backend made specifically for _my_ a } ``` -## Standard Header +### Crash Reports -Any request might or might not need these values. These values can be authenticated via the `TODO` function. +#### Individual Report + +```json +{ + count: 1, // We do not store duplicates. If a duplicate does occur + platform: "android", + error: "error", + stack: "stacktrace" +} +``` + +#### Crashes + +```json +{ + id: "UUID", + error: "error", + firstLine: "first line of error", + individual: [ + // Individual Crash Reports + ] +} +``` + +## Requests + +### Standard Header + +Any request might or might not need these headers. These values can be authenticated via the `ParseHeader` function. ```json { X-API-Key: "{API Key}", - Authorization: "Bearer {JWT Token}" + Authorization: "Bearer {JWT Token}" // No built-in functions require a JWT Token, but may be required by specific implementations. } ``` -## Error Response +### Error Response If an error status code is returned then the body will be as follows. @@ -58,23 +88,26 @@ If an error status code is returned then the body will be as follows. } ``` -## Users +### Users > TODO: Add the ability to create users and log-in through third-parties (such as Google). All requsests pertaining to users requires the `X-API-Key` header and the key must have the `users` permission. -### Create User +#### Create User > TODO: Email user to confirm. +> > TODO: Screen username for offensive words and phrases. Request: +> POST: /user/create + ```json { username: "Username", - password: "Password", + password: "Password", // Password must be email: "Email", } ``` @@ -90,19 +123,23 @@ Return: If returned status is 401, the errorCode will be one of the following: -* username +* usernameTaken * Username is already taken +* usernameDisallowed + * Username is not allowed (due to offensive words/phrases) * password - * Password does not follow rules + * Password is to short or too long. * email * Email is already linked to an account * disallowed * Username contains words/phases that are not allowed -### Login +#### Login Request: +> POST: /user + ```json { username: "Username", @@ -118,3 +155,20 @@ Return: timeout: 0, // login attempt timeout (in seconds). If non-zero, token will be empty. } ``` + +### Crash Report + +Crash reports require the `X-API-Key` header and the key must match the URL's appID and have the `crash` permission + +Request: + +> POST: /{appID}/crash + +```json +{ + id: "UUID", // This is an ignored value, but it is highly recommended to include it to prevent reporting the same crash multiple times. + platform: "android", + error: "error", + stack: "stacktrace" +} +``` diff --git a/internal/darkstorm_backend/crash.go b/internal/darkstorm_backend/crash.go index 043f315..cc87fa2 100644 --- a/internal/darkstorm_backend/crash.go +++ b/internal/darkstorm_backend/crash.go @@ -1,4 +1,15 @@ package darkstorm -type CrashReport struct{} +type IndividualCrash struct { + Platform string + Error string + Stack string + Count int +} +type CrashReport struct { + ID string + Error string + FirstLine string + Individual []IndividualCrash +} diff --git a/internal/darkstorm_backend/darkstorm_test.go b/internal/darkstorm_backend/darkstorm_test.go index a8fface..53758c2 100644 --- a/internal/darkstorm_backend/darkstorm_test.go +++ b/internal/darkstorm_backend/darkstorm_test.go @@ -1 +1,10 @@ package darkstorm + +import ( + "os" + "testing" +) + +func TestMain(t *testing.M) { + os.Exit(t.Run()) +}