validate that all of the key names are unique and are alphanumeric + _ + - and that we do not already have public key files in the target dir on disk
(keyName string, targetDir string)
| 46 | // validate that all of the key names are unique and are alphanumeric + _ + - |
| 47 | // and that we do not already have public key files in the target dir on disk |
| 48 | func validateKeyArgs(keyName string, targetDir string) error { |
| 49 | if !validKeyName(keyName) { |
| 50 | return fmt.Errorf("key name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", keyName) |
| 51 | } |
| 52 | |
| 53 | pubKeyFileName := keyName + ".pub" |
| 54 | if _, err := os.Stat(targetDir); err != nil { |
| 55 | return fmt.Errorf("public key path does not exist: \"%s\"", targetDir) |
| 56 | } |
| 57 | targetPath := filepath.Join(targetDir, pubKeyFileName) |
| 58 | if _, err := os.Stat(targetPath); err == nil { |
| 59 | return fmt.Errorf("public key file already exists: \"%s\"", targetPath) |
| 60 | } |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | func setupPassphraseAndGenerateKeys(streams command.Streams, opts keyGenerateOptions) error { |
| 65 | targetDir := opts.directory |
no outgoing calls
searching dependent graphs…