github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/scheme/options.go (about)

     1  package scheme
     2  
     3  import (
     4  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme"
     5  )
     6  
     7  func permissions(p Permissions) *Ydb_Scheme.Permissions {
     8  	var y Ydb_Scheme.Permissions
     9  	p.To(&y)
    10  
    11  	return &y
    12  }
    13  
    14  type permissionsDesc interface {
    15  	SetClear(clear bool)
    16  	AppendAction(action *Ydb_Scheme.PermissionsAction)
    17  }
    18  
    19  type PermissionsOption func(permissionsDesc)
    20  
    21  func WithClearPermissions() PermissionsOption {
    22  	return func(p permissionsDesc) {
    23  		p.SetClear(true)
    24  	}
    25  }
    26  
    27  func WithGrantPermissions(p Permissions) PermissionsOption {
    28  	return func(d permissionsDesc) {
    29  		d.AppendAction(&Ydb_Scheme.PermissionsAction{
    30  			Action: &Ydb_Scheme.PermissionsAction_Grant{
    31  				Grant: permissions(p),
    32  			},
    33  		})
    34  	}
    35  }
    36  
    37  func WithRevokePermissions(p Permissions) PermissionsOption {
    38  	return func(d permissionsDesc) {
    39  		d.AppendAction(&Ydb_Scheme.PermissionsAction{
    40  			Action: &Ydb_Scheme.PermissionsAction_Revoke{
    41  				Revoke: permissions(p),
    42  			},
    43  		})
    44  	}
    45  }
    46  
    47  func WithSetPermissions(p Permissions) PermissionsOption {
    48  	return func(d permissionsDesc) {
    49  		d.AppendAction(&Ydb_Scheme.PermissionsAction{
    50  			Action: &Ydb_Scheme.PermissionsAction_Set{
    51  				Set: permissions(p),
    52  			},
    53  		})
    54  	}
    55  }
    56  
    57  func WithChangeOwner(owner string) PermissionsOption {
    58  	return func(d permissionsDesc) {
    59  		d.AppendAction(&Ydb_Scheme.PermissionsAction{
    60  			Action: &Ydb_Scheme.PermissionsAction_ChangeOwner{
    61  				ChangeOwner: owner,
    62  			},
    63  		})
    64  	}
    65  }