add uncloud machine init command to initialise a new cluster on local machine

This commit is contained in:
Pavel Sviderski
2024-09-05 12:21:01 +10:00
parent 58fb3105cd
commit 3f71aec275
7 changed files with 222 additions and 53 deletions
+12 -3
View File
@@ -9,6 +9,15 @@ import (
type Secret []byte
// FromHexString parses a hex-encoded string into a secret.
func FromHexString(s string) (Secret, error) {
decoded, err := hex.DecodeString(s)
if err != nil {
return nil, fmt.Errorf("invalid hex-encoded secret: %w", err)
}
return decoded, nil
}
// String returns the hex-encoded string representation of the secret.
//
//goland:noinspection GoMixedReceiverTypes
@@ -23,11 +32,11 @@ func (s Secret) MarshalText() ([]byte, error) {
//goland:noinspection GoMixedReceiverTypes
func (s *Secret) UnmarshalText(text []byte) error {
decoded, err := hex.DecodeString(string(text))
secret, err := FromHexString(string(text))
if err != nil {
return fmt.Errorf("invalid hex-encoded secret: %w", err)
return err
}
*s = decoded
*s = secret
return nil
}