Commit graph

270 commits

Author SHA1 Message Date
Leonard Lyubich
89be8d3f5a [#196] pkg/client: Extend Client interface with Conn method
Add `Conn` method to `Client` interface which must return the underlying
connection. Implement new method on the core structure. `Conn` can be used
to control the connection (e.g. for closing).

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-31 10:13:00 +03:00
Leonard Lyubich
6cd3497388 [#283] pkg/session: Implement work with token contexts
Implement `Context` / `SetContext` methods on `Token` which reads / sets
token context. Support container context (`ContainerContext`).

Add helper function `GetContainerContext` for easy reading of the container
context.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
2648abb49e [#283] pkg/session: Add container context generator
Implement `sessiontest.ContainerContext` function for testing.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
1d8207ae19 [#283] pkg/session: Implement container session context
Define `ContainerContext` type for container sessions. Implement basic
functionality to work with its data.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
fb0b1ea108 [#283] pkg/session: Cover Token's Sign/Verify methods with unit test
Add `sessiontest.GenerateSigned` function which returns signed random token.
Clarify that `sessiontest.Generate` returns an unsigned token. Use these
functions to assert the correctness of `Sign` / `VerifySignature` methods.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
05e74d56db [#283] pkg/session: Implement Sign/Verify methods on Token
Implement `Token.Sign` method which calculates signature of the data of the
`Token` and writes the signature into it. Implement `Token.VerifySignature`
which checks if `Token` signature is presented and valid. These methods
allow to abstract the external context from the details of what kind of data
is being signed and how the signature is stored.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
5fe5af5bf9 [#283] pkg/owner: Implement Equal method of ID type
Implement `owner.ID.Equal` method which defines a comparison relationship
between two identifiers.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
4f286f5175 [#283] pkg/owner: Implement generators of ID's for testing
Create `ownertest` package with functions which generate random `owner.ID`
instances. These functions is going to be used for testing.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
48837bd5da [#288] pkg/eacl: Fix conversion of slices in Table.ToV2 method
Nil slice of records of the `Table` should be converted to nil slice in
corresponding field of API v2 message structure.

Add nil-check in `Table.ToV2` implementation. The changes fix corresponding
unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
fc4f7429d5 [#288] pkg/eacl: Document default values set in NewTable
Document field values of instance constructed via `NewTable`. Assert the
values in corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
8abf78009a [#288] pkg/eacl: Convert nil eACL table to nil API v2 message
Make `Table.ToV2` method to return `nil` when called on `nil`. Write
corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
8c70b4714e [#288] pkg/eacl: Fix conversion of slices in Record.ToV2 method
Nil slices of targets and filters of the `Record` should be converted to nil
slices in corresponding fields of API v2 message structure.

Add nil-check in `Record.ToV2` implementation. The changes fix corresponding
unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
374c37983d [#288] pkg/eacl: Document default values set in NewRecord
Document field values of instance constructed via `NewRecord`. Assert the
values in corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
18a3c4d54f [#288] pkg/eacl: Convert nil eACL record to nil API v2 message
Make `Record.ToV2` method to return `nil` when called on `nil`. Write
corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
b81f39368e [#288] pkg/eacl: Document default values set in NewTarget
Document field values of instance constructed via `NewTarget`. Assert the
values in corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
5844096017 [#288] pkg/eacl: Convert nil eACL target to nil API v2 message
Make `Target.ToV2` method to return `nil` when called on `nil`. Write
corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
8f27d857fa [#288] pkg/eacl: Document default values set in NewFilter
Document field values of instance constructed via `NewFilter`. Assert the
values in corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
89cb2f6e71 [#288] pkg/eacl: Convert nil eACL filter to nil message
Make `Filter.ToV2` method to return `nil` when called on `nil`. Write
corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 09:37:21 +03:00
Leonard Lyubich
25de451a2f [#283] client/container: Write new fields to eACL table in GetEACL
Call `SetSessionToken` and `SetSignature` methods on resulting eACL table
with items from response body. From now eACL signature can be accessed from
the table itself, so `EACLWithSignature.Signature` is marked deprecated.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
ad6b5aa8a9 [#283] client/container: Attach container session token to request
Write session token of `container.Container` to container SetExtendedACL
request body inside `client.SetEACL` call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
396210409d [#283] client/container: Write new fields to container in GetContainer
Call `SetSessionToken` and `SetSignature` methods on resulting container
with items from response body.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
ddccfe0072 [#283] client/container: Attach container session token to request
Write session token of `container.Container` to container PUT request body
during `client.PutContainer` call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
0719fcef59 [#283] pkg/container: Add session token and signature to Table
Extended ACL table can be set within a session, and should be signed.

Add `SessionToken` / `SetSessionToken` (`Signature` / `SetSignature`)
methods to carry session token (signature) in `Table` structure.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
37b415347d [#283] pkg/token: Replace SessionToken into a session package
There is a need to add session token to `eacl.Table` structure. To do this,
we need to replace `token.SessionToken` type to another package since `eacl`
package imports `token` one (potential cross-import).

Create `pkg/session` package and replace session token implementation to it.
Related API in `container` package is deprecated from now.

Additionally implement test generator of random session tokens.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
fcbe0bbd2e [#283] pkg/container: Add session token and signature to Container
Container can be created within a session, and should be signed.

Add `SessionToken` / `SetSessionToken` (`Signature` / `SetSignature`)
methods to carry session token (signature) in `Container` structure.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
f60f7e0cdb [#283] pkg/eacl: Remove usage of deprecated container ID from src files
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Leonard Lyubich
7314038069 [#283] pkg/container: Define ID in a separate package
In order to prevent potential cross imports, container ID should be defined
in a separate package as a base type. A similar approach was used in the
NeoFS API design.

Create `pkg/container/id` package and replace container ID implementation to
it. Related API in `container` package is deprecated from now.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00
Pavel Karpy
2ebb91cb4c [#286] client: Delete useless raw client init
Since raw client initialization is
postponed until the first `Raw()` function
call, there is no need to init empty(
without options) raw client in constructor.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-05-24 16:56:59 +03:00
Pavel Karpy
89aede1fb3 [#286] client: Add TLS options
Add `WithTLSConfig` option to client.
If it is not nil then client will
try to open secured connection.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-05-24 16:56:59 +03:00
Evgenii Stratonikov
9ddfcdfbba [#277] go.mod: remove pkg/errors
Use stdlib `errors` instead.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-05-19 11:14:56 +03:00
Alex Vanin
2e9db28f1c Bump version in pkg
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-05-07 15:11:18 +03:00
Alex Vanin
099347d3bc Synchronize namings with NeoFS API v2.6.0
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-05-07 15:11:18 +03:00
Leonard Lyubich
fcb2cce8a0 [#278] pkg/client: Fix payload slice allocation in Object Range method
Allocate capacity instead of length of the slice to write the object payload
range since each chunk is written through `append`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-30 11:15:35 +03:00
Pavel Karpy
0f7a14a69f [#274] pkg/client: Add epoch field to SendIntermediateTrustPrm
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-04-22 13:37:07 +03:00
Alex Vanin
5a507e0d1b [#273] Add go1.16 tests and fix linter error
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-04-16 16:32:14 +03:00
Leonard Lyubich
8128d598d0 [#265] pkg/client: Change trust type in SendIntermediateTrustPrm
Change accepted/returned value type of `SetTrust` / `Trust` methods of
`SendIntermediateTrustPrm` structure to `reputation.PeerToPeerTrust`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-09 11:57:42 +03:00
Leonard Lyubich
a61c15b990 [#265] pkg/reputation: Implement PeerToPeerTrust structure
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-09 11:57:42 +03:00
Leonard Lyubich
771f395d9d [#265] pkg/reputation: Implement GlobalTrust type
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-02 15:57:59 +03:00
Leonard Lyubich
05a351d344 [#265] pkg/reputation: Change PeerID implementation
Make `PeerID` type to be the wrapper over v2 `PeerID` message structure.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-02 15:57:59 +03:00
Leonard Lyubich
c5000a3334 [#265] pkg/client: Extend Client with SendIntermediateTrust method
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-04-02 15:57:59 +03:00
Leonard Lyubich
b792e4e464 [#265] pkg/client: Implement SendLocalTrust method
Define `Reputation` section interface. Embed `Reputation` interface to
`Client` one.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-25 11:20:34 +03:00
Leonard Lyubich
009f704377 [#265] pkg/reputation: Implement PeerID and Trust types
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-25 11:20:34 +03:00
Leonard Lyubich
2fcb6d9613 [#267] pkg: Fix IsSupportedVersion implementation
Current API library supports versions up to 2.4.x.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 14:30:02 +03:00
Leonard Lyubich
7cb9b8f283 [#267] pkg/client: Extend Client interface with Raw method
Add `Client.Raw` method which returns underlying raw protobuf client.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 14:30:02 +03:00
Leonard Lyubich
a43175e2ea [#263] pkg/client: Split interface method's declarations with linebreaks
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 14:03:49 +03:00
Leonard Lyubich
c819909906 [#263] pkg/client: Refactor the client to use raw protobuf client
Make `Client` to be the wrapper over raw protobuf client. Provide public
method to get the underlying raw client. Change implementations of all
methods with the new approach of the RPC execution.

Additional changes:
 * key replaced from `New` argument to `WithDefaultPrivateKey` option;
 * `GetSelfBalance` is removed as non-viable;
 * `GetEACLWithSignature` is removed, `GetEACL` returns `EACLWithSignature`;
 * `AttachSessionToken` / `AttachBearerToken` are removed as non-viable;
 * redundant options are removed.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 14:03:49 +03:00
Leonard Lyubich
5a9dd7ab3f [#263] pkg/netmap: Do not allocate nil repeated fields during conversion
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 14:03:49 +03:00
Evgenii Stratonikov
ae2fb263f1 [#266] pkg/client: Export Client interface instead of structure
Make it easier to test API clients and mock specific methods.
Also add comments on exported methods.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-03-17 13:43:22 +03:00
Alex Vanin
e39a1fd949 pkg/object: Add content type constant
Specification defined one more well-known object
attribute `Content-Type`.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-03-15 13:27:28 +03:00
Evgenii Stratonikov
64505180b4 [#261] pkg/client: Provide signing key in call options
Allow to reuse underlying connection for requests
with different key. If no key is specified the one
provided on client creation is used.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-03-12 10:40:10 +03:00