forked from TrueCloudLab/frostfs-node
[#290] cmd/cli: Add salt flag to object hash command
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
3a7f6701d8
commit
6df8c84fc2
1 changed files with 15 additions and 1 deletions
|
@ -30,6 +30,10 @@ const (
|
||||||
getRangeCmdLongDesc = "Get payload range data of an object"
|
getRangeCmdLongDesc = "Get payload range data of an object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
getRangeHashSaltFlag = "salt"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// objectCmd represents the object command
|
// objectCmd represents the object command
|
||||||
objectCmd = &cobra.Command{
|
objectCmd = &cobra.Command{
|
||||||
|
@ -157,6 +161,7 @@ func init() {
|
||||||
_ = objectHashCmd.MarkFlagRequired("oid")
|
_ = objectHashCmd.MarkFlagRequired("oid")
|
||||||
objectHashCmd.Flags().String("range", "", "Range to take hash from in the form offset1:length1,...")
|
objectHashCmd.Flags().String("range", "", "Range to take hash from in the form offset1:length1,...")
|
||||||
objectHashCmd.Flags().String("type", hashSha256, "Hash type. Either 'sha256' or 'tz'")
|
objectHashCmd.Flags().String("type", hashSha256, "Hash type. Either 'sha256' or 'tz'")
|
||||||
|
objectHashCmd.Flags().String(getRangeHashSaltFlag, "", "Salt in hex format")
|
||||||
|
|
||||||
objectCmd.AddCommand(objectRangeCmd)
|
objectCmd.AddCommand(objectRangeCmd)
|
||||||
objectRangeCmd.Flags().String("cid", "", "Container ID")
|
objectRangeCmd.Flags().String("cid", "", "Container ID")
|
||||||
|
@ -427,6 +432,11 @@ func getObjectHash(cmd *cobra.Command, _ []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
salt, err := hex.DecodeString(cmd.Flag(getRangeHashSaltFlag).Value.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cli, tok, err := initSession(ctx)
|
cli, tok, err := initSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -456,7 +466,11 @@ func getObjectHash(cmd *cobra.Command, _ []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ps := new(client.RangeChecksumParams).WithAddress(objAddr).WithRangeList(ranges...)
|
ps := new(client.RangeChecksumParams).
|
||||||
|
WithAddress(objAddr).
|
||||||
|
WithRangeList(ranges...).
|
||||||
|
WithSalt(salt)
|
||||||
|
|
||||||
switch typ {
|
switch typ {
|
||||||
case hashSha256:
|
case hashSha256:
|
||||||
res, err := cli.ObjectPayloadRangeSHA256(ctx, ps,
|
res, err := cli.ObjectPayloadRangeSHA256(ctx, ps,
|
||||||
|
|
Loading…
Reference in a new issue