initSecretRing sets c.secretRing. It tries, in this order, the --secret-keyring flag, the CAMLI_SECRET_RING env var, then defaults to the operating system dependent location otherwise. It returns an error if the file does not exist.
()
| 96 | // otherwise. |
| 97 | // It returns an error if the file does not exist. |
| 98 | func (c *initCmd) initSecretRing() error { |
| 99 | if secretRing, ok := osutil.ExplicitSecretRingFile(); ok { |
| 100 | c.secretRing = secretRing |
| 101 | } else { |
| 102 | if android.OnAndroid() { |
| 103 | panic("on android, so CAMLI_SECRET_RING should have been defined, or --secret-keyring used.") |
| 104 | } |
| 105 | c.secretRing = osutil.SecretRingFile() |
| 106 | } |
| 107 | if _, err := os.Stat(c.secretRing); err != nil { |
| 108 | hint := "\nA GPG key is required, please use 'pk-put init --newkey'.\n\nOr if you know what you're doing, you can set the global pk-put flag --secret-keyring, or the CAMLI_SECRET_RING env var, to use your own GPG ring. And --gpgkey=<pubid> or GPGKEY to select which key ID to use." |
| 109 | return fmt.Errorf("Could not use secret ring file %v: %v.\n%v", c.secretRing, err, hint) |
| 110 | } |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | // initKeyId sets c.keyId. It checks, in this order, the --gpgkey flag, the GPGKEY env var, |
| 115 | // and in the default identity secret ring. |
no test coverage detected