aboutsummaryrefslogtreecommitdiff
path: root/website.go
diff options
context:
space:
mode:
authorQuentin <quentin@dufour.io>2023-10-17 16:34:13 +0000
committerQuentin <quentin@dufour.io>2023-10-17 16:34:13 +0000
commit51a5771b0ba94efd35e0828c8423bc525ac8933f (patch)
tree52c2418e31f564469ac0f7e06589a198b5f094b3 /website.go
parent10bdee10cf6947ec6dd0ba5040d7274d6c3316a7 (diff)
parent4f7cbdd8252f0064729f22929c7ca0e63a10d284 (diff)
downloadguichet-51a5771b0ba94efd35e0828c8423bc525ac8933f.tar.gz
guichet-51a5771b0ba94efd35e0828c8423bc525ac8933f.zip
Merge pull request 'change-vhost' (#47) from change-vhost into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/guichet/pulls/47
Diffstat (limited to 'website.go')
-rw-r--r--website.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/website.go b/website.go
index 2cad12c..74daf89 100644
--- a/website.go
+++ b/website.go
@@ -17,6 +17,8 @@ var (
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")
+ ErrCantChangeVhost = fmt.Errorf("Can't change the vhost to the desired value. Maybe it's already used by someone else or an internal error occured")
+ ErrCantRemoveOldVhost = fmt.Errorf("The new vhost is bound to the bucket but the old one can't be removed, this is an internal error")
)
type WebsiteId struct {
@@ -141,12 +143,24 @@ func (w *WebsiteController) Patch(pretty string, patch *WebsitePatch) (*WebsiteV
ur := garage.NewUpdateBucketRequest()
ur.SetQuotas(*urQuota)
- // Call garage
+ // Call garage "update bucket" function
binfo, err = grgUpdateBucket(website.Internal, ur)
if err != nil {
return nil, ErrCantConfigureBucket
}
+ // Update the alias if the vhost field is set and different
+ if patch.Vhost != nil && *patch.Vhost != "" && *patch.Vhost != pretty {
+ binfo, err = grgAddGlobalAlias(website.Internal, *patch.Vhost)
+ if err != nil {
+ return nil, ErrCantChangeVhost
+ }
+ binfo, err = grgDelGlobalAlias(website.Internal, pretty)
+ if err != nil {
+ return nil, ErrCantRemoveOldVhost
+ }
+ }
+
return NewWebsiteView(binfo), nil
}
@@ -233,4 +247,5 @@ func NewWebsiteView(binfo *garage.BucketInfo) *WebsiteView {
type WebsitePatch struct {
Size *int64 `json:"quota_size"`
+ Vhost *string `json:"vhost"`
}