@@ -9,98 +9,9 @@ import (
99 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme"
1010
1111 "github.com/ydb-platform/ydb-go-sdk/v3/cluster"
12+ "github.com/ydb-platform/ydb-go-sdk/v3/scheme"
1213)
1314
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-
10415type client struct {
10516 cluster cluster.Cluster
10617 service Ydb_Scheme_V1.SchemeServiceClient
@@ -110,7 +21,7 @@ func (c *client) Close(_ context.Context) error {
11021 return nil
11122}
11223
113- func New (c cluster.Cluster ) Scheme {
24+ func New (c cluster.Cluster ) scheme. Scheme {
11425 return & client {
11526 cluster : c ,
11627 service : Ydb_Scheme_V1 .NewSchemeServiceClient (c ),
@@ -131,9 +42,9 @@ func (c *client) RemoveDirectory(ctx context.Context, path string) (err error) {
13142 return err
13243}
13344
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 ) {
13546 var (
136- d Directory
47+ d scheme. Directory
13748 err error
13849 response * Ydb_Scheme.ListDirectoryResponse
13950 result Ydb_Scheme.ListDirectoryResult
@@ -148,13 +59,13 @@ func (c *client) ListDirectory(ctx context.Context, path string) (Directory, err
14859 if err != nil {
14960 return d , err
15061 }
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 ))
15364 putEntry (d .Children , result .Children )
15465 return d , nil
15566}
15667
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 ) {
15869 var (
15970 response * Ydb_Scheme.DescribePathResponse
16071 result Ydb_Scheme.DescribePathResult
@@ -169,14 +80,14 @@ func (c *client) DescribePath(ctx context.Context, path string) (e Entry, err er
16980 if err != nil {
17081 return e , err
17182 }
172- e .from (result .Self )
83+ e .From (result .Self )
17384 return e , nil
17485}
17586
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 ) {
17788 var desc permissionsDesc
178- for _ , opt := range opts {
179- opt (& desc )
89+ for _ , o := range opts {
90+ o (& desc )
18091 }
18192 _ , err = c .service .ModifyPermissions (ctx , & Ydb_Scheme.ModifyPermissionsRequest {
18293 Path : path ,
@@ -186,70 +97,8 @@ func (c *client) ModifyPermissions(ctx context.Context, path string, opts ...Per
18697 return err
18798}
18899
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 ) {
240101 for i , e := range src {
241- (dst [i ]).from (e )
102+ (dst [i ]).From (e )
242103 }
243104}
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