@@ -9,98 +9,9 @@ import (
9
9
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme"
10
10
11
11
"github.com/ydb-platform/ydb-go-sdk/v3/cluster"
12
+ "github.com/ydb-platform/ydb-go-sdk/v3/scheme"
12
13
)
13
14
14
- type Client interface {
15
- Scheme
16
-
17
- CleanupDatabase (ctx context.Context , prefix string , names ... string ) error
18
- EnsurePathExists (ctx context.Context , path string ) error
19
- }
20
-
21
- type Scheme interface {
22
- DescribePath (ctx context.Context , path string ) (e Entry , err error )
23
- MakeDirectory (ctx context.Context , path string ) (err error )
24
- ListDirectory (ctx context.Context , path string ) (d Directory , err error )
25
- RemoveDirectory (ctx context.Context , path string ) (err error )
26
-
27
- Close (ctx context.Context ) error
28
- }
29
-
30
- type EntryType uint
31
-
32
- const (
33
- EntryTypeUnknown EntryType = iota
34
- EntryDirectory
35
- EntryTable
36
- EntryPersQueueGroup
37
- EntryDatabase
38
- EntryRtmrVolume
39
- EntryBlockStoreVolume
40
- EntryCoordinationNode
41
- )
42
-
43
- func (t EntryType ) String () string {
44
- switch t {
45
- default :
46
- return "Unknown"
47
- case EntryDirectory :
48
- return "Directory"
49
- case EntryTable :
50
- return "Table"
51
- case EntryPersQueueGroup :
52
- return "PersQueueGroup"
53
- case EntryDatabase :
54
- return "Name"
55
- case EntryRtmrVolume :
56
- return "RtmrVolume"
57
- case EntryBlockStoreVolume :
58
- return "BlockStoreVolume"
59
- case EntryCoordinationNode :
60
- return "CoordinationNode"
61
- }
62
- }
63
-
64
- type Permissions struct {
65
- Subject string
66
- PermissionNames []string
67
- }
68
-
69
- type Entry struct {
70
- Name string
71
- Owner string
72
- Type EntryType
73
- Permissions []Permissions
74
- EffectivePermissions []Permissions
75
- }
76
-
77
- func (e * Entry ) IsDirectory () bool {
78
- return e .Type == EntryDirectory
79
- }
80
- func (e * Entry ) IsTable () bool {
81
- return e .Type == EntryTable
82
- }
83
- func (e * Entry ) IsPersQueueGroup () bool {
84
- return e .Type == EntryPersQueueGroup
85
- }
86
- func (e * Entry ) IsDatabase () bool {
87
- return e .Type == EntryDatabase
88
- }
89
- func (e * Entry ) IsRtmrVolume () bool {
90
- return e .Type == EntryRtmrVolume
91
- }
92
- func (e * Entry ) IsBlockStoreVolume () bool {
93
- return e .Type == EntryBlockStoreVolume
94
- }
95
- func (e * Entry ) IsCoordinationNode () bool {
96
- return e .Type == EntryCoordinationNode
97
- }
98
-
99
- type Directory struct {
100
- Entry
101
- Children []Entry
102
- }
103
-
104
15
type client struct {
105
16
cluster cluster.Cluster
106
17
service Ydb_Scheme_V1.SchemeServiceClient
@@ -110,7 +21,7 @@ func (c *client) Close(_ context.Context) error {
110
21
return nil
111
22
}
112
23
113
- func New (c cluster.Cluster ) Scheme {
24
+ func New (c cluster.Cluster ) scheme. Scheme {
114
25
return & client {
115
26
cluster : c ,
116
27
service : Ydb_Scheme_V1 .NewSchemeServiceClient (c ),
@@ -131,9 +42,9 @@ func (c *client) RemoveDirectory(ctx context.Context, path string) (err error) {
131
42
return err
132
43
}
133
44
134
- func (c * client ) ListDirectory (ctx context.Context , path string ) (Directory , error ) {
45
+ func (c * client ) ListDirectory (ctx context.Context , path string ) (scheme. Directory , error ) {
135
46
var (
136
- d Directory
47
+ d scheme. Directory
137
48
err error
138
49
response * Ydb_Scheme.ListDirectoryResponse
139
50
result Ydb_Scheme.ListDirectoryResult
@@ -148,13 +59,13 @@ func (c *client) ListDirectory(ctx context.Context, path string) (Directory, err
148
59
if err != nil {
149
60
return d , err
150
61
}
151
- d .from (result .Self )
152
- d .Children = make ([]Entry , len (result .Children ))
62
+ d .From (result .Self )
63
+ d .Children = make ([]scheme. Entry , len (result .Children ))
153
64
putEntry (d .Children , result .Children )
154
65
return d , nil
155
66
}
156
67
157
- func (c * client ) DescribePath (ctx context.Context , path string ) (e Entry , err error ) {
68
+ func (c * client ) DescribePath (ctx context.Context , path string ) (e scheme. Entry , err error ) {
158
69
var (
159
70
response * Ydb_Scheme.DescribePathResponse
160
71
result Ydb_Scheme.DescribePathResult
@@ -169,14 +80,14 @@ func (c *client) DescribePath(ctx context.Context, path string) (e Entry, err er
169
80
if err != nil {
170
81
return e , err
171
82
}
172
- e .from (result .Self )
83
+ e .From (result .Self )
173
84
return e , nil
174
85
}
175
86
176
- func (c * client ) ModifyPermissions (ctx context.Context , path string , opts ... PermissionsOption ) (err error ) {
87
+ func (c * client ) ModifyPermissions (ctx context.Context , path string , opts ... scheme. PermissionsOption ) (err error ) {
177
88
var desc permissionsDesc
178
- for _ , opt := range opts {
179
- opt (& desc )
89
+ for _ , o := range opts {
90
+ o (& desc )
180
91
}
181
92
_ , err = c .service .ModifyPermissions (ctx , & Ydb_Scheme.ModifyPermissionsRequest {
182
93
Path : path ,
@@ -186,70 +97,8 @@ func (c *client) ModifyPermissions(ctx context.Context, path string, opts ...Per
186
97
return err
187
98
}
188
99
189
- func (e * Entry ) from (y * Ydb_Scheme.Entry ) {
190
- var (
191
- n = len (y .Permissions )
192
- m = len (y .EffectivePermissions )
193
- p = make ([]Permissions , n + m )
194
- )
195
- putPermissions (p [:n ], y .Permissions )
196
- putPermissions (p [n :], y .EffectivePermissions )
197
- * e = Entry {
198
- Name : y .Name ,
199
- Owner : y .Owner ,
200
- Type : entryType (y .Type ),
201
- Permissions : p [0 :n ],
202
- EffectivePermissions : p [n :m ],
203
- }
204
- }
205
-
206
- func entryType (t Ydb_Scheme.Entry_Type ) EntryType {
207
- switch t {
208
- case Ydb_Scheme .Entry_DIRECTORY :
209
- return EntryDirectory
210
- case Ydb_Scheme .Entry_TABLE :
211
- return EntryTable
212
- case Ydb_Scheme .Entry_PERS_QUEUE_GROUP :
213
- return EntryPersQueueGroup
214
- case Ydb_Scheme .Entry_DATABASE :
215
- return EntryDatabase
216
- case Ydb_Scheme .Entry_RTMR_VOLUME :
217
- return EntryRtmrVolume
218
- case Ydb_Scheme .Entry_BLOCK_STORE_VOLUME :
219
- return EntryBlockStoreVolume
220
- case Ydb_Scheme .Entry_COORDINATION_NODE :
221
- return EntryCoordinationNode
222
- default :
223
- return EntryTypeUnknown
224
- }
225
- }
226
-
227
- func (p Permissions ) to (y * Ydb_Scheme.Permissions ) {
228
- y .Subject = p .Subject
229
- y .PermissionNames = p .PermissionNames
230
- }
231
-
232
- func (p * Permissions ) from (y * Ydb_Scheme.Permissions ) {
233
- * p = Permissions {
234
- Subject : y .Subject ,
235
- PermissionNames : y .PermissionNames ,
236
- }
237
- }
238
-
239
- func putEntry (dst []Entry , src []* Ydb_Scheme.Entry ) {
100
+ func putEntry (dst []scheme.Entry , src []* Ydb_Scheme.Entry ) {
240
101
for i , e := range src {
241
- (dst [i ]).from (e )
102
+ (dst [i ]).From (e )
242
103
}
243
104
}
244
-
245
- func putPermissions (dst []Permissions , src []* Ydb_Scheme.Permissions ) {
246
- for i , p := range src {
247
- (dst [i ]).from (p )
248
- }
249
- }
250
-
251
- func InnerConvertEntry (y * Ydb_Scheme.Entry ) * Entry {
252
- res := & Entry {}
253
- res .from (y )
254
- return res
255
- }
0 commit comments