GetKey retrieves a key from the agent by the given comment.
(comment string, opts ...AgentOption)
| 157 | |
| 158 | // GetKey retrieves a key from the agent by the given comment. |
| 159 | func (a *Agent) GetKey(comment string, opts ...AgentOption) (*agent.Key, error) { |
| 160 | o := newOptions(opts) |
| 161 | keys, err := a.List() |
| 162 | if err != nil { |
| 163 | return nil, errors.Wrap(err, "error listing keys") |
| 164 | } |
| 165 | for _, key := range keys { |
| 166 | if key.Comment == comment { |
| 167 | if o.removeExpiredKey != nil && o.removeExpiredKey(a, key) { |
| 168 | continue |
| 169 | } |
| 170 | if o.filterBySignatureKey == nil || o.filterBySignatureKey(key) { |
| 171 | return key, nil |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | return nil, ErrNotFound |
| 176 | } |
| 177 | |
| 178 | // GetSigner returns a signer that has a key with the given comment. |
| 179 | func (a *Agent) GetSigner(comment string, opts ...AgentOption) (ssh.Signer, error) { |
no test coverage detected