-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neofs-lens: add new command meta object put
This command places the object into the metabase. It can be useful if you want to add an object directly to the metabase. Closes #1816. Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
- Loading branch information
1 parent
4aab937
commit a9605f6
Showing
7 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package meta | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" | ||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" | ||
"github.com/nspcc-dev/neofs-sdk-go/object" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var writeObjectCMD = &cobra.Command{ | ||
Use: "put", | ||
Short: "Put object to metabase", | ||
Long: "Put object from file to metabase", | ||
Args: cobra.NoArgs, | ||
Run: writeObject, | ||
} | ||
|
||
func init() { | ||
common.AddComponentPathFlag(writeObjectCMD, &vPath) | ||
common.AddInputPathFile(writeObjectCMD, &vInputObj) | ||
} | ||
|
||
func writeObject(cmd *cobra.Command, _ []string) { | ||
db := openMeta(cmd, false) | ||
defer db.Close() | ||
|
||
err := db.Init() | ||
common.ExitOnErr(cmd, common.Errf("can't init metabase: %w", err)) | ||
|
||
buf, err := os.ReadFile(vInputObj) | ||
common.ExitOnErr(cmd, common.Errf("unable to read given file: %w", err)) | ||
|
||
obj := object.New() | ||
common.ExitOnErr(cmd, common.Errf("can't unmarshal object from given file: %w", obj.Unmarshal(buf))) | ||
|
||
id, ok := obj.ID() | ||
if !ok { | ||
common.ExitOnErr(cmd, errors.New("missing ID in object")) | ||
} | ||
|
||
cnr, ok := obj.ContainerID() | ||
if !ok { | ||
common.ExitOnErr(cmd, errors.New("missing container ID in object")) | ||
} | ||
|
||
var pPrm meta.PutPrm | ||
pPrm.SetObject(obj) | ||
|
||
_, err = db.Put(pPrm) | ||
common.ExitOnErr(cmd, common.Errf("can't put object: %w", err)) | ||
|
||
cmd.Printf("[%s] Object successfully stored\n", vInputObj) | ||
cmd.Printf(" OID: %s\n CID: %s\n", id, cnr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters