From 4f7cbdd8252f0064729f22929c7ca0e63a10d284 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 17 Oct 2023 18:33:11 +0200 Subject: ajout de la modification du ndd --- website.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'website.go') 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"` } -- cgit v1.2.3