Compare commits

...

33 commits

Author SHA1 Message Date
dafc9e5476 [#86] status: Regenerate common status
* INVALID_ARGUMENT is a new common status constant.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-06-24 11:55:48 +03:00
2f6d3209e1 [#84] object: Regenerate EC-header type
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-30 15:28:26 +00:00
9e825239ac [#85] acl: Regenerate protobufs for Bearer token
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-29 19:45:44 +03:00
9789b79b1d [#85] apemanager: Generate protobufs for ape package
* Regenerate protobufs as APE specific type are defined
  as separate package;
* Move `ape` package related utils methods from `apemanager`.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-29 14:15:49 +03:00
0803bc6ded [#83] object: Regenerate protobufs for ECHeader
* Fix marshalers and converters;
* Fix unit-tests.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-16 16:31:03 +03:00
4fe42ac4ad [#82] object: Add FilterHeaderECParent filter for v2
* `FilterHeaderECParent` is used by `Object.Search`

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-13 17:03:55 +03:00
063ce11c24 [#82] object: Erase field Signature from ECHeader v2 type
* The field `Signature` is not used and should be factored out.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-08 15:09:16 +03:00
bc7b49eed2 [#82] object: Introduce new fields for EC header
* Regenerate protobufs as frostfs-api introduced `parent_split_id` and
  `parent_split_index` fields.
* Fix marshaller and converter for EC header.
* Extend v2 type `ECHeader` with `ParentSplitID` and `ParentSplitIndex` fields.
* Fix message_test for `Object`. Also generate EC headers and check it.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-08 15:09:12 +03:00
b171364079 [#81] rpc: Fix apemanager rpc service name
* Introduce `frostfsServiceNamePrefix` for rpc interface
  since `apemanager` uses `frostfs` root instead `neo.fs`.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-06 14:46:54 +03:00
0fe6b9adbb [#76] Make setter names more consistent
This will make the transition to a new codegen more seamless.
1. Setter should be named as the field itself.
2. Setter should accept 1 parameter.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-05-03 08:52:04 +03:00
fa8f92d662 [#75] audit: Remove deprecated service
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-05-02 11:54:35 +00:00
387b850e5e [#74] apemanager: Generate protobufs for apemanager service
* Generate protobufs.
* Make marshallers, unmarshallers, json-encoders etc.
* Create message encoding/decoding unit-tests.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-02 11:53:26 +00:00
67c6f305b2 [#79] object: Implement Range\RangeHash requests for EC object
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2024-04-27 23:04:46 +03:00
df9b65324a [#73] object: Implement Get\Head requests for EC object
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2024-04-22 18:14:50 +03:00
4a330a5706 [#72] session: Unify unmarshaling code
gopatch:
```
@@
var err, msg, data, t, protojson identifier
var obj expression
@@
+import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
-import protojson "google.golang.org/protobuf/encoding/protojson"

-msg := obj
-if err := protojson.Unmarshal(data, msg); err != nil {
-return err
-}
-return t.FromGRPCMessage(msg)
+return message.UnmarshalJSON(t, data, obj)

@@
var err, msg, data, t, goproto identifier
var obj expression
@@
+import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
-import goproto "google.golang.org/protobuf/proto"

-msg := obj
-if err := goproto.Unmarshal(data, msg); err != nil {
-return err
-}
-return t.FromGRPCMessage(msg)
+return message.Unmarshal(t, data, obj)
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-04-20 14:19:19 +03:00
491a47e7fe [#70] netmap: Regenerate protobuf for Replica
* Since EC field tags are renumerated, it is required
  to regenerate netmap grpc.
* Add a generator with EC replica to check it with
  unit-test.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-03-27 12:56:03 +03:00
6e9d385f3c [#71] container: Introduce CONTAINER_ACCESS_DENIED status
* Regenerate protobufs for object and container service to
  use a new frostfs-api status CONTAINER_ACCESS_DENIED.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-03-26 18:55:05 +03:00
1772b92182 [#69] object: Initial EC implementation
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-19 15:23:01 +03:00
a85146250b [#68] Makefile: Use gofumpt for formatting
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
ea6e390c7b [#68] pre-commit: Add unit test hook
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
4d35da7c77 [#68] Makefile: Allow to override testflags
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
a7bcad6aa9 [#68] Makefile: Drop GO111MODULE usages
It is ignored since go1.17.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
6fb9cae479 [#68] pre-commit: Update golangci-lint to 1.56.2
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
f69ad7ade0 [#68] pre-commit: Remove gitlint
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-03-14 10:31:58 +03:00
c1c7b344b9 [#67] go.mod: Bump protobuf version
Found by vulncheck:
Vulnerability #1: GO-2024-2611
    Infinite loop in JSON unmarshaling in google.golang.org/protobuf
  More info: https://pkg.go.dev/vuln/GO-2024-2611
  Module: google.golang.org/protobuf
    Found in: google.golang.org/protobuf@v1.32.0
    Fixed in: google.golang.org/protobuf@v1.33.0

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-03-06 13:18:14 +03:00
634e24aba7 [#65] object: Fix SetMarshalData for PutSingle request
Allow to reset marshal data

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-02-15 15:44:01 +03:00
2a124b95bc [#64] object: Allow to reset marshal data
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-02-15 14:47:28 +03:00
d60ce83e42 [#63] .forgejo: Update dco-go to v3
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-01-26 12:19:53 +03:00
72885aae83 [#62] signature: Refactor BufferPool
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-01-12 18:09:28 +03:00
b46e8cfbda [#59] util: Rename stableMarshaler
It should be with a single `l`, see `json.Marshaler`.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-11-21 15:28:03 +03:00
9cc2095446 [#59] util: Restore backwards compatibility in NestedStructureMarshal()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-11-21 15:27:57 +03:00
498877e378 [#58] makefile: Disable test results caching
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-10-31 13:47:48 +03:00
f50872f1bc [#58] object: Allow to set marshal data
Now it is possible set marshaled data to reduce memory
allocations.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-10-31 13:47:48 +03:00
91 changed files with 2602 additions and 811 deletions

View file

@ -16,6 +16,6 @@ jobs:
go-version: '1.21'
- name: Run commit format checker
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v2
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3
with:
from: 'origin/${{ github.event.pull_request.base.ref }}'

View file

@ -1,10 +0,0 @@
[general]
fail-without-commits=true
contrib=CC1
[title-match-regex]
regex=^\[\#[0-9Xx]+\]\s
[ignore-by-title]
regex=^Release(.*)
ignore=title-match-regex

View file

@ -18,13 +18,25 @@ repos:
- id: end-of-file-fixer
exclude: ".key$"
- repo: local
hooks:
- id: gofumpt
name: gofumpt
entry: make fumpt
pass_filenames: false
types: [go]
language: system
- repo: local
hooks:
- id: go-unit-tests
name: go unit tests
entry: make test GOFLAGS=''
pass_filenames: false
types: [go]
language: system
- repo: https://github.com/golangci/golangci-lint
rev: v1.51.2
rev: v1.56.2
hooks:
- id: golangci-lint
- repo: https://github.com/jorisroovers/gitlint
rev: v0.18.0
hooks:
- id: gitlint
stages: [commit-msg]

View file

@ -3,40 +3,35 @@ SHELL = bash
VERSION ?= $(shell git describe --tags --match "v*" --abbrev=8 --dirty --always)
.PHONY: dep fmts fmt imports protoc test lint version help
.PHONY: dep fmts fumpt imports protoc test lint version help
# Pull go dependencies
dep:
@printf "⇒ Tidy requirements : "
CGO_ENABLED=0 \
GO111MODULE=on \
go mod tidy -v && echo OK
@printf "⇒ Download requirements: "
CGO_ENABLED=0 \
GO111MODULE=on \
go mod download && echo OK
@printf "⇒ Install test requirements: "
CGO_ENABLED=0 \
GO111MODULE=on \
go test ./... && echo OK
# Run all code formatters
fmts: fmt imports
# Reformat code
fmt:
@echo "⇒ Processing gofmt check"
@for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \
GO111MODULE=on gofmt -s -w $$f; \
done
fmts: fumpt imports
# Reformat imports
imports:
@echo "⇒ Processing goimports check"
@for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \
GO111MODULE=on goimports -w $$f; \
goimports -w $$f; \
done
# Run gofumpt
fumpt:
@echo "⇒ Processing gofumpt check"
@gofumpt -l -w .
# Regenerate code for proto files
protoc:
@GOPRIVATE=github.com/TrueCloudLab go mod vendor
@ -54,9 +49,10 @@ protoc:
rm -rf vendor
# Run Unit Test with go test
test: GOFLAGS ?= "-count=1"
test:
@echo "⇒ Running go test"
@GO111MODULE=on go test ./...
@GOFLAGS="$(GOFLAGS)" go test ./...
# Run linters
lint:

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -2,6 +2,8 @@ package acl
import (
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
apeGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
@ -164,7 +166,7 @@ func (f *HeaderFilter) ToGRPCMessage() grpc.Message {
m.SetKey(f.key)
m.SetValue(f.value)
m.SetHeader(HeaderTypeToGRPCField(f.hdrType))
m.SetHeaderType(HeaderTypeToGRPCField(f.hdrType))
m.SetMatchType(MatchTypeToGRPCField(f.matchType))
}
@ -418,6 +420,54 @@ func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error {
return nil
}
func (c *APEOverride) ToGRPCMessage() grpc.Message {
var m *acl.BearerToken_Body_APEOverride
if c != nil {
m = new(acl.BearerToken_Body_APEOverride)
m.SetTarget(c.target.ToGRPCMessage().(*apeGRPC.ChainTarget))
if len(c.chains) > 0 {
apeChains := make([]*apeGRPC.Chain, len(c.chains))
for i := range c.chains {
apeChains[i] = c.chains[i].ToGRPCMessage().(*apeGRPC.Chain)
}
m.SetChains(apeChains)
}
}
return m
}
func (c *APEOverride) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.BearerToken_Body_APEOverride)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
if targetGRPC := v.GetTarget(); targetGRPC != nil {
if c.target == nil {
c.target = new(ape.ChainTarget)
}
if err := c.target.FromGRPCMessage(v.GetTarget()); err != nil {
return err
}
}
if apeChains := v.GetChains(); len(apeChains) > 0 {
c.chains = make([]*ape.Chain, len(apeChains))
for i := range apeChains {
c.chains[i] = new(ape.Chain)
if err := c.chains[i].FromGRPCMessage(apeChains[i]); err != nil {
return err
}
}
}
return nil
}
func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message {
var m *acl.BearerToken_Body
@ -427,7 +477,8 @@ func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message {
m.SetOwnerId(bt.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
m.SetLifetime(bt.lifetime.ToGRPCMessage().(*acl.BearerToken_Body_TokenLifetime))
m.SetEaclTable(bt.eacl.ToGRPCMessage().(*acl.EACLTable))
m.SetImpersonate(bt.impersonate)
m.SetAllowImpersonate(bt.impersonate)
m.SetAPEOverride(bt.apeOverride.ToGRPCMessage().(*acl.BearerToken_Body_APEOverride))
}
return m
@ -477,7 +528,19 @@ func (bt *BearerTokenBody) FromGRPCMessage(m grpc.Message) error {
bt.eacl = new(Table)
}
err = bt.eacl.FromGRPCMessage(eacl)
if err = bt.eacl.FromGRPCMessage(eacl); err != nil {
return err
}
}
if apeOverrideGRPC := v.GetApeOverride(); apeOverrideGRPC != nil {
if bt.apeOverride == nil {
bt.apeOverride = new(APEOverride)
}
err = bt.apeOverride.FromGRPCMessage(apeOverrideGRPC)
if err != nil {
return err
}
}
bt.impersonate = v.GetAllowImpersonate()

View file

@ -1,6 +1,7 @@
package acl
import (
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
)
@ -39,8 +40,8 @@ func (m *EACLRecord) SetTargets(v []*EACLRecord_Target) {
m.Targets = v
}
// SetHeader sets header type of the eACL filter.
func (m *EACLRecord_Filter) SetHeader(v HeaderType) {
// SetHeaderType sets header type of the eACL filter.
func (m *EACLRecord_Filter) SetHeaderType(v HeaderType) {
m.HeaderType = v
}
@ -74,6 +75,18 @@ func (m *BearerToken_Body) SetEaclTable(v *EACLTable) {
m.EaclTable = v
}
func (m *BearerToken_Body) SetAPEOverride(v *BearerToken_Body_APEOverride) {
m.ApeOverride = v
}
func (m *BearerToken_Body_APEOverride) SetChains(v []*ape.Chain) {
m.Chains = v
}
func (m *BearerToken_Body_APEOverride) SetTarget(v *ape.ChainTarget) {
m.Target = v
}
// SetOwnerId sets identifier of the bearer token owner.
func (m *BearerToken_Body) SetOwnerId(v *refs.OwnerID) {
m.OwnerId = v
@ -84,8 +97,8 @@ func (m *BearerToken_Body) SetLifetime(v *BearerToken_Body_TokenLifetime) {
m.Lifetime = v
}
// SetImpersonate allows impersonate.
func (m *BearerToken_Body) SetImpersonate(v bool) {
// SetAllowImpersonate allows impersonate.
func (m *BearerToken_Body) SetAllowImpersonate(v bool) {
m.AllowImpersonate = v
}

BIN
acl/grpc/types.pb.go generated

Binary file not shown.

View file

@ -21,6 +21,14 @@ func (t *Target) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(t, data, new(acl.EACLRecord_Target))
}
func (a *APEOverride) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *APEOverride) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(acl.BearerToken_Body_APEOverride))
}
func (r *Record) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(r)
}

View file

@ -28,10 +28,14 @@ const (
lifetimeNotValidBeforeField = 2
lifetimeIssuedAtField = 3
bearerTokenBodyACLField = 1
bearerTokenBodyOwnerField = 2
bearerTokenBodyLifetimeField = 3
bearerTokenBodyImpersonate = 4
tokenAPEChainsTargetField = 1
tokenAPEChainsChainsField = 2
bearerTokenBodyACLField = 1
bearerTokenBodyOwnerField = 2
bearerTokenBodyLifetimeField = 3
bearerTokenBodyImpersonate = 4
bearerTokenTokenAPEChainsField = 5
bearerTokenBodyField = 1
bearerTokenSignatureField = 2
@ -239,6 +243,42 @@ func (l *TokenLifetime) Unmarshal(data []byte) error {
return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime))
}
func (c *APEOverride) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(tokenAPEChainsTargetField, buf[offset:], c.target)
for i := range c.chains {
offset += protoutil.NestedStructureMarshal(tokenAPEChainsChainsField, buf[offset:], c.chains[i])
}
return buf
}
func (c *APEOverride) StableSize() (size int) {
if c == nil {
return 0
}
size += protoutil.NestedStructureSize(tokenAPEChainsTargetField, c.target)
for i := range c.chains {
size += protoutil.NestedStructureSize(tokenAPEChainsChainsField, c.chains[i])
}
return size
}
func (c *APEOverride) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(acl.BearerToken_Body_APEOverride))
}
func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
if bt == nil {
return []byte{}
@ -253,7 +293,8 @@ func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate)
offset += protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate)
protoutil.NestedStructureMarshal(bearerTokenTokenAPEChainsField, buf[offset:], bt.apeOverride)
return buf
}
@ -267,6 +308,7 @@ func (bt *BearerTokenBody) StableSize() (size int) {
size += protoutil.NestedStructureSize(bearerTokenBodyOwnerField, bt.ownerID)
size += protoutil.NestedStructureSize(bearerTokenBodyLifetimeField, bt.lifetime)
size += protoutil.BoolSize(bearerTokenBodyImpersonate, bt.impersonate)
size += protoutil.NestedStructureSize(bearerTokenTokenAPEChainsField, bt.apeOverride)
return size
}

View file

@ -2,6 +2,7 @@ package acltest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
apetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/test"
accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
)
@ -22,8 +23,20 @@ func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
if !empty {
m.SetOwnerID(accountingtest.GenerateOwnerID(false))
m.SetEACL(GenerateTable(false))
m.SetLifetime(GenerateTokenLifetime(false))
m.SetAPEOverride(GenerateAPEOverride(empty))
}
return m
}
func GenerateAPEOverride(empty bool) *acl.APEOverride {
var m *acl.APEOverride
if !empty {
m = new(acl.APEOverride)
m.SetTarget(apetest.GenerateChainTarget(empty))
m.SetChains(apetest.GenerateRawChains(false, 3))
}
return m

View file

@ -1,6 +1,9 @@
package acl
import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
)
// HeaderFilter is a unified structure of FilterInfo
// message from proto definition.
@ -46,6 +49,12 @@ type TokenLifetime struct {
exp, nbf, iat uint64
}
type APEOverride struct {
target *ape.ChainTarget
chains []*ape.Chain
}
type BearerTokenBody struct {
eacl *Table
@ -53,6 +62,8 @@ type BearerTokenBody struct {
lifetime *TokenLifetime
apeOverride *APEOverride
impersonate bool
}
@ -318,6 +329,34 @@ func (bt *BearerTokenBody) SetEACL(v *Table) {
bt.eacl = v
}
func (t *APEOverride) GetTarget() *ape.ChainTarget {
return t.target
}
func (t *APEOverride) GetChains() []*ape.Chain {
return t.chains
}
func (t *APEOverride) SetTarget(v *ape.ChainTarget) {
t.target = v
}
func (t *APEOverride) SetChains(v []*ape.Chain) {
t.chains = v
}
func (bt *BearerTokenBody) GetAPEOverride() *APEOverride {
if bt != nil {
return bt.apeOverride
}
return nil
}
func (bt *BearerTokenBody) SetAPEOverride(v *APEOverride) {
bt.apeOverride = v
}
func (bt *BearerTokenBody) GetOwnerID() *refs.OwnerID {
if bt != nil {
return bt.ownerID

132
ape/convert.go Normal file
View file

@ -0,0 +1,132 @@
package ape
import (
"fmt"
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func TargetTypeToGRPCField(typ TargetType) ape.TargetType {
switch typ {
case TargetTypeNamespace:
return ape.TargetType_NAMESPACE
case TargetTypeContainer:
return ape.TargetType_CONTAINER
case TargetTypeUser:
return ape.TargetType_USER
case TargetTypeGroup:
return ape.TargetType_GROUP
default:
return ape.TargetType_UNDEFINED
}
}
func TargetTypeFromGRPCField(typ ape.TargetType) TargetType {
switch typ {
case ape.TargetType_NAMESPACE:
return TargetTypeNamespace
case ape.TargetType_CONTAINER:
return TargetTypeContainer
case ape.TargetType_USER:
return TargetTypeUser
case ape.TargetType_GROUP:
return TargetTypeGroup
default:
return TargetTypeUndefined
}
}
func TargetTypeToGRPC(typ TargetType) ape.TargetType {
return ape.TargetType(typ)
}
func TargetTypeFromGRPC(typ ape.TargetType) TargetType {
return TargetType(typ)
}
func (v2 *ChainTarget) ToGRPCMessage() grpc.Message {
var mgrpc *ape.ChainTarget
if v2 != nil {
mgrpc = new(ape.ChainTarget)
mgrpc.SetType(TargetTypeToGRPC(v2.GetTargetType()))
mgrpc.SetName(v2.GetName())
}
return mgrpc
}
func (v2 *ChainTarget) FromGRPCMessage(m grpc.Message) error {
mgrpc, ok := m.(*ape.ChainTarget)
if !ok {
return message.NewUnexpectedMessageType(m, mgrpc)
}
v2.SetTargetType(TargetTypeFromGRPC(mgrpc.GetType()))
v2.SetName(mgrpc.GetName())
return nil
}
func (v2 *ChainRaw) ToGRPCMessage() grpc.Message {
var mgrpc *ape.Chain_Raw
if v2 != nil {
mgrpc = new(ape.Chain_Raw)
mgrpc.SetRaw(v2.GetRaw())
}
return mgrpc
}
func (v2 *ChainRaw) FromGRPCMessage(m grpc.Message) error {
mgrpc, ok := m.(*ape.Chain_Raw)
if !ok {
return message.NewUnexpectedMessageType(m, mgrpc)
}
v2.SetRaw(mgrpc.GetRaw())
return nil
}
func (v2 *Chain) ToGRPCMessage() grpc.Message {
var mgrpc *ape.Chain
if v2 != nil {
mgrpc = new(ape.Chain)
switch chainKind := v2.GetKind().(type) {
default:
panic(fmt.Sprintf("unsupported chain kind: %T", chainKind))
case *ChainRaw:
mgrpc.SetKind(chainKind.ToGRPCMessage().(*ape.Chain_Raw))
}
}
return mgrpc
}
func (v2 *Chain) FromGRPCMessage(m grpc.Message) error {
mgrpc, ok := m.(*ape.Chain)
if !ok {
return message.NewUnexpectedMessageType(m, mgrpc)
}
switch chainKind := mgrpc.GetKind().(type) {
default:
return fmt.Errorf("unsupported chain kind: %T", chainKind)
case *ape.Chain_Raw:
chainRaw := new(ChainRaw)
if err := chainRaw.FromGRPCMessage(chainKind); err != nil {
return err
}
v2.SetKind(chainRaw)
}
return nil
}

21
ape/grpc/types.go Normal file
View file

@ -0,0 +1,21 @@
package ape
func (t *ChainTarget) SetType(typ TargetType) {
t.Type = typ
}
func (t *ChainTarget) SetName(name string) {
t.Name = name
}
func (c *Chain) SetKind(kind isChain_Kind) {
c.Kind = kind
}
func (cr *Chain_Raw) SetRaw(raw []byte) {
cr.Raw = raw
}
func (cr *Chain_Raw) GetRaw() []byte {
return cr.Raw
}

BIN
ape/grpc/types.pb.go generated Normal file

Binary file not shown.

14
ape/json.go Normal file
View file

@ -0,0 +1,14 @@
package ape
import (
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (t *ChainTarget) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(t)
}
func (t *ChainTarget) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(t, data, new(ape.ChainTarget))
}

92
ape/marshal.go Normal file
View file

@ -0,0 +1,92 @@
package ape
import (
"fmt"
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
chainTargetTargetTypeField = 1
chainTargetNameField = 2
chainRawField = 1
)
func (t *ChainTarget) StableSize() (size int) {
if t == nil {
return 0
}
size += proto.EnumSize(chainTargetTargetTypeField, int32(t.targeType))
size += proto.StringSize(chainTargetNameField, t.name)
return size
}
func (t *ChainTarget) StableMarshal(buf []byte) []byte {
if t == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, t.StableSize())
}
var offset int
offset += proto.EnumMarshal(chainTargetTargetTypeField, buf[offset:], int32(t.targeType))
proto.StringMarshal(chainTargetNameField, buf[offset:], t.name)
return buf
}
func (t *ChainTarget) Unmarshal(data []byte) error {
return message.Unmarshal(t, data, new(ape.ChainTarget))
}
func (c *Chain) StableSize() (size int) {
if c == nil {
return 0
}
switch v := c.GetKind().(type) {
case *ChainRaw:
if v != nil {
size += proto.BytesSize(chainRawField, v.GetRaw())
}
default:
panic(fmt.Sprintf("unsupported chain kind: %T", v))
}
return size
}
func (c *Chain) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
var offset int
switch v := c.GetKind().(type) {
case *ChainRaw:
if v != nil {
proto.BytesMarshal(chainRawField, buf[offset:], v.GetRaw())
}
default:
panic(fmt.Sprintf("unsupported chain kind: %T", v))
}
return buf
}
func (c *Chain) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(ape.Chain))
}

View file

@ -1,15 +1,15 @@
package audit_test
package ape_test
import (
"testing"
audittest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/test"
apetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return audittest.GenerateDataAuditResult(empty) },
func(empty bool) message.Message { return apetest.GenerateChainTarget(empty) },
)
}

18
ape/string.go Normal file
View file

@ -0,0 +1,18 @@
package ape
import (
apegrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
)
func (tt TargetType) String() string {
return TargetTypeToGRPCField(tt).String()
}
func (tt *TargetType) FromString(s string) bool {
i, ok := apegrpc.TargetType_value[s]
if ok {
*tt = TargetType(i)
}
return ok
}

71
ape/test/generate.go Normal file
View file

@ -0,0 +1,71 @@
package test
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
)
func GenerateRawChains(empty bool, n int) []*ape.Chain {
if empty {
return []*ape.Chain{}
}
res := make([]*ape.Chain, n)
for i := range res {
res[i] = GenerateRawChain(empty)
}
return res
}
func GenerateRawChain(empty bool) *ape.Chain {
chRaw := new(ape.ChainRaw)
if empty {
chRaw.SetRaw([]byte("{}"))
} else {
chRaw.SetRaw([]byte(`{
"ID": "",
"Rules": [
{
"Status": "Allow",
"Actions": {
"Inverted": false,
"Names": [
"GetObject"
]
},
"Resources": {
"Inverted": false,
"Names": [
"native:object/*"
]
},
"Any": false,
"Condition": [
{
"Op": "StringEquals",
"Object": "Resource",
"Key": "Department",
"Value": "HR"
}
]
}
],
"MatchType": "DenyPriority"
}`))
}
ch := new(ape.Chain)
ch.SetKind(chRaw)
return ch
}
func GenerateChainTarget(empty bool) *ape.ChainTarget {
m := new(ape.ChainTarget)
if !empty {
m.SetTargetType(ape.TargetTypeContainer)
m.SetName("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")
}
return m
}

71
ape/types.go Normal file
View file

@ -0,0 +1,71 @@
package ape
type TargetType uint32
const (
TargetTypeUndefined TargetType = iota
TargetTypeNamespace
TargetTypeContainer
TargetTypeUser
TargetTypeGroup
)
type ChainTarget struct {
targeType TargetType
name string
}
func (ct *ChainTarget) SetTargetType(targeType TargetType) {
ct.targeType = targeType
}
func (ct *ChainTarget) SetName(name string) {
ct.name = name
}
func (ct *ChainTarget) GetTargetType() TargetType {
if ct != nil {
return ct.targeType
}
return 0
}
func (ct *ChainTarget) GetName() string {
if ct != nil {
return ct.name
}
return ""
}
type chainKind interface {
isChainKind()
}
type Chain struct {
kind chainKind
}
func (c *Chain) SetKind(kind chainKind) {
c.kind = kind
}
func (c *Chain) GetKind() chainKind {
return c.kind
}
type ChainRaw struct {
Raw []byte
}
func (*ChainRaw) isChainKind() {}
func (c *ChainRaw) SetRaw(raw []byte) {
c.Raw = raw
}
func (c *ChainRaw) GetRaw() []byte {
return c.Raw
}

358
apemanager/convert.go Normal file
View file

@ -0,0 +1,358 @@
package apemanager
import (
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
apeGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
apemanager "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (reqBody *AddChainRequestBody) ToGRPCMessage() grpc.Message {
var reqBodygrpc *apemanager.AddChainRequest_Body
if reqBody != nil {
reqBodygrpc = new(apemanager.AddChainRequest_Body)
reqBodygrpc.SetTarget(reqBody.GetTarget().ToGRPCMessage().(*apeGRPC.ChainTarget))
reqBodygrpc.SetChain(reqBody.GetChain().ToGRPCMessage().(*apeGRPC.Chain))
}
return reqBodygrpc
}
func (reqBody *AddChainRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.AddChainRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ape.ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
if chaingrpc := reqBodygrpc.GetChain(); chaingrpc != nil {
reqBody.chain = new(ape.Chain)
if err := reqBody.GetChain().FromGRPCMessage(chaingrpc); err != nil {
return err
}
}
return nil
}
func (req *AddChainRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.AddChainRequest
if req != nil {
reqgrpc = new(apemanager.AddChainRequest)
reqgrpc.SetBody(req.GetBody().ToGRPCMessage().(*apemanager.AddChainRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *AddChainRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.AddChainRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(AddChainRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *AddChainResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.AddChainResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.AddChainResponse_Body)
respBodygrpc.SetChainId(respBody.GetChainID())
}
return respBodygrpc
}
func (respBody *AddChainResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.AddChainResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
respBody.SetChainID(respBodygrpc.GetChainId())
return nil
}
func (resp *AddChainResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.AddChainResponse
if resp != nil {
respgrpc = new(apemanager.AddChainResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.AddChainResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *AddChainResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.AddChainResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(AddChainResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}
func (reqBody *RemoveChainRequestBody) ToGRPCMessage() grpc.Message {
var reqBodygrpc *apemanager.RemoveChainRequest_Body
if reqBody != nil {
reqBodygrpc = new(apemanager.RemoveChainRequest_Body)
reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apeGRPC.ChainTarget))
reqBodygrpc.SetChainId(reqBody.GetChainID())
}
return reqBodygrpc
}
func (reqBody *RemoveChainRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.RemoveChainRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ape.ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
reqBody.SetChainID(reqBodygrpc.GetChainId())
return nil
}
func (req *RemoveChainRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.RemoveChainRequest
if req != nil {
reqgrpc = new(apemanager.RemoveChainRequest)
reqgrpc.SetBody(req.body.ToGRPCMessage().(*apemanager.RemoveChainRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *RemoveChainRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.RemoveChainRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(RemoveChainRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *RemoveChainResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.RemoveChainResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.RemoveChainResponse_Body)
}
return respBodygrpc
}
func (respBody *RemoveChainResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.RemoveChainResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
return nil
}
func (resp *RemoveChainResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.RemoveChainResponse
if resp != nil {
respgrpc = new(apemanager.RemoveChainResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.RemoveChainResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *RemoveChainResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.RemoveChainResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(RemoveChainResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}
func (reqBody *ListChainsRequestBody) ToGRPCMessage() grpc.Message {
var reqBodygrpc *apemanager.ListChainsRequest_Body
if reqBody != nil {
reqBodygrpc = new(apemanager.ListChainsRequest_Body)
reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apeGRPC.ChainTarget))
}
return reqBodygrpc
}
func (reqBody *ListChainsRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.ListChainsRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ape.ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
return nil
}
func (req *ListChainsRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.ListChainsRequest
if req != nil {
reqgrpc = new(apemanager.ListChainsRequest)
reqgrpc.SetBody(req.body.ToGRPCMessage().(*apemanager.ListChainsRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *ListChainsRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.ListChainsRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(ListChainsRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *ListChainsResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.ListChainsResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.ListChainsResponse_Body)
chainsgrpc := make([]*apeGRPC.Chain, 0, len(respBody.GetChains()))
for _, chain := range respBody.GetChains() {
chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apeGRPC.Chain))
}
respBodygrpc.SetChains(chainsgrpc)
}
return respBodygrpc
}
func (respBody *ListChainsResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.ListChainsResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
chains := make([]*ape.Chain, 0, len(respBodygrpc.GetChains()))
for _, chaingrpc := range respBodygrpc.GetChains() {
chain := new(ape.Chain)
if err := chain.FromGRPCMessage(chaingrpc); err != nil {
return err
}
chains = append(chains, chain)
}
respBody.SetChains(chains)
return nil
}
func (resp *ListChainsResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.ListChainsResponse
if resp != nil {
respgrpc = new(apemanager.ListChainsResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.ListChainsResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *ListChainsResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.ListChainsResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(ListChainsResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}

106
apemanager/grpc/service.go Normal file
View file

@ -0,0 +1,106 @@
package apemanager
import (
ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc"
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
)
func (rb *AddChainRequest_Body) SetTarget(t *ape.ChainTarget) {
rb.Target = t
}
func (rb *AddChainRequest_Body) SetChain(chain *ape.Chain) {
rb.Chain = chain
}
func (r *AddChainRequest) SetBody(rb *AddChainRequest_Body) {
r.Body = rb
}
func (r *AddChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *AddChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *AddChainResponse_Body) SetChainId(chainID []byte) {
rb.ChainId = chainID
}
func (r *AddChainResponse) SetBody(rb *AddChainResponse_Body) {
r.Body = rb
}
func (r *AddChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *AddChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *RemoveChainRequest_Body) SetTarget(t *ape.ChainTarget) {
rb.Target = t
}
func (rb *RemoveChainRequest_Body) SetChainId(chainID []byte) {
rb.ChainId = chainID
}
func (r *RemoveChainRequest) SetBody(rb *RemoveChainRequest_Body) {
r.Body = rb
}
func (r *RemoveChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *RemoveChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (r *RemoveChainResponse) SetBody(rb *RemoveChainResponse_Body) {
r.Body = rb
}
func (r *RemoveChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *RemoveChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) {
r.VerifyHeader = vh
}
func (r *ListChainsRequest_Body) SetTarget(t *ape.ChainTarget) {
r.Target = t
}
func (r *ListChainsRequest) SetBody(rb *ListChainsRequest_Body) {
r.Body = rb
}
func (r *ListChainsRequest) SetMetaHeader(mh *session.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *ListChainsRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *ListChainsResponse_Body) SetChains(chains []*ape.Chain) {
rb.Chains = chains
}
func (r *ListChainsResponse) SetBody(rb *ListChainsResponse_Body) {
r.Body = rb
}
func (r *ListChainsResponse) SetMetaHeader(mh *session.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *ListChainsResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) {
r.VerifyHeader = vh
}

BIN
apemanager/grpc/service.pb.go generated Normal file

Binary file not shown.

BIN
apemanager/grpc/service_grpc.pb.go generated Normal file

Binary file not shown.

205
apemanager/marshal.go Normal file
View file

@ -0,0 +1,205 @@
package apemanager
import (
apemanager "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
addChainReqBodyTargetField = 1
addChainReqBodyChainField = 2
addChainRespBodyChainIDField = 1
removeChainReqBodyTargetField = 1
removeChainReqBodyChainField = 2
/*
Fields for RemoveResponseBody are missed since RemoveResponseBody is empty.
*/
listChainsReqBodyTargetField = 1
listChainsRespBodyChainsField = 1
)
func (rb *AddChainRequestBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.NestedStructureSize(addChainReqBodyTargetField, rb.target)
size += proto.NestedStructureSize(addChainReqBodyChainField, rb.chain)
return size
}
func (rb *AddChainRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(addChainReqBodyTargetField, buf[offset:], rb.target)
proto.NestedStructureMarshal(addChainReqBodyChainField, buf[offset:], rb.chain)
return buf
}
func (rb *AddChainRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.AddChainRequest_Body))
}
func (rb *AddChainResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.BytesSize(addChainRespBodyChainIDField, rb.chainID)
return size
}
func (rb *AddChainResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
proto.BytesMarshal(addChainRespBodyChainIDField, buf[offset:], rb.chainID)
return buf
}
func (rb *AddChainResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.AddChainResponse_Body))
}
func (rb *RemoveChainRequestBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.NestedStructureSize(addChainReqBodyTargetField, rb.target)
size += proto.BytesSize(addChainReqBodyChainField, rb.chainID)
return size
}
func (rb *RemoveChainRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(removeChainReqBodyTargetField, buf[offset:], rb.target)
proto.BytesMarshal(removeChainReqBodyChainField, buf[offset:], rb.chainID)
return buf
}
func (rb *RemoveChainRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.RemoveChainRequest_Body))
}
func (rb *RemoveChainResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
return size
}
func (rb *RemoveChainResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
return buf
}
func (rb *RemoveChainResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.RemoveChainResponse_Body))
}
func (rb *ListChainsRequestBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.NestedStructureSize(listChainsReqBodyTargetField, rb.target)
return size
}
func (rb *ListChainsRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
proto.NestedStructureMarshal(addChainReqBodyTargetField, buf[offset:], rb.target)
return buf
}
func (rb *ListChainsRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.ListChainsRequest_Body))
}
func (rb *ListChainsResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
for _, chain := range rb.GetChains() {
size += proto.NestedStructureSize(listChainsRespBodyChainsField, chain)
}
return size
}
func (rb *ListChainsResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
for _, chain := range rb.GetChains() {
offset += proto.NestedStructureMarshal(listChainsRespBodyChainsField, buf[offset:], chain)
}
return buf
}
func (rb *ListChainsResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.ListChainsResponse_Body))
}

View file

@ -0,0 +1,26 @@
package apemanager_test
import (
"testing"
apemanagertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return apemanagertest.GenerateAddChainRequestBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateAddChainRequest(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateAddChainResponseBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateAddChainResponse(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainRequestBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainRequest(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainResponseBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainResponse(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsRequestBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsRequest(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsResponseBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsResponse(empty) },
)
}

76
apemanager/status.go Normal file
View file

@ -0,0 +1,76 @@
package apemanager
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
)
// LocalizeFailStatus checks if passed global status.Code is related to ape manager failure and:
//
// then localizes the code and returns true,
// else leaves the code unchanged and returns false.
//
// Arg must be non-nil.
func LocalizeFailStatus(c *status.Code) bool {
return status.LocalizeIfInSection(c, uint32(statusgrpc.Section_SECTION_APE_MANAGER))
}
// GlobalizeFail globalizes local code of ape manager failure.
//
// Arg must be non-nil.
func GlobalizeFail(c *status.Code) {
c.GlobalizeSection(uint32(statusgrpc.Section_SECTION_APE_MANAGER))
}
const (
// StatusAPEManagerAccessDenied is a local status.Code value for
// ACCESS_DENIED ape manager failure.
StatusAPEManagerAccessDenied status.Code = iota
)
const (
// detailAccessDeniedDesc is a StatusAccessDenied detail ID for
// human-readable description.
detailAccessDeniedDesc = iota
)
// WriteAccessDeniedDesc writes human-readable description of StatusAccessDenied
// into status.Status as a detail. The status must not be nil.
//
// Existing details are expected to be ID-unique, otherwise undefined behavior.
func WriteAccessDeniedDesc(st *status.Status, desc string) {
var found bool
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
found = true
d.SetValue([]byte(desc))
}
return found
})
if !found {
var d status.Detail
d.SetID(detailAccessDeniedDesc)
d.SetValue([]byte(desc))
st.AppendDetails(d)
}
}
// ReadAccessDeniedDesc looks up for status detail with human-readable description
// of StatusAccessDenied. Returns empty string if detail is missing.
func ReadAccessDeniedDesc(st status.Status) (desc string) {
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
desc = string(d.Value())
return true
}
return false
})
return
}

30
apemanager/status_test.go Normal file
View file

@ -0,0 +1,30 @@
package apemanager_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test"
"github.com/stretchr/testify/require"
)
func TestStatusCodes(t *testing.T) {
statustest.TestCodes(t, apemanager.LocalizeFailStatus, apemanager.GlobalizeFail,
apemanager.StatusAPEManagerAccessDenied, 5120,
)
}
func TestAccessDeniedDesc(t *testing.T) {
var st status.Status
require.Empty(t, apemanager.ReadAccessDeniedDesc(st))
const desc = "some description"
apemanager.WriteAccessDeniedDesc(&st, desc)
require.Equal(t, desc, apemanager.ReadAccessDeniedDesc(st))
apemanager.WriteAccessDeniedDesc(&st, desc+"1")
require.Equal(t, desc+"1", apemanager.ReadAccessDeniedDesc(st))
}

143
apemanager/test/generate.go Normal file
View file

@ -0,0 +1,143 @@
package apemanagertest
import (
apetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
func generateChainID(empty bool) []byte {
if empty {
return []byte{}
}
return []byte("616c6c6f774f626a476574436e72")
}
func GenerateAddChainRequestBody(empty bool) *apemanager.AddChainRequestBody {
m := new(apemanager.AddChainRequestBody)
if !empty {
m.SetTarget(apetest.GenerateChainTarget(empty))
m.SetChain(apetest.GenerateRawChain(empty))
}
return m
}
func GenerateAddChainRequest(empty bool) *apemanager.AddChainRequest {
m := new(apemanager.AddChainRequest)
if !empty {
m.SetBody(GenerateAddChainRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateAddChainResponseBody(empty bool) *apemanager.AddChainResponseBody {
m := new(apemanager.AddChainResponseBody)
if !empty {
m.SetChainID(generateChainID(empty))
}
return m
}
func GenerateAddChainResponse(empty bool) *apemanager.AddChainResponse {
m := new(apemanager.AddChainResponse)
if !empty {
m.SetBody(GenerateAddChainResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}
func GenerateRemoveChainRequestBody(empty bool) *apemanager.RemoveChainRequestBody {
m := new(apemanager.RemoveChainRequestBody)
if !empty {
m.SetChainID(generateChainID(empty))
m.SetTarget(apetest.GenerateChainTarget(empty))
}
return m
}
func GenerateRemoveChainRequest(empty bool) *apemanager.RemoveChainRequest {
m := new(apemanager.RemoveChainRequest)
if !empty {
m.SetBody(GenerateRemoveChainRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateRemoveChainResponseBody(_ bool) *apemanager.RemoveChainResponseBody {
return new(apemanager.RemoveChainResponseBody)
}
func GenerateRemoveChainResponse(empty bool) *apemanager.RemoveChainResponse {
m := new(apemanager.RemoveChainResponse)
if !empty {
m.SetBody(GenerateRemoveChainResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}
func GenerateListChainsRequestBody(empty bool) *apemanager.ListChainsRequestBody {
m := new(apemanager.ListChainsRequestBody)
if !empty {
m.SetTarget(apetest.GenerateChainTarget(empty))
}
return m
}
func GenerateListChainsRequest(empty bool) *apemanager.ListChainsRequest {
m := new(apemanager.ListChainsRequest)
if !empty {
m.SetBody(GenerateListChainsRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateListChainsResponseBody(empty bool) *apemanager.ListChainsResponseBody {
m := new(apemanager.ListChainsResponseBody)
if !empty {
m.SetChains(apetest.GenerateRawChains(empty, 10))
}
return m
}
func GenerateListChainsResponse(empty bool) *apemanager.ListChainsResponse {
m := new(apemanager.ListChainsResponse)
if !empty {
m.SetBody(GenerateListChainsResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}

175
apemanager/types.go Normal file
View file

@ -0,0 +1,175 @@
package apemanager
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
)
type AddChainRequest struct {
body *AddChainRequestBody
session.RequestHeaders
}
func (r *AddChainRequest) SetBody(body *AddChainRequestBody) {
r.body = body
}
func (r *AddChainRequest) GetBody() *AddChainRequestBody {
return r.body
}
type AddChainRequestBody struct {
target *ape.ChainTarget
chain *ape.Chain
}
func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) {
rb.target = target
}
func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget {
return rb.target
}
func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) {
rb.chain = chain
}
func (rb *AddChainRequestBody) GetChain() *ape.Chain {
return rb.chain
}
type AddChainResponse struct {
body *AddChainResponseBody
session.ResponseHeaders
}
func (r *AddChainResponse) SetBody(body *AddChainResponseBody) {
r.body = body
}
func (r *AddChainResponse) GetBody() *AddChainResponseBody {
return r.body
}
type AddChainResponseBody struct {
chainID []byte
}
func (rb *AddChainResponseBody) SetChainID(chainID []byte) {
rb.chainID = chainID
}
func (rb *AddChainResponseBody) GetChainID() []byte {
return rb.chainID
}
type RemoveChainRequest struct {
body *RemoveChainRequestBody
session.RequestHeaders
}
func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) {
r.body = body
}
func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody {
return r.body
}
type RemoveChainRequestBody struct {
target *ape.ChainTarget
chainID []byte
}
func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) {
rb.target = target
}
func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget {
return rb.target
}
func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) {
rb.chainID = chainID
}
func (rb *RemoveChainRequestBody) GetChainID() []byte {
return rb.chainID
}
type RemoveChainResponse struct {
body *RemoveChainResponseBody
session.ResponseHeaders
}
type RemoveChainResponseBody struct {
}
func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) {
r.body = body
}
func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody {
return r.body
}
type ListChainsRequest struct {
body *ListChainsRequestBody
session.RequestHeaders
}
func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) {
r.body = body
}
func (r *ListChainsRequest) GetBody() *ListChainsRequestBody {
return r.body
}
type ListChainsRequestBody struct {
target *ape.ChainTarget
}
func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) {
rb.target = target
}
func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget {
return rb.target
}
type ListChainsResponse struct {
body *ListChainsResponseBody
session.ResponseHeaders
}
func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) {
r.body = body
}
func (r *ListChainsResponse) GetBody() *ListChainsResponseBody {
return r.body
}
type ListChainsResponseBody struct {
chains []*ape.Chain
session.RequestHeaders
}
func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) {
r.chains = chains
}
func (r *ListChainsResponseBody) GetChains() []*ape.Chain {
return r.chains
}

View file

@ -1,94 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *DataAuditResult) ToGRPCMessage() grpc.Message {
var m *audit.DataAuditResult
if a != nil {
m = new(audit.DataAuditResult)
m.SetAuditEpoch(a.auditEpoch)
m.SetPublicKey(a.pubKey)
m.SetContainerId(a.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
m.SetComplete(a.complete)
m.SetVersion(a.version.ToGRPCMessage().(*refsGRPC.Version))
m.SetPassNodes(a.passNodes)
m.SetFailNodes(a.failNodes)
m.SetRetries(a.retries)
m.SetRequests(a.requests)
m.SetHit(a.hit)
m.SetMiss(a.miss)
m.SetFail(a.fail)
m.SetPassSg(refs.ObjectIDListToGRPCMessage(a.passSG))
m.SetFailSg(refs.ObjectIDListToGRPCMessage(a.failSG))
}
return m
}
func (a *DataAuditResult) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*audit.DataAuditResult)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
cid := v.GetContainerId()
if cid == nil {
a.cid = nil
} else {
if a.cid == nil {
a.cid = new(refs.ContainerID)
}
err = a.cid.FromGRPCMessage(cid)
if err != nil {
return err
}
}
version := v.GetVersion()
if version == nil {
a.version = nil
} else {
if a.version == nil {
a.version = new(refs.Version)
}
err = a.version.FromGRPCMessage(version)
if err != nil {
return err
}
}
a.passSG, err = refs.ObjectIDListFromGRPCMessage(v.GetPassSg())
if err != nil {
return err
}
a.failSG, err = refs.ObjectIDListFromGRPCMessage(v.GetFailSg())
if err != nil {
return err
}
a.auditEpoch = v.GetAuditEpoch()
a.pubKey = v.GetPublicKey()
a.complete = v.GetComplete()
a.passNodes = v.GetPassNodes()
a.failNodes = v.GetFailNodes()
a.retries = v.GetRetries()
a.requests = v.GetRequests()
a.hit = v.GetHit()
a.miss = v.GetMiss()
a.fail = v.GetFail()
return err
}

View file

@ -1,75 +0,0 @@
package audit
import (
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
)
// SetVersion is a Version field setter.
func (x *DataAuditResult) SetVersion(v *refs.Version) {
x.Version = v
}
// SetAuditEpoch is an AuditEpoch field setter.
func (x *DataAuditResult) SetAuditEpoch(v uint64) {
x.AuditEpoch = v
}
// SetContainerId is a ContainerId field setter.
func (x *DataAuditResult) SetContainerId(v *refs.ContainerID) {
x.ContainerId = v
}
// SetPublicKey is a PublicKey field setter.
func (x *DataAuditResult) SetPublicKey(v []byte) {
x.PublicKey = v
}
// SetComplete is a Complete field setter.
func (x *DataAuditResult) SetComplete(v bool) {
x.Complete = v
}
// SetRequests is a Requests field setter.
func (x *DataAuditResult) SetRequests(v uint32) {
x.Requests = v
}
// SetRetries is a Retries field setter.
func (x *DataAuditResult) SetRetries(v uint32) {
x.Retries = v
}
// SetPassSg is a PassSg field setter.
func (x *DataAuditResult) SetPassSg(v []*refs.ObjectID) {
x.PassSg = v
}
// SetFailSg is a FailSg field setter.
func (x *DataAuditResult) SetFailSg(v []*refs.ObjectID) {
x.FailSg = v
}
// SetHit is a Hit field setter.
func (x *DataAuditResult) SetHit(v uint32) {
x.Hit = v
}
// SetMiss is a Miss field setter.
func (x *DataAuditResult) SetMiss(v uint32) {
x.Miss = v
}
// SetFail is a Fail field setter.
func (x *DataAuditResult) SetFail(v uint32) {
x.Fail = v
}
// SetPassNodes is a PassNodes field setter.
func (x *DataAuditResult) SetPassNodes(v [][]byte) {
x.PassNodes = v
}
// SetFailNodes is a FailNodes field setter.
func (x *DataAuditResult) SetFailNodes(v [][]byte) {
x.FailNodes = v
}

BIN
audit/grpc/types.pb.go generated

Binary file not shown.

View file

@ -1,14 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *DataAuditResult) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *DataAuditResult) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(audit.DataAuditResult))
}

View file

@ -1,88 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
_ = iota
versionFNum
auditEpochFNum
cidFNum
pubKeyFNum
completeFNum
requestsFNum
retriesFNum
passSGFNum
failSGFNum
hitFNum
missFNum
failFNum
passNodesFNum
failNodesFNum
)
// StableMarshal marshals unified DataAuditResult structure into a protobuf
// binary format without field order shuffle.
func (a *DataAuditResult) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version)
offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch)
offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid)
offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey)
offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests)
offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries)
offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG)
offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG)
offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit)
offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss)
offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail)
offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
return buf
}
// StableSize returns byte length of DataAuditResult structure
// marshaled by StableMarshal function.
func (a *DataAuditResult) StableSize() (size int) {
if a == nil {
return 0
}
size += proto.NestedStructureSize(versionFNum, a.version)
size += proto.Fixed64Size(auditEpochFNum, a.auditEpoch)
size += proto.NestedStructureSize(cidFNum, a.cid)
size += proto.BytesSize(pubKeyFNum, a.pubKey)
size += proto.BoolSize(completeFNum, a.complete)
size += proto.UInt32Size(requestsFNum, a.requests)
size += proto.UInt32Size(retriesFNum, a.retries)
size += refs.ObjectIDNestedListSize(passSGFNum, a.passSG)
size += refs.ObjectIDNestedListSize(failSGFNum, a.failSG)
size += proto.UInt32Size(hitFNum, a.hit)
size += proto.UInt32Size(missFNum, a.miss)
size += proto.UInt32Size(failFNum, a.fail)
size += proto.RepeatedBytesSize(passNodesFNum, a.passNodes)
size += proto.RepeatedBytesSize(failNodesFNum, a.failNodes)
return size
}
// Unmarshal unmarshals DataAuditResult structure from its protobuf
// binary representation.
func (a *DataAuditResult) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(audit.DataAuditResult))
}

View file

@ -1,29 +0,0 @@
package audittest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
)
func GenerateDataAuditResult(empty bool) *audit.DataAuditResult {
m := new(audit.DataAuditResult)
if !empty {
m.SetPublicKey([]byte{1, 2, 3})
m.SetAuditEpoch(13)
m.SetHit(100)
m.SetMiss(200)
m.SetFail(300)
m.SetComplete(true)
m.SetPassNodes([][]byte{{1}, {2}})
m.SetFailNodes([][]byte{{3}, {4}})
m.SetRequests(666)
m.SetRetries(777)
m.SetVersion(refstest.GenerateVersion(false))
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetPassSG(refstest.GenerateObjectIDs(false))
m.SetFailSG(refstest.GenerateObjectIDs(false))
}
return m
}

View file

@ -1,243 +0,0 @@
package audit
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
)
// DataAuditResult is a unified structure of
// DataAuditResult message from proto definition.
type DataAuditResult struct {
version *refs.Version
auditEpoch uint64
requests, retries uint32
hit, miss, fail uint32
cid *refs.ContainerID
pubKey []byte
passSG, failSG []refs.ObjectID
failNodes, passNodes [][]byte
complete bool
}
// GetVersion returns version of Data Audit structure.
func (a *DataAuditResult) GetVersion() *refs.Version {
if a != nil {
return a.version
}
return nil
}
// SetVersion sets version of Data Audit structure.
func (a *DataAuditResult) SetVersion(v *refs.Version) {
a.version = v
}
// GetAuditEpoch returns epoch number when the Data Audit was conducted.
func (a *DataAuditResult) GetAuditEpoch() uint64 {
if a != nil {
return a.auditEpoch
}
return 0
}
// SetAuditEpoch sets epoch number when the Data Audit was conducted.
func (a *DataAuditResult) SetAuditEpoch(v uint64) {
a.auditEpoch = v
}
// GetContainerID returns container under audit.
func (a *DataAuditResult) GetContainerID() *refs.ContainerID {
if a != nil {
return a.cid
}
return nil
}
// SetContainerID sets container under audit.
func (a *DataAuditResult) SetContainerID(v *refs.ContainerID) {
a.cid = v
}
// GetPublicKey returns public key of the auditing InnerRing node in a binary format.
func (a *DataAuditResult) GetPublicKey() []byte {
if a != nil {
return a.pubKey
}
return nil
}
// SetPublicKey sets public key of the auditing InnerRing node in a binary format.
func (a *DataAuditResult) SetPublicKey(v []byte) {
a.pubKey = v
}
// GetPassSG returns list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) GetPassSG() []refs.ObjectID {
if a != nil {
return a.passSG
}
return nil
}
// SetPassSG sets list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) SetPassSG(v []refs.ObjectID) {
a.passSG = v
}
// GetFailSG returns list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) GetFailSG() []refs.ObjectID {
if a != nil {
return a.failSG
}
return nil
}
// SetFailSG sets list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) SetFailSG(v []refs.ObjectID) {
a.failSG = v
}
// GetRequests returns number of requests made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) GetRequests() uint32 {
if a != nil {
return a.requests
}
return 0
}
// SetRequests sets number of requests made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) SetRequests(v uint32) {
a.requests = v
}
// GetRetries returns number of retries made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) GetRetries() uint32 {
if a != nil {
return a.retries
}
return 0
}
// SetRetries sets number of retries made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) SetRetries(v uint32) {
a.retries = v
}
// GetHit returns number of sampled objects under audit placed
// in an optimal way according to the containers placement policy
// when checking PoP.
func (a *DataAuditResult) GetHit() uint32 {
if a != nil {
return a.hit
}
return 0
}
// SetHit sets number of sampled objects under audit placed
// in an optimal way according to the containers placement policy
// when checking PoP.
func (a *DataAuditResult) SetHit(v uint32) {
a.hit = v
}
// GetMiss returns number of sampled objects under audit placed
// in suboptimal way according to the containers placement policy,
// but still at a satisfactory level when checking PoP.
func (a *DataAuditResult) GetMiss() uint32 {
if a != nil {
return a.miss
}
return 0
}
// SetMiss sets number of sampled objects under audit placed
// in suboptimal way according to the containers placement policy,
// but still at a satisfactory level when checking PoP.
func (a *DataAuditResult) SetMiss(v uint32) {
a.miss = v
}
// GetFail returns number of sampled objects under audit stored
// in a way not confirming placement policy or not found at all
// when checking PoP.
func (a *DataAuditResult) GetFail() uint32 {
if a != nil {
return a.fail
}
return 0
}
// SetFail sets number of sampled objects under audit stored
// in a way not confirming placement policy or not found at all
// when checking PoP.
func (a *DataAuditResult) SetFail(v uint32) {
a.fail = v
}
// GetPassNodes returns list of storage node public keys that
// passed at least one PDP.
func (a *DataAuditResult) GetPassNodes() [][]byte {
if a != nil {
return a.passNodes
}
return nil
}
// SetPassNodes sets list of storage node public keys that
// passed at least one PDP.
func (a *DataAuditResult) SetPassNodes(v [][]byte) {
a.passNodes = v
}
// GetFailNodes returns list of storage node public keys that
// failed at least one PDP.
func (a *DataAuditResult) GetFailNodes() [][]byte {
if a != nil {
return a.failNodes
}
return nil
}
// SetFailNodes sets list of storage node public keys that
// failed at least one PDP.
func (a *DataAuditResult) SetFailNodes(v [][]byte) {
a.failNodes = v
}
// GetComplete returns boolean completion statement of audit result.
func (a *DataAuditResult) GetComplete() bool {
if a != nil {
return a.complete
}
return false // bool default
}
// SetComplete sets boolean completion statement of audit result.
func (a *DataAuditResult) SetComplete(v bool) {
a.complete = v
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
go.mod
View file

@ -7,7 +7,7 @@ require (
github.com/stretchr/testify v1.8.3
golang.org/x/sync v0.2.0
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.30.0
google.golang.org/protobuf v1.33.0
)
require (

4
go.sum
View file

@ -38,8 +38,8 @@ google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

BIN
lock/grpc/types.pb.go generated

Binary file not shown.

View file

@ -142,6 +142,8 @@ func (r *Replica) ToGRPCMessage() grpc.Message {
m.SetSelector(r.selector)
m.SetCount(r.count)
m.EcDataCount = r.ecDataCount
m.EcParityCount = r.ecParityCount
}
return m
@ -155,6 +157,8 @@ func (r *Replica) FromGRPCMessage(m grpc.Message) error {
r.selector = v.GetSelector()
r.count = v.GetCount()
r.ecDataCount = v.GetEcDataCount()
r.ecParityCount = v.GetEcParityCount()
return nil
}

Binary file not shown.

Binary file not shown.

BIN
netmap/grpc/types.pb.go generated

Binary file not shown.

View file

@ -19,8 +19,10 @@ const (
attributeSelectorField = 4
filterSelectorField = 5
countReplicaField = 1
selectorReplicaField = 2
countReplicaField = 1
selectorReplicaField = 2
ecDataCountReplicaField = 3
ecParityCountReplicaField = 4
replicasPolicyField = 1
backupPolicyField = 2
@ -134,7 +136,9 @@ func (r *Replica) StableMarshal(buf []byte) []byte {
var offset int
offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count)
protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
offset += protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
offset += protoutil.UInt32Marshal(ecDataCountReplicaField, buf[offset:], r.ecDataCount)
protoutil.UInt32Marshal(ecParityCountReplicaField, buf[offset:], r.ecParityCount)
return buf
}
@ -146,6 +150,8 @@ func (r *Replica) StableSize() (size int) {
size += protoutil.UInt32Size(countReplicaField, r.count)
size += protoutil.StringSize(selectorReplicaField, r.selector)
size += protoutil.UInt32Size(ecDataCountReplicaField, r.ecDataCount)
size += protoutil.UInt32Size(ecParityCountReplicaField, r.ecParityCount)
return size
}

View file

@ -81,6 +81,17 @@ func GenerateReplica(empty bool) *netmap.Replica {
return m
}
func GenerateEC(empty bool) *netmap.Replica {
m := new(netmap.Replica)
if !empty {
m.SetECDataCount(4)
m.SetECParityCount(2)
}
return m
}
func GenerateReplicas(empty bool) []netmap.Replica {
var res []netmap.Replica
@ -88,6 +99,7 @@ func GenerateReplicas(empty bool) []netmap.Replica {
res = append(res,
*GenerateReplica(false),
*GenerateReplica(false),
*GenerateEC(false),
)
}

View file

@ -50,6 +50,9 @@ type Selector struct {
type Replica struct {
count uint32
selector string
ecDataCount uint32
ecParityCount uint32
}
type Operation uint32
@ -259,6 +262,30 @@ func (r *Replica) SetCount(count uint32) {
r.count = count
}
func (r *Replica) GetECDataCount() uint32 {
if r != nil {
return r.ecDataCount
}
return 0
}
func (r *Replica) SetECDataCount(count uint32) {
r.ecDataCount = count
}
func (r *Replica) GetECParityCount() uint32 {
if r != nil {
return r.ecParityCount
}
return 0
}
func (r *Replica) SetECParityCount(count uint32) {
r.ecParityCount = count
}
func (p *PlacementPolicy) GetUnique() bool {
if p != nil {
return p.unique

View file

@ -10,7 +10,7 @@ import (
func TestSetNotification(t *testing.T) {
o := new(Object)
var ni = NotificationInfo{
ni := NotificationInfo{
epoch: 10,
topic: "test",
}

View file

@ -262,6 +262,74 @@ func (h *SplitHeader) FromGRPCMessage(m grpc.Message) error {
return nil
}
func (h *ECHeader) ToGRPCMessage() grpc.Message {
var m *object.Header_EC
if h != nil {
m = new(object.Header_EC)
m.Parent = h.Parent.ToGRPCMessage().(*refsGRPC.ObjectID)
m.ParentSplitId = h.ParentSplitID
m.ParentSplitParentId = h.ParentSplitParentID.ToGRPCMessage().(*refsGRPC.ObjectID)
m.ParentAttributes = AttributesToGRPC(h.ParentAttributes)
m.Index = h.Index
m.Total = h.Total
m.Header = h.Header
m.HeaderLength = h.HeaderLength
}
return m
}
func (h *ECHeader) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*object.Header_EC)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
par := v.GetParent()
if par == nil {
h.Parent = nil
} else {
if h.Parent == nil {
h.Parent = new(refs.ObjectID)
}
err = h.Parent.FromGRPCMessage(par)
if err != nil {
return err
}
}
h.ParentSplitID = v.GetParentSplitId()
parSplitParentID := v.GetParentSplitParentId()
if parSplitParentID == nil {
h.ParentSplitParentID = nil
} else {
if h.ParentSplitParentID == nil {
h.ParentSplitParentID = new(refs.ObjectID)
}
err = h.ParentSplitParentID.FromGRPCMessage(parSplitParentID)
if err != nil {
return err
}
}
if h.ParentAttributes, err = AttributesFromGRPC(v.GetParentAttributes()); err != nil {
return err
}
h.Index = v.GetIndex()
h.Total = v.GetTotal()
h.Header = v.GetHeader()
h.HeaderLength = v.GetHeaderLength()
return nil
}
func (h *Header) ToGRPCMessage() grpc.Message {
var m *object.Header
@ -275,6 +343,7 @@ func (h *Header) ToGRPCMessage() grpc.Message {
m.SetContainerId(h.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
m.SetSessionToken(h.sessionToken.ToGRPCMessage().(*sessionGRPC.SessionToken))
m.SetSplit(h.split.ToGRPCMessage().(*object.Header_Split))
m.Ec = h.ec.ToGRPCMessage().(*object.Header_EC)
m.SetAttributes(AttributesToGRPC(h.attr))
m.SetPayloadLength(h.payloadLen)
m.SetCreationEpoch(h.creatEpoch)
@ -313,6 +382,9 @@ func (h *Header) FromGRPCMessage(m grpc.Message) error {
if err := h.fillSplitHeader(v); err != nil {
return err
}
if err := h.fillECHeader(v); err != nil {
return err
}
h.attr, err = AttributesFromGRPC(v.GetAttributes())
if err != nil {
@ -417,6 +489,19 @@ func (h *Header) fillSplitHeader(v *object.Header) error {
return h.split.FromGRPCMessage(split)
}
func (h *Header) fillECHeader(v *object.Header) error {
ec := v.GetEc()
if ec == nil {
h.ec = nil
return nil
}
if h.ec == nil {
h.ec = new(ECHeader)
}
return h.ec.FromGRPCMessage(ec)
}
func (h *HeaderWithSignature) ToGRPCMessage() grpc.Message {
var m *object.HeaderWithSignature
@ -591,6 +676,73 @@ func (s *SplitInfo) FromGRPCMessage(m grpc.Message) error {
return nil
}
func (s *ECInfo) ToGRPCMessage() grpc.Message {
var m *object.ECInfo
if s != nil {
m = new(object.ECInfo)
if s.Chunks != nil {
chunks := make([]*object.ECInfo_Chunk, len(s.Chunks))
for i := range chunks {
chunks[i] = s.Chunks[i].ToGRPCMessage().(*object.ECInfo_Chunk)
}
m.Chunks = chunks
}
}
return m
}
func (s *ECInfo) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*object.ECInfo)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
chunks := v.GetChunks()
if chunks == nil {
s.Chunks = nil
} else {
s.Chunks = make([]ECChunk, len(chunks))
for i := range chunks {
if err := s.Chunks[i].FromGRPCMessage(chunks[i]); err != nil {
return err
}
}
}
return nil
}
func (c *ECChunk) ToGRPCMessage() grpc.Message {
var m *object.ECInfo_Chunk
if c != nil {
m = new(object.ECInfo_Chunk)
m.Total = c.Total
m.Index = c.Index
m.Id = c.ID.ToGRPCMessage().(*refsGRPC.ObjectID)
}
return m
}
func (c *ECChunk) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*object.ECInfo_Chunk)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
if err := c.ID.FromGRPCMessage(v.GetId()); err != nil {
return err
}
c.Index = v.Index
c.Total = v.Total
return nil
}
func (r *GetRequestBody) ToGRPCMessage() grpc.Message {
var m *object.GetRequest_Body
@ -771,6 +923,8 @@ func (r *GetResponseBody) ToGRPCMessage() grpc.Message {
m.SetChunk(t.ToGRPCMessage().(*object.GetResponse_Body_Chunk))
case *SplitInfo:
m.SetSplitInfo(t.ToGRPCMessage().(*object.SplitInfo))
case *ECInfo:
m.SetEcInfo(t.ToGRPCMessage().(*object.ECInfo))
default:
panic(fmt.Sprintf("unknown get object part %T", t))
}
@ -809,6 +963,12 @@ func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error {
r.objPart = partSplit
err = partSplit.FromGRPCMessage(pt.SplitInfo)
}
case *object.GetResponse_Body_EcInfo:
if pt != nil {
partEC := new(ECInfo)
r.objPart = partEC
err = partEC.FromGRPCMessage(pt.EcInfo)
}
default:
err = fmt.Errorf("unknown get object part %T", pt)
}
@ -1348,6 +1508,8 @@ func (r *HeadResponseBody) ToGRPCMessage() grpc.Message {
m.SetShortHeader(v.ToGRPCMessage().(*object.ShortHeader))
case *SplitInfo:
m.SetSplitInfo(v.ToGRPCMessage().(*object.SplitInfo))
case *ECInfo:
m.SetEcInfo(v.ToGRPCMessage().(*object.ECInfo))
default:
panic(fmt.Sprintf("unknown head part %T", v))
}
@ -1386,6 +1548,12 @@ func (r *HeadResponseBody) FromGRPCMessage(m grpc.Message) error {
r.hdrPart = partSplit
err = partSplit.FromGRPCMessage(pt.SplitInfo)
}
case *object.HeadResponse_Body_EcInfo:
if pt != nil {
partEC := new(ECInfo)
r.hdrPart = partEC
err = partEC.FromGRPCMessage(pt.EcInfo)
}
default:
err = fmt.Errorf("unknown head part %T", pt)
}
@ -1817,6 +1985,8 @@ func (r *GetRangeResponseBody) ToGRPCMessage() grpc.Message {
m.SetChunk(v.ToGRPCMessage().(*object.GetRangeResponse_Body_Chunk))
case *SplitInfo:
m.SetSplitInfo(v.ToGRPCMessage().(*object.SplitInfo))
case *ECInfo:
m.SetEcInfo(v.ToGRPCMessage().(*object.ECInfo))
default:
panic(fmt.Sprintf("unknown get range part %T", v))
}
@ -1849,6 +2019,12 @@ func (r *GetRangeResponseBody) FromGRPCMessage(m grpc.Message) error {
r.rngPart = partSplit
err = partSplit.FromGRPCMessage(pt.SplitInfo)
}
case *object.GetRangeResponse_Body_EcInfo:
if pt != nil {
partEC := new(ECInfo)
r.rngPart = partEC
err = partEC.FromGRPCMessage(pt.EcInfo)
}
default:
err = fmt.Errorf("unknown get range part %T", pt)
}

View file

@ -36,6 +36,9 @@ const (
// FilterHeaderSplitID is a filter key to "split.splitID" field of the object header.
FilterHeaderSplitID = ReservedFilterPrefix + "split.splitID"
// FilterHeaderECParent is a filter key to "ec.parent" field of the object header.
FilterHeaderECParent = ReservedFilterPrefix + "ec.parent"
)
const (

View file

@ -78,6 +78,13 @@ func (m *GetResponse_Body) SetSplitInfo(v *SplitInfo) {
}
}
// SetEcInfo sets part of the object payload.
func (m *GetResponse_Body) SetEcInfo(v *ECInfo) {
m.ObjectPart = &GetResponse_Body_EcInfo{
EcInfo: v,
}
}
// SetBody sets body of the response.
func (m *GetResponse) SetBody(v *GetResponse_Body) {
m.Body = v
@ -275,6 +282,13 @@ func (m *HeadResponse_Body) SetSplitInfo(v *SplitInfo) {
}
}
// SetEcInfo sets meta info about the erasure coded object.
func (m *HeadResponse_Body) SetEcInfo(v *ECInfo) {
m.Head = &HeadResponse_Body_EcInfo{
EcInfo: v,
}
}
// SetBody sets body of the response.
func (m *HeadResponse) SetBody(v *HeadResponse_Body) {
m.Body = v
@ -421,6 +435,13 @@ func (m *GetRangeResponse_Body) SetSplitInfo(v *SplitInfo) {
}
}
// SetEcInfo sets meta info about the erasure-coded object.
func (m *GetRangeResponse_Body) SetEcInfo(v *ECInfo) {
m.RangePart = &GetRangeResponse_Body_EcInfo{
EcInfo: v,
}
}
// SetBody sets body of the response.
func (m *GetRangeResponse) SetBody(v *GetRangeResponse_Body) {
m.Body = v

Binary file not shown.

Binary file not shown.

BIN
object/grpc/types.pb.go generated

Binary file not shown.

View file

@ -61,6 +61,22 @@ func (s *SplitInfo) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(s, data, new(object.SplitInfo))
}
func (e *ECInfo) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(e)
}
func (e *ECInfo) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(e, data, new(object.ECInfo))
}
func (e *ECChunk) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(e)
}
func (e *ECChunk) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(e, data, new(object.ECInfo_Chunk))
}
func (f *SearchFilter) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(f)
}

View file

@ -26,6 +26,15 @@ const (
splitHdrChildrenField = 5
splitHdrSplitIDField = 6
ecHdrParentField = 1
ecHdrIndexField = 2
ecHdrTotalField = 3
ecHdrHeaderLengthField = 4
ecHdrHeaderField = 5
ecHdrParentSplitID = 6
ecHdrParentSplitParentID = 7
ecHdrParentAttributes = 8
hdrVersionField = 1
hdrContainerIDField = 2
hdrOwnerIDField = 3
@ -37,6 +46,7 @@ const (
hdrSessionTokenField = 9
hdrAttributesField = 10
hdrSplitField = 11
hdrECField = 12
hdrWithSigHeaderField = 1
hdrWithSigSignatureField = 2
@ -50,6 +60,12 @@ const (
splitInfoLastPartField = 2
splitInfoLinkField = 3
ecInfoChunksField = 1
ecChunkIDField = 1
ecChunkIndexField = 2
ecChunkTotalField = 3
getReqBodyAddressField = 1
getReqBodyRawFlagField = 2
@ -60,6 +76,7 @@ const (
getRespBodyInitField = 1
getRespBodyChunkField = 2
getRespBodySplitInfoField = 3
getRespBodyECInfoField = 4
putReqInitObjectIDField = 1
putReqInitSignatureField = 2
@ -82,6 +99,7 @@ const (
headRespBodyHeaderField = 1
headRespBodyShortHeaderField = 2
headRespBodySplitInfoField = 3
headRespBodyECInfoField = 4
searchFilterMatchField = 1
searchFilterNameField = 2
@ -102,6 +120,7 @@ const (
getRangeRespChunkField = 1
getRangeRespSplitInfoField = 2
getRangeRespECInfoField = 3
getRangeHashReqBodyAddressField = 1
getRangeHashReqBodyRangesField = 2
@ -229,6 +248,53 @@ func (h *SplitHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header_Split))
}
func (h *ECHeader) StableMarshal(buf []byte) []byte {
if h == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, h.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(ecHdrParentField, buf[offset:], h.Parent)
offset += proto.UInt32Marshal(ecHdrIndexField, buf[offset:], h.Index)
offset += proto.UInt32Marshal(ecHdrTotalField, buf[offset:], h.Total)
offset += proto.UInt32Marshal(ecHdrHeaderLengthField, buf[offset:], h.HeaderLength)
offset += proto.BytesMarshal(ecHdrHeaderField, buf[offset:], h.Header)
offset += proto.BytesMarshal(ecHdrParentSplitID, buf[offset:], h.ParentSplitID)
offset += proto.NestedStructureMarshal(ecHdrParentSplitParentID, buf[offset:], h.ParentSplitParentID)
for i := range h.ParentAttributes {
offset += proto.NestedStructureMarshal(ecHdrParentAttributes, buf[offset:], &h.ParentAttributes[i])
}
return buf
}
func (h *ECHeader) StableSize() (size int) {
if h == nil {
return 0
}
size += proto.NestedStructureSize(ecHdrParentField, h.Parent)
size += proto.UInt32Size(ecHdrIndexField, h.Index)
size += proto.UInt32Size(ecHdrTotalField, h.Total)
size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength)
size += proto.BytesSize(ecHdrHeaderField, h.Header)
size += proto.BytesSize(ecHdrParentSplitID, h.ParentSplitID)
size += proto.NestedStructureSize(ecHdrParentSplitParentID, h.ParentSplitParentID)
for i := range h.ParentAttributes {
size += proto.NestedStructureSize(ecHdrParentAttributes, &h.ParentAttributes[i])
}
return size
}
func (h *ECHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header_EC))
}
func (h *Header) StableMarshal(buf []byte) []byte {
if h == nil {
return []byte{}
@ -255,6 +321,7 @@ func (h *Header) StableMarshal(buf []byte) []byte {
}
proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split)
proto.NestedStructureMarshal(hdrECField, buf[offset:], h.ec)
return buf
}
@ -277,6 +344,7 @@ func (h *Header) StableSize() (size int) {
size += proto.NestedStructureSize(hdrAttributesField, &h.attr[i])
}
size += proto.NestedStructureSize(hdrSplitField, h.split)
size += proto.NestedStructureSize(hdrECField, h.ec)
return size
}
@ -322,6 +390,14 @@ func (o *Object) StableMarshal(buf []byte) []byte {
return []byte{}
}
if o.marshalData != nil {
if buf == nil {
return o.marshalData
}
copy(buf, o.marshalData)
return buf
}
if buf == nil {
buf = make([]byte, o.StableSize())
}
@ -336,6 +412,16 @@ func (o *Object) StableMarshal(buf []byte) []byte {
return buf
}
// SetMarshalData sets marshal data to reduce memory allocations.
//
// It is unsafe to modify/copy object data after setting marshal data.
func (o *Object) SetMarshalData(data []byte) {
if o == nil {
return
}
o.marshalData = data
}
func (o *Object) StableSize() (size int) {
if o == nil {
return 0
@ -387,6 +473,74 @@ func (s *SplitInfo) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(object.SplitInfo))
}
func (e *ECInfo) StableMarshal(buf []byte) []byte {
if e == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, e.StableSize())
}
var offset int
for i := range e.Chunks {
offset += proto.NestedStructureMarshal(ecInfoChunksField, buf[offset:], &e.Chunks[i])
}
return buf
}
func (e *ECInfo) StableSize() (size int) {
if e == nil {
return 0
}
for i := range e.Chunks {
size += proto.NestedStructureSize(ecInfoChunksField, &e.Chunks[i])
}
return size
}
func (e *ECInfo) Unmarshal(data []byte) error {
return message.Unmarshal(e, data, new(object.ECInfo))
}
func (c *ECChunk) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(ecChunkIDField, buf[offset:], &c.ID)
offset += proto.UInt32Marshal(ecChunkIndexField, buf[offset:], c.Index)
proto.UInt32Marshal(ecChunkTotalField, buf[offset:], c.Total)
return buf
}
func (c *ECChunk) StableSize() (size int) {
if c == nil {
return 0
}
size += proto.NestedStructureSize(ecChunkIDField, &c.ID)
size += proto.UInt32Size(ecChunkIndexField, c.Index)
size += proto.UInt32Size(ecChunkTotalField, c.Total)
return size
}
func (c *ECChunk) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(object.ECInfo_Chunk))
}
func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
@ -472,6 +626,8 @@ func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
}
case *SplitInfo:
proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v)
case *ECInfo:
proto.NestedStructureMarshal(getRespBodyECInfoField, buf, v)
default:
panic("unknown one of object get response body type")
}
@ -494,6 +650,8 @@ func (r *GetResponseBody) StableSize() (size int) {
}
case *SplitInfo:
size += proto.NestedStructureSize(getRespBodySplitInfoField, v)
case *ECInfo:
size += proto.NestedStructureSize(getRespBodyECInfoField, v)
default:
panic("unknown one of object get response body type")
}
@ -732,6 +890,10 @@ func (r *HeadResponseBody) StableMarshal(buf []byte) []byte {
if v != nil {
proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v)
}
case *ECInfo:
if v != nil {
proto.NestedStructureMarshal(headRespBodyECInfoField, buf, v)
}
default:
panic("unknown one of object put request body type")
}
@ -758,6 +920,10 @@ func (r *HeadResponseBody) StableSize() (size int) {
if v != nil {
size += proto.NestedStructureSize(headRespBodySplitInfoField, v)
}
case *ECInfo:
if v != nil {
size += proto.NestedStructureSize(headRespBodyECInfoField, v)
}
default:
panic("unknown one of object put request body type")
}
@ -958,6 +1124,10 @@ func (r *GetRangeResponseBody) StableMarshal(buf []byte) []byte {
if v != nil {
proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v)
}
case *ECInfo:
if v != nil {
proto.NestedStructureMarshal(getRangeRespECInfoField, buf, v)
}
default:
panic("unknown one of object get range request body type")
}
@ -980,6 +1150,10 @@ func (r *GetRangeResponseBody) StableSize() (size int) {
if v != nil {
size = proto.NestedStructureSize(getRangeRespSplitInfoField, v)
}
case *ECInfo:
if v != nil {
size = proto.NestedStructureSize(getRangeRespECInfoField, v)
}
default:
panic("unknown one of object get range request body type")
}
@ -1071,6 +1245,15 @@ func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if r.marshalData != nil {
if buf == nil {
return r.marshalData
}
copy(buf, r.marshalData)
return buf
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
@ -1082,6 +1265,19 @@ func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte {
return buf
}
// SetMarshalData sets marshal data to reduce memory allocations.
//
// It is unsafe to modify/copy request data after setting marshal data.
func (r *PutSingleRequestBody) SetMarshalData(data []byte) {
if r == nil {
return
}
r.marshalData = data
proto.NestedStructureSetMarshalData(putSingleReqObjectField, r.marshalData, r.object)
}
func (r *PutSingleRequestBody) StableSize() int {
if r == nil {
return 0

View file

@ -13,9 +13,12 @@ func TestMessageConvert(t *testing.T) {
func(empty bool) message.Message { return objecttest.GenerateShortHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateAttribute(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeaderWithSplitHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeaderWithECHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateECHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateObject(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) },
func(empty bool) message.Message { return objecttest.GenerateECInfo(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetObjectPartInit(empty) },

View file

@ -68,17 +68,42 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m.SetParentSignature(refstest.GenerateSignature(empty))
if withPar {
m.SetParentHeader(generateHeader(empty, false))
m.SetParentHeader(GenerateHeaderWithSplitHeader(empty))
}
return m
}
func GenerateHeader(empty bool) *object.Header {
return generateHeader(empty, true)
func GenerateHeaderWithSplitHeader(empty bool) *object.Header {
m := generateHeader(empty)
m.SetSplit(generateSplitHeader(empty, false))
return m
}
func generateHeader(empty, withSplit bool) *object.Header {
func GenerateHeaderWithECHeader(empty bool) *object.Header {
m := generateHeader(empty)
m.SetEC(GenerateECHeader(empty))
return m
}
func GenerateECHeader(empty bool) *object.ECHeader {
ech := new(object.ECHeader)
if !empty {
ech.Parent = refstest.GenerateObjectID(empty)
ech.ParentSplitID = []byte{1, 2, 3}
ech.ParentSplitParentID = refstest.GenerateObjectID(empty)
ech.ParentAttributes = GenerateAttributes(empty)
ech.Index = 0
ech.Total = 2
ech.Header = []byte("chunk of ec-encoded parent header")
ech.HeaderLength = uint32(2 * len(ech.Header))
}
return ech
}
func generateHeader(empty bool) *object.Header {
m := new(object.Header)
if !empty {
@ -95,10 +120,6 @@ func generateHeader(empty, withSplit bool) *object.Header {
m.SetHomomorphicHash(refstest.GenerateChecksum(empty))
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
if withSplit {
m.SetSplit(generateSplitHeader(empty, false))
}
return m
}
@ -106,7 +127,7 @@ func GenerateHeaderWithSignature(empty bool) *object.HeaderWithSignature {
m := new(object.HeaderWithSignature)
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -120,7 +141,7 @@ func GenerateObject(empty bool) *object.Object {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -137,6 +158,31 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
return m
}
func GenerateECInfo(empty bool) *object.ECInfo {
m := new(object.ECInfo)
if !empty {
m.Chunks = make([]object.ECChunk, 2)
for i := range m.Chunks {
m.Chunks[i] = *GenerateECChunk(false)
}
}
return m
}
func GenerateECChunk(empty bool) *object.ECChunk {
m := new(object.ECChunk)
if !empty {
m.ID = *refstest.GenerateObjectID(false)
m.Index = 4
m.Total = 7
}
return m
}
func GenerateGetRequestBody(empty bool) *object.GetRequestBody {
m := new(object.GetRequestBody)
@ -169,7 +215,7 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -223,7 +269,7 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}

View file

@ -39,6 +39,17 @@ type SplitHeader struct {
splitID []byte
}
type ECHeader struct {
Parent *refs.ObjectID
ParentSplitID []byte
ParentSplitParentID *refs.ObjectID
ParentAttributes []Attribute
Index uint32
Total uint32
Header []byte
HeaderLength uint32
}
type Header struct {
version *refs.Version
@ -59,6 +70,8 @@ type Header struct {
attr []Attribute
split *SplitHeader
ec *ECHeader
}
type HeaderWithSignature struct {
@ -75,6 +88,9 @@ type Object struct {
header *Header
payload []byte
// marshalData holds marshaled data, must not be marshaled by StableMarshal
marshalData []byte
}
type SplitInfo struct {
@ -85,6 +101,16 @@ type SplitInfo struct {
link *refs.ObjectID
}
type ECChunk struct {
ID refs.ObjectID
Index uint32
Total uint32
}
type ECInfo struct {
Chunks []ECChunk
}
type GetRequestBody struct {
addr *refs.Address
@ -304,6 +330,9 @@ type GetRangeHashResponse struct {
type PutSingleRequestBody struct {
object *Object
copyNum []uint32
// marshalData holds marshaled data, must not be marshaled by StableMarshal
marshalData []byte
}
type PutSingleRequest struct {
@ -312,8 +341,7 @@ type PutSingleRequest struct {
session.RequestHeaders
}
type PutSingleResponseBody struct {
}
type PutSingleResponseBody struct{}
type PutSingleResponse struct {
body *PutSingleResponseBody
@ -650,6 +678,17 @@ func (h *Header) SetSplit(v *SplitHeader) {
h.split = v
}
func (h *Header) GetEC() *ECHeader {
if h != nil {
return h.ec
}
return nil
}
func (h *Header) SetEC(v *ECHeader) {
h.ec = v
}
func (h *HeaderWithSignature) GetHeader() *Header {
if h != nil {
return h.header
@ -1471,3 +1510,9 @@ func (r *PutSingleResponse) GetBody() *PutSingleResponseBody {
func (r *PutSingleResponse) SetBody(v *PutSingleResponseBody) {
r.body = v
}
func (s *ECInfo) getObjectPart() {}
func (s *ECInfo) getHeaderPart() {}
func (s *ECInfo) getRangePart() {}

View file

@ -196,7 +196,7 @@ func (c *Checksum) ToGRPCMessage() grpc.Message {
if c != nil {
m = new(refs.Checksum)
m.SetChecksumType(ChecksumTypeToGRPC(c.typ))
m.SetType(ChecksumTypeToGRPC(c.typ))
m.SetSum(c.sum)
}

View file

@ -25,8 +25,8 @@ func (x *Address) SetObjectId(v *ObjectID) {
x.ObjectId = v
}
// SetChecksumType in generic checksum structure.
func (x *Checksum) SetChecksumType(v ChecksumType) {
// SetType in generic checksum structure.
func (x *Checksum) SetType(v ChecksumType) {
x.Type = v
}

BIN
refs/grpc/types.pb.go generated

Binary file not shown.

60
rpc/apemanager.go Normal file
View file

@ -0,0 +1,60 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
)
const serviceAPEManager = frostfsServiceNamePrefix + "apemanager.APEManagerService"
const (
rpcAPEManagerAddChain = "AddChain"
rpcAPEManagerRemoveChain = "RemoveChain"
rpcAPEManagerListChains = "ListChains"
)
func AddChain(
cli *client.Client,
req *apemanager.AddChainRequest,
opts ...client.CallOption,
) (*apemanager.AddChainResponse, error) {
resp := new(apemanager.AddChainResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerAddChain), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func RemoveChain(
cli *client.Client,
req *apemanager.RemoveChainRequest,
opts ...client.CallOption,
) (*apemanager.RemoveChainResponse, error) {
resp := new(apemanager.RemoveChainResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerRemoveChain), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func ListChains(
cli *client.Client,
req *apemanager.ListChainsRequest,
opts ...client.CallOption,
) (*apemanager.ListChainsResponse, error) {
resp := new(apemanager.ListChainsResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerListChains), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}

View file

@ -1,3 +1,10 @@
package rpc
const serviceNamePrefix = "neo.fs.v2."
const (
// serviceNamePrefix is still used in "old" services but should be
// considered as deprecated. Since new services use "frostfs" root,
// `frostfsServiceNamePrefix` must be used for their rpc interface.
serviceNamePrefix = "neo.fs.v2."
frostfsServiceNamePrefix = "frostfs.v2."
)

View file

@ -383,7 +383,7 @@ func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message {
m.SetEpoch(r.epoch)
m.SetTtl(r.ttl)
m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader))
m.SetNetworkMagic(r.netMagic)
m.SetMagicNumber(r.netMagic)
}
return m
@ -674,7 +674,10 @@ func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message {
m = new(session.ObjectSessionContext)
m.SetVerb(ObjectSessionVerbToGRPCField(c.verb))
m.SetTarget(c.cnr.ToGRPCMessage().(*refsGRPC.ContainerID), refs.ObjectIDListToGRPCMessage(c.objs))
m.SetTarget(&session.ObjectSessionContext_Target{
Container: c.cnr.ToGRPCMessage().(*refsGRPC.ContainerID),
Objects: refs.ObjectIDListToGRPCMessage(c.objs),
})
}
return m
@ -724,9 +727,9 @@ func (t *TokenBody) ToGRPCMessage() grpc.Message {
case nil:
m.Context = nil
case *ObjectSessionContext:
m.SetObjectSessionContext(typ.ToGRPCMessage().(*session.ObjectSessionContext))
m.SetObject(typ.ToGRPCMessage().(*session.ObjectSessionContext))
case *ContainerSessionContext:
m.SetContainerSessionContext(typ.ToGRPCMessage().(*session.ContainerSessionContext))
m.SetContainer(typ.ToGRPCMessage().(*session.ContainerSessionContext))
}
m.SetOwnerId(t.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))

Binary file not shown.

Binary file not shown.

View file

@ -52,25 +52,22 @@ func (m *SessionToken_Body) SetSessionKey(v []byte) {
}
// SetObjectAddressContext sets object context of the session token.
func (m *SessionToken_Body) SetObjectSessionContext(v *ObjectSessionContext) {
func (m *SessionToken_Body) SetObject(v *ObjectSessionContext) {
m.Context = &SessionToken_Body_Object{
Object: v,
}
}
// SetContainerSessionContext sets container context of the session token.
func (m *SessionToken_Body) SetContainerSessionContext(v *ContainerSessionContext) {
// SetContainer sets container context of the session token.
func (m *SessionToken_Body) SetContainer(v *ContainerSessionContext) {
m.Context = &SessionToken_Body_Container{
Container: v,
}
}
// SetTarget specifies objects involved in the object session.
func (m *ObjectSessionContext) SetTarget(cnr *refs.ContainerID, objs []*refs.ObjectID) {
m.Target = &ObjectSessionContext_Target{
Container: cnr,
Objects: objs,
}
func (m *ObjectSessionContext) SetTarget(tgt *ObjectSessionContext_Target) {
m.Target = tgt
}
// SetVerb sets type of request for which the token is issued.
@ -147,8 +144,8 @@ func (m *RequestMetaHeader) GetNetworkMagic() uint64 {
return 0
}
// SetNetworkMagic sets NeoFS network magic.
func (m *RequestMetaHeader) SetNetworkMagic(v uint64) {
// SetMagicNumber sets NeoFS network magic.
func (m *RequestMetaHeader) SetMagicNumber(v uint64) {
m.MagicNumber = v
}

BIN
session/grpc/types.pb.go generated

Binary file not shown.

View file

@ -3,7 +3,6 @@ package session
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
func (c *ObjectSessionContext) MarshalJSON() ([]byte, error) {
@ -27,13 +26,7 @@ func (t *TokenBody) MarshalJSON() ([]byte, error) {
}
func (t *TokenBody) UnmarshalJSON(data []byte) error {
msg := new(session.SessionToken_Body)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return t.FromGRPCMessage(msg)
return message.UnmarshalJSON(t, data, new(session.SessionToken_Body))
}
func (t *Token) MarshalJSON() ([]byte, error) {
@ -41,13 +34,7 @@ func (t *Token) MarshalJSON() ([]byte, error) {
}
func (t *Token) UnmarshalJSON(data []byte) error {
msg := new(session.SessionToken)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return t.FromGRPCMessage(msg)
return message.UnmarshalJSON(t, data, new(session.SessionToken))
}
func (x *XHeader) MarshalJSON() ([]byte, error) {
@ -55,13 +42,7 @@ func (x *XHeader) MarshalJSON() ([]byte, error) {
}
func (x *XHeader) UnmarshalJSON(data []byte) error {
msg := new(session.XHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return x.FromGRPCMessage(msg)
return message.UnmarshalJSON(x, data, new(session.XHeader))
}
func (r *RequestMetaHeader) MarshalJSON() ([]byte, error) {
@ -69,13 +50,7 @@ func (r *RequestMetaHeader) MarshalJSON() ([]byte, error) {
}
func (r *RequestMetaHeader) UnmarshalJSON(data []byte) error {
msg := new(session.RequestMetaHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return r.FromGRPCMessage(msg)
return message.UnmarshalJSON(r, data, new(session.RequestMetaHeader))
}
func (r *RequestVerificationHeader) MarshalJSON() ([]byte, error) {
@ -83,13 +58,7 @@ func (r *RequestVerificationHeader) MarshalJSON() ([]byte, error) {
}
func (r *RequestVerificationHeader) UnmarshalJSON(data []byte) error {
msg := new(session.RequestVerificationHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return r.FromGRPCMessage(msg)
return message.UnmarshalJSON(r, data, new(session.RequestVerificationHeader))
}
func (r *ResponseMetaHeader) MarshalJSON() ([]byte, error) {
@ -97,13 +66,7 @@ func (r *ResponseMetaHeader) MarshalJSON() ([]byte, error) {
}
func (r *ResponseMetaHeader) UnmarshalJSON(data []byte) error {
msg := new(session.ResponseMetaHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return r.FromGRPCMessage(msg)
return message.UnmarshalJSON(r, data, new(session.ResponseMetaHeader))
}
func (r *ResponseVerificationHeader) MarshalJSON() ([]byte, error) {
@ -111,13 +74,7 @@ func (r *ResponseVerificationHeader) MarshalJSON() ([]byte, error) {
}
func (r *ResponseVerificationHeader) UnmarshalJSON(data []byte) error {
msg := new(session.ResponseVerificationHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
return r.FromGRPCMessage(msg)
return message.UnmarshalJSON(r, data, new(session.ResponseVerificationHeader))
}
func (x *ContainerSessionContext) MarshalJSON() ([]byte, error) {

View file

@ -4,7 +4,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
goproto "google.golang.org/protobuf/proto"
)
const (
@ -154,12 +153,7 @@ func (x *XHeader) StableSize() (size int) {
}
func (x *XHeader) Unmarshal(data []byte) error {
m := new(session.XHeader)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return x.FromGRPCMessage(m)
return message.Unmarshal(x, data, new(session.XHeader))
}
func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
@ -193,12 +187,7 @@ func (l *TokenLifetime) StableSize() (size int) {
}
func (l *TokenLifetime) Unmarshal(data []byte) error {
m := new(session.SessionToken_Body_TokenLifetime)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return l.FromGRPCMessage(m)
return message.Unmarshal(l, data, new(session.SessionToken_Body_TokenLifetime))
}
func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
@ -211,7 +200,7 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
}
offset := proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb))
proto.NestedStructureMarshal(objectCtxTargetField, buf[offset:], objectSessionContextTarget{
proto.NestedStructureMarshalUnchecked(objectCtxTargetField, buf[offset:], objectSessionContextTarget{
cnr: c.cnr,
objs: c.objs,
})
@ -225,7 +214,7 @@ func (c *ObjectSessionContext) StableSize() (size int) {
}
size += proto.EnumSize(objectCtxVerbField, int32(c.verb))
size += proto.NestedStructureSize(objectCtxTargetField, objectSessionContextTarget{
size += proto.NestedStructureSizeUnchecked(objectCtxTargetField, objectSessionContextTarget{
cnr: c.cnr,
objs: c.objs,
})
@ -234,12 +223,7 @@ func (c *ObjectSessionContext) StableSize() (size int) {
}
func (c *ObjectSessionContext) Unmarshal(data []byte) error {
m := new(session.ObjectSessionContext)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return c.FromGRPCMessage(m)
return message.Unmarshal(c, data, new(session.ObjectSessionContext))
}
const (
@ -338,12 +322,7 @@ func (t *TokenBody) StableSize() (size int) {
}
func (t *TokenBody) Unmarshal(data []byte) error {
m := new(session.SessionToken_Body)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return t.FromGRPCMessage(m)
return message.Unmarshal(t, data, new(session.SessionToken_Body))
}
func (t *Token) StableMarshal(buf []byte) []byte {
@ -375,12 +354,7 @@ func (t *Token) StableSize() (size int) {
}
func (t *Token) Unmarshal(data []byte) error {
m := new(session.SessionToken)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return t.FromGRPCMessage(m)
return message.Unmarshal(t, data, new(session.SessionToken))
}
func (r *RequestMetaHeader) StableMarshal(buf []byte) []byte {
@ -435,12 +409,7 @@ func (r *RequestMetaHeader) StableSize() (size int) {
}
func (r *RequestMetaHeader) Unmarshal(data []byte) error {
m := new(session.RequestMetaHeader)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return r.FromGRPCMessage(m)
return message.Unmarshal(r, data, new(session.RequestMetaHeader))
}
func (r *RequestVerificationHeader) StableMarshal(buf []byte) []byte {
@ -476,12 +445,7 @@ func (r *RequestVerificationHeader) StableSize() (size int) {
}
func (r *RequestVerificationHeader) Unmarshal(data []byte) error {
m := new(session.RequestVerificationHeader)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return r.FromGRPCMessage(m)
return message.Unmarshal(r, data, new(session.RequestVerificationHeader))
}
func (r *ResponseMetaHeader) StableMarshal(buf []byte) []byte {
@ -532,12 +496,7 @@ func (r *ResponseMetaHeader) StableSize() (size int) {
}
func (r *ResponseMetaHeader) Unmarshal(data []byte) error {
m := new(session.ResponseMetaHeader)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return r.FromGRPCMessage(m)
return message.Unmarshal(r, data, new(session.ResponseMetaHeader))
}
func (r *ResponseVerificationHeader) StableMarshal(buf []byte) []byte {
@ -573,10 +532,5 @@ func (r *ResponseVerificationHeader) StableSize() (size int) {
}
func (r *ResponseVerificationHeader) Unmarshal(data []byte) error {
m := new(session.ResponseVerificationHeader)
if err := goproto.Unmarshal(data, m); err != nil {
return err
}
return r.FromGRPCMessage(m)
return message.Unmarshal(r, data, new(session.ResponseVerificationHeader))
}

View file

@ -632,7 +632,8 @@ func (r *ResponseMetaHeader) SetStatus(v *status.Status) {
func SetStatus(msg interface {
GetMetaHeader() *ResponseMetaHeader
SetMetaHeader(*ResponseMetaHeader)
}, st *status.Status) {
}, st *status.Status,
) {
meta := msg.GetMetaHeader()
if meta == nil {
meta = new(ResponseMetaHeader)

View file

@ -43,7 +43,8 @@ func (c *RequestHeaders) SetVerificationHeader(v *RequestVerificationHeader) {
func (c *RequestHeaders) ToMessage(m interface {
SetMetaHeader(*session.RequestMetaHeader)
SetVerifyHeader(*session.RequestVerificationHeader)
}) {
},
) {
m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.RequestMetaHeader))
m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.RequestVerificationHeader))
}
@ -51,7 +52,8 @@ func (c *RequestHeaders) ToMessage(m interface {
func (c *RequestHeaders) FromMessage(m interface {
GetMetaHeader() *session.RequestMetaHeader
GetVerifyHeader() *session.RequestVerificationHeader
}) error {
},
) error {
metaHdr := m.GetMetaHeader()
if metaHdr == nil {
c.metaHeader = nil
@ -122,7 +124,8 @@ func (c *ResponseHeaders) SetVerificationHeader(v *ResponseVerificationHeader) {
func (c *ResponseHeaders) ToMessage(m interface {
SetMetaHeader(*session.ResponseMetaHeader)
SetVerifyHeader(*session.ResponseVerificationHeader)
}) {
},
) {
m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.ResponseMetaHeader))
m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.ResponseVerificationHeader))
}
@ -130,7 +133,8 @@ func (c *ResponseHeaders) ToMessage(m interface {
func (c *ResponseHeaders) FromMessage(m interface {
GetMetaHeader() *session.ResponseMetaHeader
GetVerifyHeader() *session.ResponseVerificationHeader
}) error {
},
) error {
metaHdr := m.GetMetaHeader()
if metaHdr == nil {
c.metaHeader = nil

View file

@ -4,6 +4,7 @@ import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
@ -105,5 +106,19 @@ func serviceMessageBody(req any) stableMarshaler {
return v.GetBody()
case *netmap.SnapshotResponse:
return v.GetBody()
/* APEManager */
case *apemanager.AddChainRequest:
return v.GetBody()
case *apemanager.AddChainResponse:
return v.GetBody()
case *apemanager.RemoveChainRequest:
return v.GetBody()
case *apemanager.RemoveChainResponse:
return v.GetBody()
case *apemanager.ListChainsRequest:
return v.GetBody()
case *apemanager.ListChainsResponse:
return v.GetBody()
}
}

BIN
status/grpc/types.pb.go generated

Binary file not shown.

Binary file not shown.

54
util/pool/buffer.go Normal file
View file

@ -0,0 +1,54 @@
package pool
import (
"sync"
)
// Buffer contains a byte slice.
type Buffer struct {
Data []byte
}
// BufferPool manages a pool of Buffers.
type BufferPool struct {
poolSliceSize uint32 // Size for the buffer slices in the pool.
buffersPool *sync.Pool
}
// NewBufferPool creates a BufferPool with a specified size.
func NewBufferPool(poolSliceSize uint32) BufferPool {
pool := sync.Pool{
New: func() any {
return new(Buffer)
},
}
return BufferPool{poolSliceSize: poolSliceSize, buffersPool: &pool}
}
// Get retrieves a Buffer from the pool or creates a new one if necessary.
// It ensures the buffer's capacity is at least the specified size.
func (pool BufferPool) Get(size uint32) *Buffer {
result := pool.buffersPool.Get().(*Buffer)
if cap(result.Data) < int(size) {
result.Data = make([]byte, size)
} else {
result.Data = result.Data[:size]
}
return result
}
// Put returns a Buffer to the pool if its capacity does not exceed poolSliceSize.
func (pool BufferPool) Put(buf *Buffer) {
if cap(buf.Data) > int(pool.poolSliceSize) {
return
}
buf.Data = buf.Data[:0]
pool.buffersPool.Put(buf)
}
// PoolSliceSize returns the size for buffer slices in the pool.
func (pool BufferPool) PoolSliceSize() uint32 {
return uint32(pool.poolSliceSize)
}

View file

@ -15,10 +15,16 @@ import (
)
type (
stableMarshaller interface {
stableMarshaler interface {
StableMarshal([]byte) []byte
StableSize() int
}
setMarshalData[T any] interface {
SetMarshalData([]byte)
StableSize() int
~*T
}
)
func BytesMarshal(field int, buf, v []byte) int {
@ -249,12 +255,21 @@ func VarUIntSize(x uint64) int {
return (bits.Len64(x|1) + 6) / 7
}
func NestedStructureMarshal[T stableMarshaller](field int64, buf []byte, v T) int {
n := v.StableSize()
if n == 0 {
type ptrStableMarshaler[T any] interface {
stableMarshaler
~*T
}
func NestedStructureMarshal[T any, M ptrStableMarshaler[T]](field int64, buf []byte, v M) int {
if v == nil {
return 0
}
return NestedStructureMarshalUnchecked(field, buf, v)
}
func NestedStructureMarshalUnchecked[T stableMarshaler](field int64, buf []byte, v T) int {
n := v.StableSize()
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType)
offset := binary.PutUvarint(buf, prefix)
offset += binary.PutUvarint(buf[offset:], uint64(n))
@ -263,13 +278,42 @@ func NestedStructureMarshal[T stableMarshaller](field int64, buf []byte, v T) in
return offset + n
}
func NestedStructureSize[T stableMarshaller](field int64, v T) (size int) {
n := v.StableSize()
if n == 0 {
// NestedStructureSetMarshalData calculates offset for field in parentData
// and calls SetMarshalData for nested structure.
//
// Returns marshalled data length of nested structure.
func NestedStructureSetMarshalData[T any, M setMarshalData[T]](field int64, parentData []byte, v M) int {
if v == nil {
return 0
}
size = protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(n))
return
if parentData == nil {
v.SetMarshalData(nil)
return 0
}
n := v.StableSize()
buf := make([]byte, binary.MaxVarintLen64)
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType)
offset := binary.PutUvarint(buf, prefix)
offset += binary.PutUvarint(buf, uint64(n))
v.SetMarshalData(parentData[offset : offset+n])
return offset + n
}
func NestedStructureSize[T any, M ptrStableMarshaler[T]](field int64, v M) (size int) {
if v == nil {
return 0
}
return NestedStructureSizeUnchecked(field, v)
}
func NestedStructureSizeUnchecked[T stableMarshaler](field int64, v T) int {
n := v.StableSize()
return protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(n))
}
func Fixed64Marshal(field int, buf []byte, v uint64) int {

View file

@ -50,9 +50,7 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
buf = make([]byte, s.stableSize())
}
var (
i, offset, fieldNum int
)
var i, offset, fieldNum int
fieldNum = 1
if wrongField {

Binary file not shown.

View file

@ -205,22 +205,22 @@ type marshalerDesc struct {
var marshalers = map[protoreflect.Kind]marshalerDesc{
protoreflect.BoolKind: {Prefix: "Bool"},
protoreflect.EnumKind: {Prefix: "Enum"},
//protoreflect.Int32Kind: "",
//protoreflect.Sint32Kind: "",
// protoreflect.Int32Kind: "",
// protoreflect.Sint32Kind: "",
protoreflect.Uint32Kind: {Prefix: "UInt32", RepeatedDouble: true},
protoreflect.Int64Kind: {Prefix: "Int64", RepeatedDouble: true},
//protoreflect.Sint64Kind: "",
// protoreflect.Sint64Kind: "",
protoreflect.Uint64Kind: {Prefix: "UInt64", RepeatedDouble: true},
//protoreflect.Sfixed32Kind: "",
// protoreflect.Sfixed32Kind: "",
protoreflect.Fixed32Kind: {Prefix: "Fixed32", RepeatedDouble: true},
//protoreflect.FloatKind: "",
//protoreflect.Sfixed64Kind: "",
// protoreflect.FloatKind: "",
// protoreflect.Sfixed64Kind: "",
protoreflect.Fixed64Kind: {Prefix: "Fixed64", RepeatedDouble: true},
protoreflect.DoubleKind: {Prefix: "Float64"},
protoreflect.StringKind: {Prefix: "String"},
protoreflect.BytesKind: {Prefix: "Bytes"},
protoreflect.MessageKind: {Prefix: "NestedStructure"},
//protoreflect.GroupKind: "",
// protoreflect.GroupKind: "",
}
func sortFields(fs []*protogen.Field) []*protogen.Field {

View file

@ -1,33 +0,0 @@
package signature
import "sync"
const poolSliceMaxSize = 128 * 1024
type buffer struct {
data []byte
}
var buffersPool = sync.Pool{
New: func() any {
return new(buffer)
},
}
func newBufferFromPool(size int) *buffer {
result := buffersPool.Get().(*buffer)
if cap(result.data) < size {
result.data = make([]byte, size)
} else {
result.data = result.data[:size]
}
return result
}
func returnBufferToPool(buf *buffer) {
if cap(buf.data) > poolSliceMaxSize {
return
}
buf.data = buf.data[:0]
buffersPool.Put(buf)
}

View file

@ -4,9 +4,14 @@ import (
"crypto/ecdsa"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/pool"
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
)
const poolSliceMaxSize = 128 * 1024
var buffersPool = pool.NewBufferPool(poolSliceMaxSize)
type DataSource interface {
ReadSignedData([]byte) ([]byte, error)
SignedDataSize() int
@ -35,10 +40,10 @@ func SignDataWithHandler(key *ecdsa.PrivateKey, src DataSource, handler KeySigna
opts[i](cfg)
}
buffer := newBufferFromPool(src.SignedDataSize())
defer returnBufferToPool(buffer)
buffer := buffersPool.Get(uint32(src.SignedDataSize()))
defer buffersPool.Put(buffer)
data, err := src.ReadSignedData(buffer.data)
data, err := src.ReadSignedData(buffer.Data)
if err != nil {
return err
}
@ -64,10 +69,10 @@ func VerifyDataWithSource(dataSrc DataSource, sigSrc KeySignatureSource, opts ..
opts[i](cfg)
}
buffer := newBufferFromPool(dataSrc.SignedDataSize())
defer returnBufferToPool(buffer)
buffer := buffersPool.Get(uint32(dataSrc.SignedDataSize()))
defer buffersPool.Put(buffer)
data, err := dataSrc.ReadSignedData(buffer.data)
data, err := dataSrc.ReadSignedData(buffer.Data)
if err != nil {
return err
}

View file

@ -35,10 +35,10 @@ func verify(cfg *cfg, data []byte, sig *refs.Signature) error {
case refs.ECDSA_RFC6979_SHA256:
return crypto.VerifyRFC6979(pub, data, sig.GetSign())
case refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT:
buffer := newBufferFromPool(base64.StdEncoding.EncodedLen(len(data)))
defer returnBufferToPool(buffer)
base64.StdEncoding.Encode(buffer.data, data)
if !walletconnect.Verify(pub, buffer.data, sig.GetSign()) {
buffer := buffersPool.Get(uint32(base64.StdEncoding.EncodedLen(len(data))))
defer buffersPool.Put(buffer)
base64.StdEncoding.Encode(buffer.Data, data)
if !walletconnect.Verify(pub, buffer.Data, sig.GetSign()) {
return crypto.ErrInvalidSignature
}
return nil
@ -54,10 +54,10 @@ func sign(cfg *cfg, key *ecdsa.PrivateKey, data []byte) ([]byte, error) {
case refs.ECDSA_RFC6979_SHA256:
return crypto.SignRFC6979(key, data)
case refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT:
buffer := newBufferFromPool(base64.StdEncoding.EncodedLen(len(data)))
defer returnBufferToPool(buffer)
base64.StdEncoding.Encode(buffer.data, data)
return walletconnect.Sign(key, buffer.data)
buffer := buffersPool.Get(uint32(base64.StdEncoding.EncodedLen(len(data))))
defer buffersPool.Put(buffer)
base64.StdEncoding.Encode(buffer.Data, data)
return walletconnect.Sign(key, buffer.Data)
default:
panic(fmt.Sprintf("unsupported scheme %s", cfg.scheme))
}

View file

@ -109,5 +109,4 @@ func TestVerifyNeonWallet(t *testing.T) {
}
require.True(t, VerifyMessage(nil, sm))
}
}