An API for Guichet #23
8 changed files with 139 additions and 147 deletions
2
api.go
2
api.go
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
2
cli.go
2
cli.go
|
@ -3,9 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"golang.org/x/term"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"golang.org/x/term"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var fsCli = flag.NewFlagSet("cli", flag.ContinueOnError)
|
var fsCli = flag.NewFlagSet("cli", flag.ContinueOnError)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func gadmin() (*garage.APIClient, context.Context) {
|
func gadmin() (*garage.APIClient, context.Context) {
|
||||||
// Set Host and other parameters
|
// Set Host and other parameters
|
||||||
configuration := garage.NewConfiguration()
|
configuration := garage.NewConfiguration()
|
||||||
|
@ -47,8 +46,6 @@ func grgGetKey(accessKey string) (*garage.KeyInfo, error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func grgCreateBucket(bucket string) (*garage.BucketInfo, error) {
|
func grgCreateBucket(bucket string) (*garage.BucketInfo, error) {
|
||||||
client, ctx := gadmin()
|
client, ctx := gadmin()
|
||||||
|
|
||||||
|
|
3
login.go
3
login.go
|
@ -112,6 +112,7 @@ type Capabilities struct {
|
||||||
CanAdmin bool
|
CanAdmin bool
|
||||||
CanInvite bool
|
CanInvite bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCapabilities(login *LoginStatus, entry *ldap.Entry) *Capabilities {
|
func NewCapabilities(login *LoginStatus, entry *ldap.Entry) *Capabilities {
|
||||||
// Initialize
|
// Initialize
|
||||||
canAdmin := false
|
canAdmin := false
|
||||||
|
@ -148,6 +149,7 @@ type LoggedUser struct {
|
||||||
Quota *UserQuota
|
Quota *UserQuota
|
||||||
s3key *garage.KeyInfo
|
s3key *garage.KeyInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLoggedUser(login *LoginStatus) (*LoggedUser, error) {
|
func NewLoggedUser(login *LoginStatus) (*LoggedUser, error) {
|
||||||
requestKind := "(objectClass=organizationalPerson)"
|
requestKind := "(objectClass=organizationalPerson)"
|
||||||
if strings.EqualFold(login.Info.DN(), config.AdminAccount) {
|
if strings.EqualFold(login.Info.DN(), config.AdminAccount) {
|
||||||
|
@ -251,7 +253,6 @@ func RequireUser(r *http.Request) (*LoggedUser, error) {
|
||||||
return nil, ErrNotAuthenticated
|
return nil, ErrNotAuthenticated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
loginStatus, err := NewLoginStatus(r, login_info)
|
loginStatus, err := NewLoginStatus(r, login_info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
1
main.go
1
main.go
|
@ -192,7 +192,6 @@ func logRequest(handler http.Handler) http.Handler {
|
||||||
|
|
||||||
// Page handlers ----
|
// Page handlers ----
|
||||||
|
|
||||||
|
|
||||||
// --- Home Controller
|
// --- Home Controller
|
||||||
type HomePageData struct {
|
type HomePageData struct {
|
||||||
User *LoggedUser
|
User *LoggedUser
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
|
||||||
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
|
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -107,6 +107,7 @@ type QuotaStat struct {
|
||||||
Ratio float64 `json:"ratio"`
|
Ratio float64 `json:"ratio"`
|
||||||
Burstable bool `json:"burstable"`
|
Burstable bool `json:"burstable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewQuotaStat(current, max int64, burstable bool) QuotaStat {
|
func NewQuotaStat(current, max int64, burstable bool) QuotaStat {
|
||||||
return QuotaStat{
|
return QuotaStat{
|
||||||
Current: current,
|
Current: current,
|
||||||
|
|
12
website.go
12
website.go
|
@ -2,9 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -19,16 +19,14 @@ var (
|
||||||
ErrBucketDeleteUnfinishedUpload = fmt.Errorf("You must remove all the unfinished multipart uploads before deleting a bucket")
|
ErrBucketDeleteUnfinishedUpload = fmt.Errorf("You must remove all the unfinished multipart uploads before deleting a bucket")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type WebsiteId struct {
|
type WebsiteId struct {
|
||||||
Pretty string `json:"name"`
|
Pretty string `json:"name"`
|
||||||
Internal string `json:"-"`
|
Internal string `json:"-"`
|
||||||
Alt []string `json:"alt_name"`
|
Alt []string `json:"alt_name"`
|
||||||
Expanded bool `json:"expanded"`
|
Expanded bool `json:"expanded"`
|
||||||
Url string `json:"domain"`
|
Url string `json:"domain"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebsiteId(id string, aliases []string) *WebsiteId {
|
func NewWebsiteId(id string, aliases []string) *WebsiteId {
|
||||||
pretty := id
|
pretty := id
|
||||||
var alt []string
|
var alt []string
|
||||||
|
@ -65,7 +63,7 @@ func NewWebsiteController(user *LoggedUser) (*WebsiteController, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bckt := range(keyInfo.Buckets) {
|
for _, bckt := range keyInfo.Buckets {
|
||||||
if len(bckt.GlobalAliases) > 0 {
|
if len(bckt.GlobalAliases) > 0 {
|
||||||
wid := NewWebsiteId(*bckt.Id, bckt.GlobalAliases)
|
wid := NewWebsiteId(*bckt.Id, bckt.GlobalAliases)
|
||||||
idx[wid.Pretty] = wid
|
idx[wid.Pretty] = wid
|
||||||
|
@ -183,7 +181,6 @@ func (w *WebsiteController) Create(pretty string) (*WebsiteView, error) {
|
||||||
ur.SetWebsiteAccess(*wr)
|
ur.SetWebsiteAccess(*wr)
|
||||||
ur.SetQuotas(*qr)
|
ur.SetQuotas(*qr)
|
||||||
|
|
||||||
|
|
||||||
binfo, err = grgUpdateBucket(*binfo.Id, ur)
|
binfo, err = grgUpdateBucket(*binfo.Id, ur)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrCantConfigureBucket
|
return nil, ErrCantConfigureBucket
|
||||||
|
@ -219,9 +216,6 @@ func (w *WebsiteController) Delete(pretty string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type WebsiteView struct {
|
type WebsiteView struct {
|
||||||
Name *WebsiteId `json:"identified_as"`
|
Name *WebsiteId `json:"identified_as"`
|
||||||
Size QuotaStat `json:"quota_size"`
|
Size QuotaStat `json:"quota_size"`
|
||||||
|
|
Loading…
Reference in a new issue