MCPcopy Create free account
hub / github.com/hashicorp/vault / VerifyWithContext

Method VerifyWithContext

api/ssh_agent.go:244–278  ·  view source on GitHub ↗

VerifyWithContext the same as Verify but with a custom context.

(ctx context.Context, otp string)

Source from the content-addressed store, hash-verified

242
243// VerifyWithContext the same as Verify but with a custom context.
244func (c *SSHHelper) VerifyWithContext(ctx context.Context, otp string) (*SSHVerifyResponse, error) {
245 ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
246 defer cancelFunc()
247
248 data := map[string]interface{}{
249 "otp": otp,
250 }
251 verifyPath := fmt.Sprintf("/v1/%s/verify", c.MountPoint)
252 r := c.c.NewRequest(http.MethodPut, verifyPath)
253 if err := r.SetJSONBody(data); err != nil {
254 return nil, err
255 }
256
257 resp, err := c.c.rawRequestWithContext(ctx, r)
258 if err != nil {
259 return nil, err
260 }
261 defer resp.Body.Close()
262
263 secret, err := ParseSecret(resp.Body)
264 if err != nil {
265 return nil, err
266 }
267
268 if secret.Data == nil {
269 return nil, nil
270 }
271
272 var verifyResp SSHVerifyResponse
273 err = mapstructure.Decode(secret.Data, &verifyResp)
274 if err != nil {
275 return nil, err
276 }
277 return &verifyResp, nil
278}

Callers 1

VerifyMethod · 0.95

Calls 6

SetJSONBodyMethod · 0.95
ParseSecretFunction · 0.85
withConfiguredTimeoutMethod · 0.80
rawRequestWithContextMethod · 0.80
NewRequestMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected