Skip to content

Commit b453765

Browse files
committed
feat(certs): Added ability to list certs and filter by IssuedCN and CollectionId
1 parent ea1b1c8 commit b453765

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
env:
2727
# GitHub sets the GITHUB_TOKEN secret automatically.
2828
ENV_FILE: ${{ secrets.ENV_FILE }}
29-
run: echo $ENV_FILE | base64 --decode > .env && cat .env && go test -v ./...
29+
run: echo $ENV_FILE | base64 --decode > .env && go test -v ./...
3030

3131

3232

api/certificate.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,56 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
389389
return &jsonResp, err
390390
}
391391

392+
func (c *Client) ListCertificates(q map[string]string) ([]GetCertificateResponse, error) {
393+
// Set Keyfactor-specific headers
394+
headers := &apiHeaders{
395+
Headers: []StringTuple{
396+
{"x-keyfactor-api-version", "1"},
397+
{"x-keyfactor-requested-with", "APIClient"},
398+
},
399+
}
400+
401+
// Construct URL query for /Certificates/{ID} requests
402+
query := apiQuery{
403+
Query: []StringTuple{},
404+
}
405+
query.Query = append(query.Query, StringTuple{
406+
"includeLocations", "true",
407+
})
408+
searchCollection, ok := q["collection"]
409+
if ok {
410+
query.Query = append(query.Query, StringTuple{
411+
"collectionId", searchCollection,
412+
})
413+
}
414+
subjectName, ok := q["subject"]
415+
if ok {
416+
query.Query = append(query.Query, StringTuple{
417+
"pq.queryString", fmt.Sprintf(`IssuedCN -eq "%s"`, subjectName),
418+
})
419+
}
420+
421+
keyfactorAPIStruct := &request{
422+
Method: "GET",
423+
Endpoint: "Certificates",
424+
Headers: headers,
425+
Query: &query,
426+
Payload: nil,
427+
}
428+
429+
resp, err := c.sendRequest(keyfactorAPIStruct)
430+
if err != nil {
431+
return nil, err
432+
}
433+
434+
var jsonResp []GetCertificateResponse
435+
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
436+
if err != nil {
437+
return nil, err
438+
}
439+
return jsonResp, err
440+
}
441+
392442
// RecoverCertificate takes arguments for RecoverCertArgs to facilitate a call to Keyfactor
393443
// that recovers a certificate and associated private key (if retained) in the specified format.
394444
// The download certificate endpoint requires one of the following to retrieve a cert:

0 commit comments

Comments
 (0)