diff --git a/frostfsid/config.yml b/frostfsid/config.yml index 0beb114..d3bdc0c 100644 --- a/frostfsid/config.yml +++ b/frostfsid/config.yml @@ -7,6 +7,7 @@ safemethods: - "getGroupByName" - "getNamespace" - "getNamespaceExtended" + - "getValueForSubjectKey" - "getSubject" - "getSubjectExtended" - "getSubjectByKey" diff --git a/frostfsid/frostfsid_contract.go b/frostfsid/frostfsid_contract.go index d7c2f38..7de4721 100644 --- a/frostfsid/frostfsid_contract.go +++ b/frostfsid/frostfsid_contract.go @@ -472,6 +472,30 @@ func GetSubjectKeyByName(ns, name string) interop.PublicKey { return subjKey } +// GetSubjectKey returns the value associated with the key for the subject. +func GetValueForSubjectKey(addr interop.Hash160, name string) string { + if len(addr) != interop.Hash160Len { + panic("incorrect address length") + } + + ctx := storage.GetReadOnlyContext() + sKey := subjectKeyFromAddr(addr) + data := storage.Get(ctx, sKey).([]byte) + if data == nil { + return "" + } + + sbj := std.Deserialize(data).(Subject) + + for k, v := range sbj.KV { + if k == name { + return v + } + } + + return "" +} + func ListSubjects() iterator.Iterator { ctx := storage.GetReadOnlyContext() return storage.Find(ctx, []byte{subjectKeysPrefix}, storage.KeysOnly|storage.RemovePrefix) diff --git a/rpcclient/frostfsid/client.go b/rpcclient/frostfsid/client.go index ddea629..6ddbee1 100644 --- a/rpcclient/frostfsid/client.go +++ b/rpcclient/frostfsid/client.go @@ -227,6 +227,11 @@ func (c *ContractReader) GetSubjectKeyByName(ns string, name string) (*keys.Publ return unwrap.PublicKey(c.invoker.Call(c.hash, "getSubjectKeyByName", ns, name)) } +// GetValueForSubjectKey invokes `getValueForSubjectKey` method of contract. +func (c *ContractReader) GetValueForSubjectKey(addr util.Uint160, name string) (string, error) { + return unwrap.UTF8String(c.invoker.Call(c.hash, "getValueForSubjectKey", addr, name)) +} + // ListGroupSubjects invokes `listGroupSubjects` method of contract. func (c *ContractReader) ListGroupSubjects(ns string, groupID *big.Int) (uuid.UUID, result.Iterator, error) { return unwrap.SessionIterator(c.invoker.Call(c.hash, "listGroupSubjects", ns, groupID))