feat: add dynamic scope from request's input
- all occurences of '[abc]' where 'abc' is a valid input name ('name' field from json) is replaced with its value between square brackets
This commit is contained in:
parent
214e2348aa
commit
346cc4e557
22
handler.go
22
handler.go
|
@ -1,7 +1,9 @@
|
|||
package aicra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.xdrm.io/go/aicra/api"
|
||||
"git.xdrm.io/go/aicra/internal/config"
|
||||
|
@ -50,8 +52,26 @@ func (s Handler) resolve(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// replace format '[a]' in scope where 'a' is an existing input's name
|
||||
scope := make([][]string, len(service.Scope))
|
||||
for a, list := range service.Scope {
|
||||
scope[a] = make([]string, len(list))
|
||||
for b, perm := range list {
|
||||
scope[a][b] = perm
|
||||
for name, value := range input.Data {
|
||||
if stringer, ok := value.(fmt.Stringer); ok {
|
||||
scope[a][b] = strings.ReplaceAll(
|
||||
scope[a][b],
|
||||
fmt.Sprintf("[%s]", name),
|
||||
fmt.Sprintf("[%s]", stringer),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var auth = api.Auth{
|
||||
Required: service.Scope,
|
||||
Required: scope,
|
||||
Active: []string{},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue