mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-15 04:45:45 +01:00
feature (middleware): add environment variable in template bind
This enable binding environment variable for things like hostname that
would look like '{{ .ENV_NAME }}.example.com'
This commit is contained in:
parent
77767af252
commit
fea8c024c9
1 changed files with 9 additions and 0 deletions
|
|
@ -3,12 +3,14 @@ package ctrl
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
. "github.com/mickael-kerjean/filestash/server/middleware"
|
||||
"github.com/mickael-kerjean/filestash/server/model"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
|
@ -306,6 +308,12 @@ func SessionAuthMiddleware(ctx App, res http.ResponseWriter, req *http.Request)
|
|||
)
|
||||
return
|
||||
}
|
||||
for _, value := range os.Environ() {
|
||||
pair := strings.SplitN(value, "=", 2)
|
||||
if len(pair) == 2 {
|
||||
templateBind[fmt.Sprintf("ENV_%s", pair[0])] = pair[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Step3: create a backend connection object
|
||||
session, err := func(tb map[string]string) (map[string]string, error) {
|
||||
|
|
@ -318,6 +326,7 @@ func SessionAuthMiddleware(ctx App, res http.ResponseWriter, req *http.Request)
|
|||
[]byte(Config.Get("middleware.attribute_mapping.params").String()),
|
||||
&globalMapping,
|
||||
); err != nil {
|
||||
Log.Warning("session::authMiddlware 'attribute mapping error' %s", err.Error())
|
||||
return map[string]string{}, err
|
||||
}
|
||||
mappingToUse := map[string]string{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue