Skip to content

Commit

Permalink
enhances way of SSH flow to deal with set timeout in Request. Removes…
Browse files Browse the repository at this point in the history
… request set timeout in some tests since that now VCert it uses it to set workToDoTimeout, it will give us errors when the tiemout is very small. Now we use TPP's default value for it
  • Loading branch information
luispresuelVenafi committed Nov 21, 2024
1 parent ba0de87 commit 19f6903
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/venafi/tpp/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,11 @@ func TestRenewCertRestoringValues(t *testing.T) {
req.FetchPrivateKey = true
req.KeyPassword = os.Getenv("TPP_PASSWORD")

req.Timeout = time.Second * 30 // explicitly setting this value here
// to make sure we only wait for certificate issuance for 30 seconds because
// setting it before the RequestCertificate function, will override
// workToDoTimeout to only wait to 30 seconds

pcc, err := tpp.RetrieveCertificate(req)
if err != nil {
t.Fatal(err)
Expand All @@ -1846,11 +1851,11 @@ func TestRenewCertRestoringValues(t *testing.T) {
renewReq := certificate.RenewalRequest{
CertificateDN: req.PickupID,
}
pickupdID, err := tpp.RenewCertificate(&renewReq)
pickupID, err := tpp.RenewCertificate(&renewReq)
if err != nil {
t.Fatal(err)
}
req = &certificate.Request{PickupID: pickupdID, Timeout: 30 * time.Second}
req = &certificate.Request{PickupID: pickupID, Timeout: 30 * time.Second}
pcc, err = tpp.RetrieveCertificate(req)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/venafi/tpp/sshCertUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func RequestSshCertificate(c *Connector, req *certificate.SshCertRequest) (*cert
}

//TODO: Maybe, there is a better way to set the timeout.
c.client.Timeout = time.Duration(req.Timeout) * time.Second
if req.Timeout > 0 {
c.client.Timeout = req.Timeout * time.Second
}
statusCode, status, body, err := c.request("POST", urlResourceSshCertReq, sshCertReq)
if err != nil {
return nil, err
Expand All @@ -55,7 +57,7 @@ func RequestSshCertificate(c *Connector, req *certificate.SshCertRequest) (*cert
response, err := parseSshCertOperationResponse(statusCode, status, body)

if err != nil {
if response.Response.ErrorMessage != "" && c.verbose {
if &response != nil && response.Response.ErrorMessage != "" && c.verbose {
log.Println(util.GetJsonAsString(response.Response))
}
return nil, err
Expand Down

0 comments on commit 19f6903

Please sign in to comment.