summaryrefslogtreecommitdiff
path: root/go/internal/keyline/key_line.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/internal/keyline/key_line.go')
-rw-r--r--go/internal/keyline/key_line.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/go/internal/keyline/key_line.go b/go/internal/keyline/key_line.go
index 7b19c87..f92f50b 100644
--- a/go/internal/keyline/key_line.go
+++ b/go/internal/keyline/key_line.go
@@ -16,6 +16,7 @@ var (
const (
PublicKeyPrefix = "key"
+ PrincipalPrefix = "username"
SshOptions = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"
)
@@ -27,11 +28,11 @@ type KeyLine struct {
}
func NewPublicKeyLine(id string, publicKey string, rootDir string) (*KeyLine, error) {
- if err := validate(id, publicKey); err != nil {
- return nil, err
- }
+ return newKeyLine(id, publicKey, PublicKeyPrefix, rootDir)
+}
- return &KeyLine{Id: id, Value: publicKey, Prefix: PublicKeyPrefix, RootDir: rootDir}, nil
+func NewPrincipalKeyLine(keyId string, principal string, rootDir string) (*KeyLine, error) {
+ return newKeyLine(keyId, principal, PrincipalPrefix, rootDir)
}
func (k *KeyLine) ToString() string {
@@ -40,6 +41,14 @@ func (k *KeyLine) ToString() string {
return fmt.Sprintf(`command="%s",%s %s`, command, SshOptions, k.Value)
}
+func newKeyLine(id string, value string, prefix string, rootDir string) (*KeyLine, error) {
+ if err := validate(id, value); err != nil {
+ return nil, err
+ }
+
+ return &KeyLine{Id: id, Value: value, Prefix: prefix, RootDir: rootDir}, nil
+}
+
func validate(id string, value string) error {
if !keyRegex.MatchString(id) {
return errors.New(fmt.Sprintf("Invalid key_id: %s", id))