An API for Guichet #23

Merged
quentin merged 14 commits from api into main 2023-09-26 06:44:36 +00:00
6 changed files with 44 additions and 14 deletions
Showing only changes of commit d8633d7fb8 - Show all commits

7
api.go
View file

@ -22,8 +22,13 @@ func handleAPIWebsiteList(w http.ResponseWriter, r *http.Request) {
} }
if r.Method == http.MethodGet { if r.Method == http.MethodGet {
describe, err := ctrl.Describe()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ctrl.Describe()) json.NewEncoder(w).Encode(describe)
return return
} }

View file

@ -194,9 +194,8 @@ func handleWebsiteList(w http.ResponseWriter, r *http.Request) {
return return
} }
desc := ctrl.Describe() if len(ctrl.PrettyList) > 0 {
if len(desc.Websites) > 0 { http.Redirect(w, r, "/website/inspect/"+ctrl.PrettyList[0], http.StatusFound)
http.Redirect(w, r, "/website/inspect/"+desc.Websites[0].Pretty, http.StatusFound)
} else { } else {
http.Redirect(w, r, "/website/new", http.StatusFound) http.Redirect(w, r, "/website/new", http.StatusFound)
} }
@ -245,7 +244,7 @@ func handleWebsiteNew(w http.ResponseWriter, r *http.Request) {
} }
type WebsiteInspectTpl struct { type WebsiteInspectTpl struct {
Ctrl *WebsiteController Describe *WebsiteDescribe
View *WebsiteView View *WebsiteView
Err error Err error
} }
@ -288,7 +287,13 @@ func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) {
return return
} }
tpl := &WebsiteInspectTpl{ ctrl, view, processErr } describe, err := ctrl.Describe()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tpl := &WebsiteInspectTpl{ describe, view, processErr }
tWebsiteInspect := getTemplate("garage_website_inspect.html") tWebsiteInspect := getTemplate("garage_website_inspect.html")
tWebsiteInspect.Execute(w, &tpl) tWebsiteInspect.Execute(w, &tpl)

View file

@ -6,8 +6,14 @@
"ANONYMOUS::bind:*,ou=users,dc=bottin,dc=eu:", "ANONYMOUS::bind:*,ou=users,dc=bottin,dc=eu:",
"ANONYMOUS::bind:cn=admin,dc=bottin,dc=eu:", "ANONYMOUS::bind:cn=admin,dc=bottin,dc=eu:",
"*,dc=bottin,dc=eu::read:*:* !userpassword", "*,dc=bottin,dc=eu::read:*:* !userpassword",
"*::read modify:SELF:*",
"cn=admin,dc=bottin,dc=eu::read add modify delete:*:*", "cn=admin,dc=bottin,dc=eu::read add modify delete:*:*",
"*:cn=admin,ou=groups,dc=bottin,dc=eu:read add modify delete:*:*" "*:cn=admin,ou=groups,dc=bottin,dc=eu:read add modify delete:*:*",
"ANONYMOUS::bind:*,ou=invitations,dc=bottin,dc=eu:",
"*,ou=invitations,dc=bottin,dc=eu::delete:SELF:*",
"*,ou=invitations,dc=bottin,dc=eu::add:*,ou=users,dc=bottin,dc=eu:*",
"*,ou=invitations,dc=bottin,dc=eu::modifyAdd:cn=email,ou=groups,dc=bottin,dc=eu:*",
"*::read modify:SELF:*"
] ]
} }

View file

@ -60,6 +60,7 @@ func handleInvitationCode(w http.ResponseWriter, r *http.Request) {
inviteDn := config.InvitationNameAttr + "=" + code_id + "," + config.InvitationBaseDN inviteDn := config.InvitationNameAttr + "=" + code_id + "," + config.InvitationBaseDN
err = l.Bind(inviteDn, code_pw) err = l.Bind(inviteDn, code_pw)
if err != nil { if err != nil {
log.Println(err)
templateInviteInvalidCode := getTemplate("invite_invalid_code.html") templateInviteInvalidCode := getTemplate("invite_invalid_code.html")
templateInviteInvalidCode.Execute(w, nil) templateInviteInvalidCode.Execute(w, nil)
return return

View file

@ -24,7 +24,7 @@
<div class="list-group mt-3"> <div class="list-group mt-3">
{{ $view := .View }} {{ $view := .View }}
{{ range $wid := .Ctrl.List }} {{ range $wid := .Describe.Websites }}
{{ if eq $wid.Internal $view.Name.Internal }} {{ if eq $wid.Internal $view.Name.Internal }}
<a href="/website/inspect/{{ $wid.Pretty }}" class="list-group-item list-group-item-action active"> <a href="/website/inspect/{{ $wid.Pretty }}" class="list-group-item list-group-item-action active">
{{ $wid.Url }} {{ $wid.Url }}
@ -38,8 +38,8 @@
</div> </div>
<p class="text-center mt-2"> <p class="text-center mt-2">
{{ .Ctrl.WebsiteCount.Current }} sites créés sur {{ .Ctrl.WebsiteCount.Max }}<br/> {{ .Describe.AllowedWebsites.Current }} sites créés sur {{ .Describe.AllowedWebsites.Max }}<br/>
Jusqu'à {{ .Ctrl.User.Quota.WebsiteSizeBurstedPretty }} par site web Jusqu'à {{ .Describe.BurstBucketQuotaSize }} par site web
</p> </p>
</div> </div>
<div class="col-md-9"> <div class="col-md-9">

View file

@ -81,16 +81,29 @@ func NewWebsiteController(user *LoggedUser) (*WebsiteController, error) {
} }
type WebsiteDescribe struct { type WebsiteDescribe struct {
AllowedWebsites *QuotaStat `json:"quota"` AccessKeyId string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
AllowedWebsites *QuotaStat `json:"quota_website_count"`
BurstBucketQuotaSize string `json:"burst_bucket_quota_size"`
Websites []*WebsiteId `json:"vhosts"` Websites []*WebsiteId `json:"vhosts"`
} }
func (w *WebsiteController) Describe() *WebsiteDescribe { func (w *WebsiteController) Describe() (*WebsiteDescribe, error) {
s3key, err := w.User.S3KeyInfo()
if err != nil {
return nil, err
}
r := make([]*WebsiteId, 0, len(w.PrettyList)) r := make([]*WebsiteId, 0, len(w.PrettyList))
for _, k := range w.PrettyList { for _, k := range w.PrettyList {
r = append(r, w.WebsiteIdx[k]) r = append(r, w.WebsiteIdx[k])
} }
return &WebsiteDescribe { &w.WebsiteCount, r } return &WebsiteDescribe {
*s3key.AccessKeyId,
*s3key.SecretAccessKey,
&w.WebsiteCount,
w.User.Quota.WebsiteSizeBurstedPretty(),
r }, nil
} }
func (w *WebsiteController) Inspect(pretty string) (*WebsiteView, error) { func (w *WebsiteController) Inspect(pretty string) (*WebsiteView, error) {