forked from TrueCloudLab/frostfs-contract
[#76] frostfsid: Add GetGroupByName method
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
parent
6e72d0b3b4
commit
55a4163951
5 changed files with 45 additions and 0 deletions
|
@ -114,6 +114,7 @@ const (
|
||||||
getGroupMethod = "getGroup"
|
getGroupMethod = "getGroup"
|
||||||
getGroupExtendedMethod = "getGroupExtended"
|
getGroupExtendedMethod = "getGroupExtended"
|
||||||
getGroupIDByNameMethod = "getGroupIDByName"
|
getGroupIDByNameMethod = "getGroupIDByName"
|
||||||
|
getGroupByNameMethod = "getGroupByName"
|
||||||
setGroupNameMethod = "setGroupName"
|
setGroupNameMethod = "setGroupName"
|
||||||
setGroupKVMethod = "setGroupKV"
|
setGroupKVMethod = "setGroupKV"
|
||||||
deleteGroupKVMethod = "deleteGroupKV"
|
deleteGroupKVMethod = "deleteGroupKV"
|
||||||
|
@ -482,6 +483,16 @@ func (c Client) GetGroupIDByName(namespace, groupName string) (int64, error) {
|
||||||
return unwrap.Int64(c.act.Call(c.contract, getGroupIDByNameMethod, namespace, groupName))
|
return unwrap.Int64(c.act.Call(c.contract, getGroupIDByNameMethod, namespace, groupName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupByName gets group by its name (namespace scope).
|
||||||
|
func (c Client) GetGroupByName(namespace, groupName string) (*Group, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getGroupByNameMethod, namespace, groupName))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseGroup(items)
|
||||||
|
}
|
||||||
|
|
||||||
// ListGroups gets all groups in specific namespace.
|
// ListGroups gets all groups in specific namespace.
|
||||||
func (c Client) ListGroups(namespace string) ([]*Group, error) {
|
func (c Client) ListGroups(namespace string) ([]*Group, error) {
|
||||||
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupsMethod, namespace)
|
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupsMethod, namespace)
|
||||||
|
|
|
@ -4,6 +4,7 @@ safemethods:
|
||||||
- "getGroup"
|
- "getGroup"
|
||||||
- "getGroupExtended"
|
- "getGroupExtended"
|
||||||
- "getGroupIDByName"
|
- "getGroupIDByName"
|
||||||
|
- "getGroupByName"
|
||||||
- "getNamespace"
|
- "getNamespace"
|
||||||
- "getNamespaceExtended"
|
- "getNamespaceExtended"
|
||||||
- "getSubject"
|
- "getSubject"
|
||||||
|
|
|
@ -585,6 +585,19 @@ func GetGroupIDByName(ns, name string) int {
|
||||||
return std.Deserialize(groupIDRaw).(int)
|
return std.Deserialize(groupIDRaw).(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetGroupByName(ns, name string) Group {
|
||||||
|
groupID := GetGroupIDByName(ns, name)
|
||||||
|
gKey := groupKey(ns, groupID)
|
||||||
|
|
||||||
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
data := storage.Get(ctx, gKey).([]byte)
|
||||||
|
if data == nil {
|
||||||
|
panic("group not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return std.Deserialize(data).(Group)
|
||||||
|
}
|
||||||
|
|
||||||
func SetGroupName(ns string, groupID int, name string) {
|
func SetGroupName(ns string, groupID int, name string) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
checkContractOwner(ctx)
|
checkContractOwner(ctx)
|
||||||
|
|
|
@ -177,6 +177,11 @@ func (c *ContractReader) GetGroup(ns string, groupID *big.Int) ([]stackitem.Item
|
||||||
return unwrap.Array(c.invoker.Call(c.hash, "getGroup", ns, groupID))
|
return unwrap.Array(c.invoker.Call(c.hash, "getGroup", ns, groupID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupByName invokes `getGroupByName` method of contract.
|
||||||
|
func (c *ContractReader) GetGroupByName(ns string, name string) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "getGroupByName", ns, name))
|
||||||
|
}
|
||||||
|
|
||||||
// GetGroupExtended invokes `getGroupExtended` method of contract.
|
// GetGroupExtended invokes `getGroupExtended` method of contract.
|
||||||
func (c *ContractReader) GetGroupExtended(ns string, groupID *big.Int) ([]stackitem.Item, error) {
|
func (c *ContractReader) GetGroupExtended(ns string, groupID *big.Int) ([]stackitem.Item, error) {
|
||||||
return unwrap.Array(c.invoker.Call(c.hash, "getGroupExtended", ns, groupID))
|
return unwrap.Array(c.invoker.Call(c.hash, "getGroupExtended", ns, groupID))
|
||||||
|
|
|
@ -537,6 +537,21 @@ func TestFrostFSID_Client_GetSubjectByName(t *testing.T) {
|
||||||
require.Equal(t, defaultNamespace, subj.Namespace)
|
require.Equal(t, defaultNamespace, subj.Namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_GetGroupByName(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
groupName := "group"
|
||||||
|
actGroupID, err := ffsid.cli.ParseGroupID(ffsid.cli.Wait(ffsid.cli.CreateGroup(defaultNamespace, groupName)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
group, err := ffsid.cli.GetGroupByName(defaultNamespace, groupName)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, actGroupID, group.ID)
|
||||||
|
require.Equal(t, defaultNamespace, group.Namespace)
|
||||||
|
require.Equal(t, groupName, group.Name)
|
||||||
|
}
|
||||||
|
|
||||||
func prettyPrintExtendedSubjects(subjects []*client.SubjectExtended) {
|
func prettyPrintExtendedSubjects(subjects []*client.SubjectExtended) {
|
||||||
for _, subj := range subjects {
|
for _, subj := range subjects {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
|
Loading…
Reference in a new issue