mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 13:11:46 +08: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:
@ -3,12 +3,14 @@ package ctrl
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
. "github.com/mickael-kerjean/filestash/server/common"
|
. "github.com/mickael-kerjean/filestash/server/common"
|
||||||
. "github.com/mickael-kerjean/filestash/server/middleware"
|
. "github.com/mickael-kerjean/filestash/server/middleware"
|
||||||
"github.com/mickael-kerjean/filestash/server/model"
|
"github.com/mickael-kerjean/filestash/server/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@ -306,6 +308,12 @@ func SessionAuthMiddleware(ctx App, res http.ResponseWriter, req *http.Request)
|
|||||||
)
|
)
|
||||||
return
|
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
|
// Step3: create a backend connection object
|
||||||
session, err := func(tb map[string]string) (map[string]string, error) {
|
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()),
|
[]byte(Config.Get("middleware.attribute_mapping.params").String()),
|
||||||
&globalMapping,
|
&globalMapping,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
Log.Warning("session::authMiddlware 'attribute mapping error' %s", err.Error())
|
||||||
return map[string]string{}, err
|
return map[string]string{}, err
|
||||||
}
|
}
|
||||||
mappingToUse := map[string]string{}
|
mappingToUse := map[string]string{}
|
||||||
|
|||||||
Reference in New Issue
Block a user