@@ -4,13 +4,13 @@ import (
44 "fmt"
55 "io/ioutil"
66 "path"
7- "regexp"
87 "strconv"
98 "strings"
109
1110 "github.com/deis/workflow-cli/controller/api"
1211 "github.com/deis/workflow-cli/controller/client"
1312 "github.com/deis/workflow-cli/controller/models/keys"
13+ "github.com/deis/workflow-cli/pkg/ssh"
1414)
1515
1616// KeysList lists a user's keys.
@@ -157,22 +157,16 @@ func listKeys() ([]api.KeyCreateRequest, error) {
157157}
158158
159159func getKey (filename string ) (api.KeyCreateRequest , error ) {
160- regex := regexp .MustCompile ("^(ssh-...|ecdsa-[^ ]+) ([^ ]+) ?(.*)" )
161- contents , err := ioutil .ReadFile (filename )
160+ keyContents , err := ioutil .ReadFile (filename )
162161
163162 if err != nil {
164163 return api.KeyCreateRequest {}, err
165164 }
166165
167- if regex .Match (contents ) {
168- capture := regex .FindStringSubmatch (string (contents ))
169- if capture [3 ] != "" {
170- return api.KeyCreateRequest {ID : capture [3 ], Public : string (contents ), Name : filename }, nil
171- }
172-
173- id := strings .Split (path .Base (filename ), "." )[0 ]
174- return api.KeyCreateRequest {ID : id , Public : string (contents ), Name : filename }, nil
166+ backupID := strings .Split (path .Base (filename ), "." )[0 ]
167+ keyInfo , err := ssh .ParsePubKey (backupID , keyContents )
168+ if err != nil {
169+ return api.KeyCreateRequest {}, fmt .Errorf ("%s is not a valid ssh key" , filename )
175170 }
176-
177- return api.KeyCreateRequest {}, fmt .Errorf ("%s is not a valid ssh key" , filename )
171+ return api.KeyCreateRequest {ID : keyInfo .ID , Public : keyInfo .Public , Name : filename }, nil
178172}
0 commit comments