MCPcopy Create free account
hub / github.com/docker/cli / validateKeyArgs

Function validateKeyArgs

cmd/docker-trust/trust/key_generate.go:48–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
48func 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
64func setupPassphraseAndGenerateKeys(streams command.Streams, opts keyGenerateOptions) error {
65 targetDir := opts.directory

Callers 2

validateAndGenerateKeyFunction · 0.85
TestValidateKeyArgsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValidateKeyArgsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…