diff options
Diffstat (limited to 'website.go')
-rw-r--r-- | website.go | 80 |
1 files changed, 37 insertions, 43 deletions
@@ -2,33 +2,31 @@ package main import ( "fmt" + garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" "sort" "strings" - garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" ) var ( - ErrWebsiteNotFound = fmt.Errorf("Website not found") - ErrFetchBucketInfo = fmt.Errorf("Failed to fetch bucket information") - ErrWebsiteQuotaReached = fmt.Errorf("Can't create additional websites, quota reached") - ErrEmptyBucketName = fmt.Errorf("You can't create a website with an empty name") - ErrCantCreateBucket = fmt.Errorf("Can't create this bucket. Maybe another bucket already exists with this name or you have an invalid character") - ErrCantAllowKey = fmt.Errorf("Can't allow given key on the target bucket") - ErrCantConfigureBucket = fmt.Errorf("Unable to configure the bucket (activating website, adding quotas, etc.)") - ErrBucketDeleteNotEmpty = fmt.Errorf("You must remove all the files before deleting a bucket") + ErrWebsiteNotFound = fmt.Errorf("Website not found") + ErrFetchBucketInfo = fmt.Errorf("Failed to fetch bucket information") + ErrWebsiteQuotaReached = fmt.Errorf("Can't create additional websites, quota reached") + ErrEmptyBucketName = fmt.Errorf("You can't create a website with an empty name") + ErrCantCreateBucket = fmt.Errorf("Can't create this bucket. Maybe another bucket already exists with this name or you have an invalid character") + ErrCantAllowKey = fmt.Errorf("Can't allow given key on the target bucket") + ErrCantConfigureBucket = fmt.Errorf("Unable to configure the bucket (activating website, adding quotas, etc.)") + ErrBucketDeleteNotEmpty = fmt.Errorf("You must remove all the files before deleting a bucket") ErrBucketDeleteUnfinishedUpload = fmt.Errorf("You must remove all the unfinished multipart uploads before deleting a bucket") ) - - type WebsiteId struct { - Pretty string `json:"name"` - Internal string `json:"-"` - Alt []string `json:"alt_name"` - Expanded bool `json:"expanded"` - Url string `json:"domain"` - + Pretty string `json:"name"` + Internal string `json:"-"` + Alt []string `json:"alt_name"` + Expanded bool `json:"expanded"` + Url string `json:"domain"` } + func NewWebsiteId(id string, aliases []string) *WebsiteId { pretty := id var alt []string @@ -43,16 +41,16 @@ func NewWebsiteId(id string, aliases []string) *WebsiteId { url = fmt.Sprintf("%s.web.deuxfleurs.fr", pretty) } - return &WebsiteId { pretty, id, alt, expanded, url } + return &WebsiteId{pretty, id, alt, expanded, url} } func NewWebsiteIdFromBucketInfo(binfo *garage.BucketInfo) *WebsiteId { return NewWebsiteId(*binfo.Id, binfo.GlobalAliases) } type WebsiteController struct { - User *LoggedUser - WebsiteIdx map[string]*WebsiteId - PrettyList []string + User *LoggedUser + WebsiteIdx map[string]*WebsiteId + PrettyList []string WebsiteCount QuotaStat } @@ -65,7 +63,7 @@ func NewWebsiteController(user *LoggedUser) (*WebsiteController, error) { return nil, err } - for _, bckt := range(keyInfo.Buckets) { + for _, bckt := range keyInfo.Buckets { if len(bckt.GlobalAliases) > 0 { wid := NewWebsiteId(*bckt.Id, bckt.GlobalAliases) idx[wid.Pretty] = wid @@ -77,15 +75,15 @@ func NewWebsiteController(user *LoggedUser) (*WebsiteController, error) { maxW := user.Quota.WebsiteCount quota := NewQuotaStat(int64(len(wlist)), maxW, true) - return &WebsiteController { user, idx, wlist, quota }, nil + return &WebsiteController{user, idx, wlist, quota}, nil } type WebsiteDescribe struct { - 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"` + 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"` } func (w *WebsiteController) Describe() (*WebsiteDescribe, error) { @@ -96,14 +94,14 @@ func (w *WebsiteController) Describe() (*WebsiteDescribe, error) { r := make([]*WebsiteId, 0, len(w.PrettyList)) for _, k := range w.PrettyList { - r = append(r, w.WebsiteIdx[k]) + r = append(r, w.WebsiteIdx[k]) } - return &WebsiteDescribe { - *s3key.AccessKeyId, - *s3key.SecretAccessKey, - &w.WebsiteCount, + return &WebsiteDescribe{ + *s3key.AccessKeyId, + *s3key.SecretAccessKey, + &w.WebsiteCount, w.User.Quota.WebsiteSizeBurstedPretty(), - r }, nil + r}, nil } func (w *WebsiteController) Inspect(pretty string) (*WebsiteView, error) { @@ -183,7 +181,6 @@ func (w *WebsiteController) Create(pretty string) (*WebsiteView, error) { ur.SetWebsiteAccess(*wr) ur.SetQuotas(*qr) - binfo, err = grgUpdateBucket(*binfo.Id, ur) if err != nil { return nil, ErrCantConfigureBucket @@ -209,7 +206,7 @@ func (w *WebsiteController) Delete(pretty string) error { if *binfo.Objects > int64(0) { return ErrBucketDeleteNotEmpty - } + } if *binfo.UnfinishedUploads > int32(0) { return ErrBucketDeleteUnfinishedUpload @@ -219,13 +216,10 @@ func (w *WebsiteController) Delete(pretty string) error { return err } - - - type WebsiteView struct { - Name *WebsiteId `json:"identified_as"` - Size QuotaStat `json:"quota_size"` - Files QuotaStat `json:"quota_files"` + Name *WebsiteId `json:"identified_as"` + Size QuotaStat `json:"quota_size"` + Files QuotaStat `json:"quota_files"` } func NewWebsiteView(binfo *garage.BucketInfo) *WebsiteView { @@ -234,7 +228,7 @@ func NewWebsiteView(binfo *garage.BucketInfo) *WebsiteView { wid := NewWebsiteIdFromBucketInfo(binfo) size := NewQuotaStat(*binfo.Bytes, (&q).GetMaxSize(), true) objects := NewQuotaStat(*binfo.Objects, (&q).GetMaxObjects(), false) - return &WebsiteView { wid, size, objects } + return &WebsiteView{wid, size, objects} } type WebsitePatch struct { |