2024-02-01 13:11:17 +00:00
|
|
|
package frostfsid
|
2023-11-08 13:36:55 +00:00
|
|
|
|
|
|
|
import (
|
2024-01-17 08:35:09 +00:00
|
|
|
"errors"
|
2023-11-08 13:36:55 +00:00
|
|
|
"fmt"
|
|
|
|
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2024-01-30 14:07:05 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/ape"
|
2023-11-08 13:36:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2024-01-12 10:54:00 +00:00
|
|
|
"github.com/spf13/cobra"
|
2023-11-08 13:36:55 +00:00
|
|
|
)
|
|
|
|
|
2024-01-12 10:54:00 +00:00
|
|
|
func getFrostfsIDSubjectKey(cmd *cobra.Command) *keys.PublicKey {
|
|
|
|
subjKeyHex, _ := cmd.Flags().GetString(subjectKeyFlag)
|
|
|
|
subjKey, err := keys.NewPublicKeyFromString(subjKeyHex)
|
|
|
|
commonCmd.ExitOnErr(cmd, "invalid subject key: %w", err)
|
|
|
|
return subjKey
|
|
|
|
}
|
|
|
|
|
2024-01-12 15:03:18 +00:00
|
|
|
func getFrostfsIDSubjectAddress(cmd *cobra.Command) util.Uint160 {
|
|
|
|
subjAddress, _ := cmd.Flags().GetString(subjectAddressFlag)
|
|
|
|
subjAddr, err := address.StringToUint160(subjAddress)
|
|
|
|
commonCmd.ExitOnErr(cmd, "invalid subject address: %w", err)
|
|
|
|
return subjAddr
|
|
|
|
}
|
2024-01-17 08:35:09 +00:00
|
|
|
|
|
|
|
func getFrostfsIDSubjectName(cmd *cobra.Command) string {
|
|
|
|
subjectName, _ := cmd.Flags().GetString(subjectNameFlag)
|
|
|
|
|
|
|
|
if subjectName == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-01-30 14:07:05 +00:00
|
|
|
if !ape.SubjectNameRegexp.MatchString(subjectName) {
|
2024-01-17 08:35:09 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "invalid subject name: %w",
|
2024-01-30 14:07:05 +00:00
|
|
|
fmt.Errorf("name must match regexp: %s", ape.SubjectNameRegexp.String()))
|
2024-01-17 08:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return subjectName
|
|
|
|
}
|
|
|
|
|
|
|
|
func getFrostfsIDGroupName(cmd *cobra.Command) string {
|
|
|
|
groupName, _ := cmd.Flags().GetString(groupNameFlag)
|
|
|
|
|
2024-01-30 14:07:05 +00:00
|
|
|
if !ape.GroupNameRegexp.MatchString(groupName) {
|
2024-01-17 08:35:09 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "invalid group name: %w",
|
2024-01-30 14:07:05 +00:00
|
|
|
fmt.Errorf("name must match regexp: %s", ape.GroupNameRegexp.String()))
|
2024-01-17 08:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return groupName
|
|
|
|
}
|
|
|
|
|
|
|
|
func getFrostfsIDGroupID(cmd *cobra.Command) int64 {
|
|
|
|
groupID, _ := cmd.Flags().GetInt64(groupIDFlag)
|
|
|
|
if groupID <= 0 {
|
|
|
|
commonCmd.ExitOnErr(cmd, "invalid group id: %w",
|
|
|
|
errors.New("group id must be positive integer"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return groupID
|
|
|
|
}
|
|
|
|
|
|
|
|
func getFrostfsIDNamespace(cmd *cobra.Command) string {
|
|
|
|
ns, _ := cmd.Flags().GetString(namespaceFlag)
|
|
|
|
if ns == rootNamespacePlaceholder {
|
|
|
|
ns = ""
|
|
|
|
}
|
|
|
|
|
2024-01-30 14:07:05 +00:00
|
|
|
if !ape.NamespaceNameRegexp.MatchString(ns) {
|
2024-01-17 08:35:09 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "invalid namespace: %w",
|
2024-01-30 14:07:05 +00:00
|
|
|
fmt.Errorf("name must match regexp: %s", ape.NamespaceNameRegexp.String()))
|
2024-01-17 08:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ns
|
|
|
|
}
|