feature: dynamic scope using input arguments #23

Merged
xdrm-brackets merged 4 commits from feature/dynamic-scope into 0.3.0 2021-05-19 12:06:20 +00:00
1 changed files with 21 additions and 1 deletions
Showing only changes of commit 346cc4e557 - Show all commits

View File

@ -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{},
}