37 lines
1,022 B
Go
37 lines
1,022 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/sirupsen/logrus"
|
||
|
"gitlab.com/mstarongitlab/linstrom/server/middlewares"
|
||
|
"gitlab.com/mstarongitlab/linstrom/storage"
|
||
|
)
|
||
|
|
||
|
// Mount under /.well-known/webfinger
|
||
|
func webfingerHandler(w http.ResponseWriter, r *http.Request) {
|
||
|
logEntry, ok := r.Context().Value(middlewares.CONTEXT_KEY_LOGRUS).(*logrus.Entry)
|
||
|
if !ok {
|
||
|
http.Error(w, "couldn't get logging entry from context", http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
store := storage.Storage{}
|
||
|
|
||
|
requestedResource := r.FormValue("resource")
|
||
|
if requestedResource == "" {
|
||
|
http.Error(w, "bad request. Include \"resource\" parameter", http.StatusBadRequest)
|
||
|
logEntry.Infoln("No resource parameter. Cancelling")
|
||
|
return
|
||
|
}
|
||
|
accName := strings.TrimPrefix(requestedResource, "acc:")
|
||
|
acc, err := store.FindLocalAccount(accName)
|
||
|
if err != nil {
|
||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||
|
logEntry.WithError(err).Warningln("couldn't find account")
|
||
|
return
|
||
|
}
|
||
|
fmt.Fprint(w, acc)
|
||
|
}
|