@@ -17,14 +17,11 @@ package handlers
1717
1818import (
1919 "fmt"
20- "path"
2120
2221 "github.com/go-openapi/runtime/middleware"
2322 "github.com/google/renameio"
2423 client_native "github.com/haproxytech/client-native/v2"
25- "github.com/haproxytech/client-native/v2/misc"
2624 "github.com/haproxytech/client-native/v2/models"
27- "github.com/haproxytech/client-native/v2/storage"
2825
2926 "github.com/haproxytech/dataplaneapi/configuration"
3027 "github.com/haproxytech/dataplaneapi/haproxy"
@@ -104,28 +101,11 @@ func (h *CreateClusterHandlerImpl) Handle(params cluster.PostClusterParams, prin
104101 if err != nil {
105102 return h .err406 (err , nil )
106103 }
107- storageDir := key ["storage-dir" ]
108- if storageDir != "" {
109- _ , errStorage := misc .CheckOrCreateWritableDirectory (storageDir )
110- if errStorage != nil {
111- return h .err409 (errStorage , nil )
112- }
113- dirs := []storage.FileType {
114- storage .BackupsType , storage .MapsType , storage .SSLType ,
115- storage .SpoeTransactionsType , storage .SpoeType ,
116- storage .TransactionsType ,
117- storage .FileType ("certs-cluster" ),
118- }
119- for _ , dir := range dirs {
120- _ , errStorage := misc .CheckOrCreateWritableDirectory (path .Join (storageDir , string (dir )))
121- if errStorage != nil {
122- return h .err409 (errStorage , nil )
123- }
124- }
125- h .Config .Cluster .StorageDir .Store (storageDir )
126- h .Config .HAProxy .ClusterTLSCertDir = path .Join (storageDir , "certs-cluster" )
127- h .Config .Cluster .CertificateDir .Store (path .Join (storageDir , "certs-cluster" ))
104+ errStorageDir := configuration .CheckIfStorageDirIsOK (key ["storage-dir" ], h .Config )
105+ if errStorageDir != nil {
106+ return h .err409 (errStorageDir , nil )
128107 }
108+
129109 // enforcing API advertising options
130110 if a := params .AdvertisedAddress ; a != nil {
131111 h .Config .APIOptions .APIAddress = * a
0 commit comments