forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.2.99.go
119 lines (105 loc) · 4.36 KB
/
2.2.99.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package migrations
import (
"fmt"
"path"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/go-version"
"github.com/pborman/uuid"
"github.com/pydio/cells/common"
"github.com/pydio/cells/common/config"
"github.com/pydio/cells/common/proto/object"
"github.com/pydio/cells/x/configx"
)
func init() {
v, _ := version.NewVersion("2.2.99")
add(v, getMigration(updateVersionsStore))
add(v, getMigration(updateThumbsStore))
}
func updateVersionsStore(conf configx.Values) error {
c := conf.Val("services", "pydio.versions-store")
dsName := c.Val("datasource").Default(configx.Reference("#/defaults/datasource")).String()
bucket := c.Val("bucket").Default("versions").String()
// Create a new "internal" datasource
crtSources := config.ListSourcesFromConfig()
dsObject, ok := crtSources[dsName]
if !ok {
return fmt.Errorf("cannot find versions-store datasource")
}
var newDsName = "versions"
if _, exists := config.ListSourcesFromConfig()[newDsName]; exists {
newDsName = "versions" + uuid.New()[0:6]
}
dsCopy := proto.Clone(dsObject).(*object.DataSource)
dsCopy.Name = newDsName
dsCopy.ObjectsBucket = bucket
dsCopy.FlatStorage = true
dsCopy.StorageConfiguration[object.StorageKeyCellsInternal] = "true"
dsCopy.StorageConfiguration[object.StorageKeyInitFromBucket] = "true"
dsCopy.StorageConfiguration[object.StorageKeyNormalize] = "false"
dsCopy.VersioningPolicyName = ""
dsCopy.EncryptionKey = ""
if f, o := dsObject.StorageConfiguration[object.StorageKeyFolder]; o {
dsCopy.StorageConfiguration[object.StorageKeyFolder] = path.Join(path.Dir(f), bucket)
}
conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataSync_+newDsName).Set(dsCopy)
conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataIndex_+newDsName).Set(map[string]interface{}{
"dsn": "default",
"tables": config.IndexServiceTableNames(newDsName),
})
// Reset sync > sources
syncSrcVal := conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataSync, "sources")
indexSrcVal := conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataIndex, "sources")
indexSlice := indexSrcVal.StringArray()
syncSlice := syncSrcVal.StringArray()
syncSlice = append(syncSlice, newDsName)
indexSlice = append(indexSlice, newDsName)
syncSrcVal.Set(syncSlice)
indexSrcVal.Set(indexSlice)
// Finally update pydio.versions-store/datasource value
c.Val("datasource").Set(newDsName)
return nil
}
func updateThumbsStore(conf configx.Values) error {
c := conf.Val("services", "pydio.thumbs_store")
dsName := c.Val("datasource").Default(configx.Reference("#/defaults/datasource")).String()
bucket := c.Val("bucket").Default("thumbs").String()
// Create a new "internal" datasource
crtSources := config.ListSourcesFromConfig()
dsObject, ok := crtSources[dsName]
if !ok {
return fmt.Errorf("cannot find thumbs_store datasource")
}
var newDsName = "thumbnails"
if _, exists := config.ListSourcesFromConfig()[newDsName]; exists {
newDsName = "thumbnails" + uuid.New()[0:6]
}
dsCopy := proto.Clone(dsObject).(*object.DataSource)
dsCopy.Name = newDsName
dsCopy.ObjectsBucket = bucket
dsCopy.FlatStorage = true
dsCopy.StorageConfiguration[object.StorageKeyCellsInternal] = "true"
dsCopy.StorageConfiguration[object.StorageKeyInitFromBucket] = "true"
dsCopy.StorageConfiguration[object.StorageKeyNormalize] = "false"
dsCopy.VersioningPolicyName = ""
dsCopy.EncryptionKey = ""
if f, o := dsObject.StorageConfiguration[object.StorageKeyFolder]; o {
dsCopy.StorageConfiguration[object.StorageKeyFolder] = path.Join(path.Dir(f), bucket)
}
conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataSync_+newDsName).Set(dsCopy)
conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataIndex_+newDsName).Set(map[string]interface{}{
"dsn": "default",
"tables": config.IndexServiceTableNames(newDsName),
})
// Reset sync > sources
syncSrcVal := conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataSync, "sources")
indexSrcVal := conf.Val("services", common.ServiceGrpcNamespace_+common.ServiceDataIndex, "sources")
indexSlice := indexSrcVal.StringArray()
syncSlice := syncSrcVal.StringArray()
syncSlice = append(syncSlice, newDsName)
indexSlice = append(indexSlice, newDsName)
syncSrcVal.Set(syncSlice)
indexSrcVal.Set(indexSlice)
// Finally update pydio.thumbs_store/datasource value
c.Val("datasource").Set(newDsName)
return nil
}