feat: add configuration api route (#459)

* feat: add configuration api route

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

* feat: rename cache methods

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

---------

Signed-off-by: Matthis Holleville <matthish29@gmail.com>
This commit is contained in:
Matthis
2023-05-25 11:42:49 +02:00
committed by GitHub
parent 49e120c28e
commit fa4a0757b8
9 changed files with 150 additions and 102 deletions

42
pkg/cache/cache.go vendored
View File

@@ -1,6 +1,8 @@
package cache
import (
"errors"
"github.com/spf13/viper"
)
@@ -39,3 +41,43 @@ func RemoteCacheEnabled() (bool, error) {
}
return false, nil
}
func AddRemoteCache(bucketName string, region string) error {
var cacheInfo CacheProvider
err := viper.UnmarshalKey("cache", &cacheInfo)
if err != nil {
return err
}
if cacheInfo.BucketName != "" {
return errors.New("Error: a cache is already configured, please remove it first")
}
cacheInfo.BucketName = bucketName
cacheInfo.Region = region
viper.Set("cache", cacheInfo)
err = viper.WriteConfig()
if err != nil {
return err
}
return nil
}
func RemoveRemoteCache(bucketName string) error {
var cacheInfo CacheProvider
err := viper.UnmarshalKey("cache", &cacheInfo)
if err != nil {
return err
}
if cacheInfo.BucketName == "" {
return errors.New("Error: no cache is configured")
}
cacheInfo = CacheProvider{}
viper.Set("cache", cacheInfo)
err = viper.WriteConfig()
if err != nil {
return err
}
return nil
}