[#1689] cli: Add split-header
option for object patch command
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m18s
Pre-commit hooks / Pre-commit (push) Successful in 1m38s
Build / Build Components (push) Successful in 1m40s
Tests and linters / Run gofumpt (push) Successful in 3m34s
Tests and linters / Lint (push) Successful in 3m46s
Tests and linters / Staticcheck (push) Successful in 3m56s
Tests and linters / Tests (push) Successful in 4m8s
Tests and linters / gopls check (push) Successful in 4m25s
OCI image / Build container images (push) Successful in 4m51s
Tests and linters / Tests with -race (push) Successful in 8m10s
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m18s
Pre-commit hooks / Pre-commit (push) Successful in 1m38s
Build / Build Components (push) Successful in 1m40s
Tests and linters / Run gofumpt (push) Successful in 3m34s
Tests and linters / Lint (push) Successful in 3m46s
Tests and linters / Staticcheck (push) Successful in 3m56s
Tests and linters / Tests (push) Successful in 4m8s
Tests and linters / gopls check (push) Successful in 4m25s
OCI image / Build container images (push) Successful in 4m51s
Tests and linters / Tests with -race (push) Successful in 8m10s
* Make `split-header` option read binary- or JSON-encoded split-header; * Use `PatchHeader` instead of `PatchAttributes`. Change-Id: I50ae1bd93d4695657249dacbea981199a39e1a35 Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
11493d587b
commit
2a6cdbdb72
2 changed files with 32 additions and 1 deletions
|
@ -858,6 +858,8 @@ type PatchObjectPrm struct {
|
||||||
|
|
||||||
ReplaceAttribute bool
|
ReplaceAttribute bool
|
||||||
|
|
||||||
|
NewSplitHeader *objectSDK.SplitHeader
|
||||||
|
|
||||||
PayloadPatches []PayloadPatch
|
PayloadPatches []PayloadPatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,7 +890,11 @@ func Patch(ctx context.Context, prm PatchObjectPrm) (*PatchRes, error) {
|
||||||
return nil, fmt.Errorf("init payload reading: %w", err)
|
return nil, fmt.Errorf("init payload reading: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if patcher.PatchAttributes(ctx, prm.NewAttributes, prm.ReplaceAttribute) {
|
if patcher.PatchHeader(ctx, client.PatchHeaderPrm{
|
||||||
|
NewSplitHeader: prm.NewSplitHeader,
|
||||||
|
NewAttributes: prm.NewAttributes,
|
||||||
|
ReplaceAttributes: prm.ReplaceAttribute,
|
||||||
|
}) {
|
||||||
for _, pp := range prm.PayloadPatches {
|
for _, pp := range prm.PayloadPatches {
|
||||||
payloadFile, err := os.OpenFile(pp.PayloadPath, os.O_RDONLY, os.ModePerm)
|
payloadFile, err := os.OpenFile(pp.PayloadPath, os.O_RDONLY, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||||
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
||||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
|
@ -20,6 +22,7 @@ const (
|
||||||
replaceAttrsFlagName = "replace-attrs"
|
replaceAttrsFlagName = "replace-attrs"
|
||||||
rangeFlagName = "range"
|
rangeFlagName = "range"
|
||||||
payloadFlagName = "payload"
|
payloadFlagName = "payload"
|
||||||
|
splitHeaderFlagName = "split-header"
|
||||||
)
|
)
|
||||||
|
|
||||||
var objectPatchCmd = &cobra.Command{
|
var objectPatchCmd = &cobra.Command{
|
||||||
|
@ -50,6 +53,7 @@ func initObjectPatchCmd() {
|
||||||
flags.Bool(replaceAttrsFlagName, false, "Replace object attributes by new ones.")
|
flags.Bool(replaceAttrsFlagName, false, "Replace object attributes by new ones.")
|
||||||
flags.StringSlice(rangeFlagName, []string{}, "Range to which patch payload is applied. Format: offset:length")
|
flags.StringSlice(rangeFlagName, []string{}, "Range to which patch payload is applied. Format: offset:length")
|
||||||
flags.StringSlice(payloadFlagName, []string{}, "Path to file with patch payload.")
|
flags.StringSlice(payloadFlagName, []string{}, "Path to file with patch payload.")
|
||||||
|
flags.String(splitHeaderFlagName, "", "Path to binary or JSON-encoded split header")
|
||||||
}
|
}
|
||||||
|
|
||||||
func patch(cmd *cobra.Command, _ []string) {
|
func patch(cmd *cobra.Command, _ []string) {
|
||||||
|
@ -84,6 +88,8 @@ func patch(cmd *cobra.Command, _ []string) {
|
||||||
prm.NewAttributes = newAttrs
|
prm.NewAttributes = newAttrs
|
||||||
prm.ReplaceAttribute = replaceAttrs
|
prm.ReplaceAttribute = replaceAttrs
|
||||||
|
|
||||||
|
prm.NewSplitHeader = parseSplitHeaderBinaryOrJSON(cmd)
|
||||||
|
|
||||||
for i := range ranges {
|
for i := range ranges {
|
||||||
prm.PayloadPatches = append(prm.PayloadPatches, internalclient.PayloadPatch{
|
prm.PayloadPatches = append(prm.PayloadPatches, internalclient.PayloadPatch{
|
||||||
Range: ranges[i],
|
Range: ranges[i],
|
||||||
|
@ -147,3 +153,22 @@ func patchPayloadPaths(cmd *cobra.Command) []string {
|
||||||
v, _ := cmd.Flags().GetStringSlice(payloadFlagName)
|
v, _ := cmd.Flags().GetStringSlice(payloadFlagName)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseSplitHeaderBinaryOrJSON(cmd *cobra.Command) *objectSDK.SplitHeader {
|
||||||
|
path, _ := cmd.Flags().GetString(splitHeaderFlagName)
|
||||||
|
if path == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
commonCmd.ExitOnErr(cmd, "read file error: %w", err)
|
||||||
|
|
||||||
|
splitHdrV2 := new(objectV2.SplitHeader)
|
||||||
|
err = splitHdrV2.Unmarshal(data)
|
||||||
|
if err != nil {
|
||||||
|
err = splitHdrV2.UnmarshalJSON(data)
|
||||||
|
commonCmd.ExitOnErr(cmd, "unmarshal error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectSDK.NewSplitHeaderFromV2(splitHdrV2)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue