2024-05-06 13:33:20 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
apemanagerV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
|
2024-05-06 13:33:20 +00:00
|
|
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
2024-05-28 09:05:02 +00:00
|
|
|
sessionV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
2024-05-06 13:33:20 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature"
|
2024-05-28 09:05:02 +00:00
|
|
|
apeSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
|
2024-05-06 13:33:20 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrmAPEManagerListChains groups parameters of APEManagerListChains operation.
|
|
|
|
type PrmAPEManagerListChains struct {
|
|
|
|
XHeaders []string
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
ChainTarget apeSDK.ChainTarget
|
2024-05-06 13:33:20 +00:00
|
|
|
}
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
func (prm *PrmAPEManagerListChains) buildRequest(c *Client) (*apemanagerV2.ListChainsRequest, error) {
|
2024-05-06 13:33:20 +00:00
|
|
|
if len(prm.XHeaders)%2 != 0 {
|
|
|
|
return nil, errorInvalidXHeaders
|
|
|
|
}
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
req := new(apemanagerV2.ListChainsRequest)
|
|
|
|
reqBody := new(apemanagerV2.ListChainsRequestBody)
|
2024-05-06 13:33:20 +00:00
|
|
|
|
|
|
|
reqBody.SetTarget(prm.ChainTarget.ToV2())
|
|
|
|
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
var meta sessionV2.RequestMetaHeader
|
2024-05-06 13:33:20 +00:00
|
|
|
writeXHeadersToMeta(prm.XHeaders, &meta)
|
|
|
|
|
|
|
|
c.prepareRequest(req, &meta)
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResAPEManagerListChains struct {
|
|
|
|
statusRes
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
Chains []apeSDK.Chain
|
2024-05-06 13:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// APEManagerListChains lists Chains for ChainTarget.
|
|
|
|
func (c *Client) APEManagerListChains(ctx context.Context, prm PrmAPEManagerListChains) (*ResAPEManagerListChains, error) {
|
|
|
|
req, err := prm.buildRequest(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
|
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.ListChains(&c.c, req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var res ResAPEManagerListChains
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ch := range resp.GetBody().GetChains() {
|
2024-05-28 09:05:02 +00:00
|
|
|
var chSDK apeSDK.Chain
|
2024-05-06 13:33:20 +00:00
|
|
|
if err := chSDK.ReadFromV2(ch); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res.Chains = append(res.Chains, chSDK)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|