summaryrefslogtreecommitdiff
path: root/app/middleware
diff options
context:
space:
mode:
authorJacob Weisz <ocdtrekkie@noreply@mills.io>2022-09-24 05:29:27 +0000
committerJames Mills <james@mills.io>2022-09-24 05:29:27 +0000
commit70fbc8c7b0d65fd71878520e5cb14e4a494137fa (patch)
tree33ee4a923fd9647e056304a755d775517fd34592 /app/middleware
parent29f278459156f7bd9aec225ed78706d18e001c56 (diff)
Add Sandstorm packaging files (#26)
I am not quite done here, I need to finish some of the packaging metadata, and I am going to maybe take a pass at permissions prior to release. Opening the pull request so you can easily track the progress. Note that Sandstorm app metadata is supposed to be less than 1 MB total, so I optimized your screenshots. I dare you to tell the difference with the naked eye. Co-authored-by: Jacob Weisz <inbox@jacobweisz.com> Reviewed-on: https://git.mills.io/prologic/tube/pulls/26 Co-authored-by: Jacob Weisz <ocdtrekkie@noreply@mills.io> Co-committed-by: Jacob Weisz <ocdtrekkie@noreply@mills.io>
Diffstat (limited to 'app/middleware')
-rw-r--r--app/middleware/auth.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/middleware/auth.go b/app/middleware/auth.go
index 61a58e3..c023492 100644
--- a/app/middleware/auth.go
+++ b/app/middleware/auth.go
@@ -3,6 +3,7 @@ package middleware
import (
"crypto/subtle"
"net/http"
+ "strings"
log "github.com/sirupsen/logrus"
)
@@ -48,3 +49,17 @@ func OptionallyRequireAdminAuth(handler http.HandlerFunc, password string) http.
handler(w, r)
}
}
+
+func RequireSandstormPermission(handler http.HandlerFunc, permissionNeeded string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+
+ // Failed
+ if !strings.Contains(r.Header.Get("X-Sandstorm-Permissions"), permissionNeeded) {
+ http.Error(w, "Unauthorized", http.StatusUnauthorized)
+ log.Debugln("No upload capability granted")
+ return
+ }
+
+ handler(w, r)
+ }
+}