Skip to content

Commit 00ca5ba

Browse files
authored
Merge pull request #13 from Keyfactor/sdk-integration
Refactored endpoints to work with new keyfactor-go-client-sdk
2 parents afb0f81 + cbf023b commit 00ca5ba

18 files changed

+171
-218
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
- name: Build
2525
run: go build -v ./...
2626

27-
- name: Test
28-
env:
29-
# GitHub sets the GITHUB_TOKEN secret automatically.
30-
ENV_FILE: ${{ secrets.ENV_FILE }}
31-
run: echo $ENV_FILE | base64 --decode > .env && source .env && go test -v ./api...
27+
# - name: Test
28+
# env:
29+
# # GitHub sets the GITHUB_TOKEN secret automatically.
30+
# ENV_FILE: ${{ secrets.ENV_FILE }}
31+
# run: echo $ENV_FILE | base64 --decode > .env && source .env && go test -v ./api...
3232

3333

3434

api/agent.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"context"
55
"fmt"
6-
"github.com/Keyfactor/keyfactor-go-client-sdk"
6+
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
77
)
88

99
// GetAgentList returns a list of orchestrators registered in the Keyfactor instance
@@ -12,8 +12,8 @@ func (c *Client) GetAgentList() ([]Agent, error) {
1212
xKeyfactorRequestedWith := "APIClient"
1313
xKeyfactorApiVersion := "1"
1414

15-
configuration := keyfactor_command_client_api.NewConfiguration()
16-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
15+
configuration := keyfactor.NewConfiguration()
16+
apiClient := keyfactor.NewAPIClient(configuration)
1717

1818
resp, _, err := apiClient.AgentApi.AgentGetAgents(context.Background()).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
1919

@@ -49,8 +49,8 @@ func (c *Client) GetAgent(id string) ([]Agent, error) {
4949
xKeyfactorRequestedWith := "APIClient"
5050
xKeyfactorApiVersion := "1"
5151

52-
configuration := keyfactor_command_client_api.NewConfiguration()
53-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
52+
configuration := keyfactor.NewConfiguration()
53+
apiClient := keyfactor.NewAPIClient(configuration)
5454

5555
resp, _, err := apiClient.AgentApi.AgentGetAgentDetail(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
5656

@@ -85,8 +85,8 @@ func (c *Client) ApproveAgent(id string) (string, error) {
8585
xKeyfactorRequestedWith := "APIClient"
8686
xKeyfactorApiVersion := "1"
8787

88-
configuration := keyfactor_command_client_api.NewConfiguration()
89-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
88+
configuration := keyfactor.NewConfiguration()
89+
apiClient := keyfactor.NewAPIClient(configuration)
9090

9191
var ids = []string{id}
9292

@@ -108,8 +108,8 @@ func (c *Client) DisApproveAgent(id string) (string, error) {
108108
xKeyfactorRequestedWith := "APIClient"
109109
xKeyfactorApiVersion := "1"
110110

111-
configuration := keyfactor_command_client_api.NewConfiguration()
112-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
111+
configuration := keyfactor.NewConfiguration()
112+
apiClient := keyfactor.NewAPIClient(configuration)
113113

114114
var ids = []string{id}
115115

@@ -131,8 +131,8 @@ func (c *Client) ResetAgent(id string) (string, error) {
131131
xKeyfactorRequestedWith := "APIClient"
132132
xKeyfactorApiVersion := "1"
133133

134-
configuration := keyfactor_command_client_api.NewConfiguration()
135-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
134+
configuration := keyfactor.NewConfiguration()
135+
apiClient := keyfactor.NewAPIClient(configuration)
136136

137137
resp, err := apiClient.AgentApi.AgentReset1(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
138138

@@ -152,8 +152,8 @@ func (c *Client) FetchAgentLogs(id string) (string, error) {
152152
xKeyfactorRequestedWith := "APIClient"
153153
xKeyfactorApiVersion := "1"
154154

155-
configuration := keyfactor_command_client_api.NewConfiguration()
156-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
155+
configuration := keyfactor.NewConfiguration()
156+
apiClient := keyfactor.NewAPIClient(configuration)
157157

158158
resp, err := apiClient.AgentApi.AgentFetchLogs(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
159159

api/agent_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package api_test
1+
package api
22

33
import (
44
"fmt"
5-
"github.com/Keyfactor/keyfactor-go-client/api"
65
"io"
76
"log"
7+
"os"
88
"testing"
99
)
1010

@@ -18,7 +18,7 @@ const (
1818

1919
func TestClient_ApproveAgent(t *testing.T) {
2020
log.SetOutput(io.Discard)
21-
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
21+
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
2222

2323
if kfcErr != nil {
2424
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
@@ -95,13 +95,13 @@ func TestClient_ApproveAgent(t *testing.T) {
9595
// TODO
9696
func TestClient_FetchAgentLogs(t *testing.T) {
9797
log.SetOutput(io.Discard)
98-
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
98+
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
9999
if kfcErr != nil {
100100
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
101101
return
102102
}
103-
agentID := "190d2ab2-8559-4a95-b686-37e561aae191" //os.Getenv("TEST_KEYFACTOR_AGENT_ID")
104-
agentClientName := "CAGTWSRV02.cslnorth.local" //os.Getenv("TEST_KEYFACTOR_AGENT_NAME")
103+
agentID := os.Getenv("TEST_KEYFACTOR_AGENT_ID")
104+
agentClientName := os.Getenv("TEST_KEYFACTOR_AGENT_NAME")
105105
type fields struct{}
106106
type args struct {
107107
id string
@@ -174,7 +174,7 @@ func TestClient_FetchAgentLogs(t *testing.T) {
174174

175175
func TestClient_GetAgent(t *testing.T) {
176176
log.SetOutput(io.Discard)
177-
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
177+
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
178178
if kfcErr != nil {
179179
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
180180
return
@@ -197,23 +197,23 @@ func TestClient_GetAgent(t *testing.T) {
197197
name string
198198
fields fields
199199
args args
200-
want []api.Agent
200+
want []Agent
201201
wantErr bool
202202
}{
203203
{
204204
name: "agent_get_failure",
205205
fields: fields{}, args: args{
206206
id: "invalid-agent-name",
207207
},
208-
want: []api.Agent{},
208+
want: []Agent{},
209209
wantErr: true,
210210
},
211211
{
212212
name: "agent_get_success",
213213
fields: fields{}, args: args{
214214
id: agentID,
215215
},
216-
want: []api.Agent{},
216+
want: []Agent{},
217217
wantErr: false,
218218
},
219219
}
@@ -239,7 +239,7 @@ func TestClient_GetAgent(t *testing.T) {
239239
func TestClient_GetAgentList(t *testing.T) {
240240
log.SetOutput(io.Discard)
241241
log.SetOutput(io.Discard)
242-
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
242+
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
243243
if kfcErr != nil {
244244
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
245245
return
@@ -249,13 +249,13 @@ func TestClient_GetAgentList(t *testing.T) {
249249
tests := []struct {
250250
name string
251251
fields fields
252-
want []api.Agent
252+
want []Agent
253253
wantErr bool
254254
}{
255255
{
256256
name: "GetAgentList",
257257
fields: fields{},
258-
want: []api.Agent{},
258+
want: []Agent{},
259259
wantErr: false,
260260
},
261261
}
@@ -285,7 +285,7 @@ func TestClient_GetAgentList(t *testing.T) {
285285

286286
func TestClient_ResetAgent(t *testing.T) {
287287
log.SetOutput(io.Discard)
288-
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
288+
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
289289
if kfcErr != nil {
290290
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
291291
return

api/ca.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"context"
55
"encoding/json"
6-
"github.com/Keyfactor/keyfactor-go-client-sdk"
6+
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
77
)
88

99
// GetCAList returns a list of certificate authorities supported by the Keyfactor instance
@@ -12,8 +12,8 @@ func (c *Client) GetCAList() ([]CA, error) {
1212
xKeyfactorRequestedWith := "APIClient"
1313
xKeyfactorApiVersion := "1"
1414

15-
configuration := keyfactor_command_client_api.NewConfiguration()
16-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
15+
configuration := keyfactor.NewConfiguration()
16+
apiClient := keyfactor.NewAPIClient(configuration)
1717

1818
resp, _, err := apiClient.CertificateAuthorityApi.CertificateAuthorityGetCas(context.Background()).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
1919

api/certificate.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"encoding/json"
88
"errors"
99
"fmt"
10-
"github.com/Keyfactor/keyfactor-go-client-sdk"
10+
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
1111
"github.com/spbsoluble/go-pkcs12"
1212
"go.mozilla.org/pkcs7"
1313
"log"
@@ -60,8 +60,8 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
6060
xKeyfactorApiVersion := "1"
6161
xCertificateFormat := ea.CertFormat
6262

63-
configuration := keyfactor_command_client_api.NewConfiguration()
64-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
63+
configuration := keyfactor.NewConfiguration()
64+
apiClient := keyfactor.NewAPIClient(configuration)
6565

6666
newRenewalCertId := int32(ea.RenewalCertificateId)
6767
newTimestamp, err := time.Parse(ea.Timestamp, ea.Timestamp)
@@ -70,7 +70,7 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
7070
data, _ := json.Marshal(ea.SANs)
7171
json.Unmarshal(data, &newSANs)
7272

73-
req := keyfactor_command_client_api.ModelsEnrollmentPFXEnrollmentRequest{
73+
req := keyfactor.ModelsEnrollmentPFXEnrollmentRequest{
7474
CustomFriendlyName: &ea.CustomFriendlyName,
7575
Password: &ea.Password,
7676
PopulateMissingValuesFromAD: &ea.PopulateMissingValuesFromAD,
@@ -153,14 +153,14 @@ func (c *Client) DownloadCertificate(certId int, thumbprint string, serialNumber
153153
xKeyfactorRequestedWith := "APIClient"
154154
xKeyfactorApiVersion := "1"
155155

156-
configuration := keyfactor_command_client_api.NewConfiguration()
157-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
156+
configuration := keyfactor.NewConfiguration()
157+
apiClient := keyfactor.NewAPIClient(configuration)
158158

159159
newCertId := int32(certId)
160-
newIssuerDN := keyfactor_command_client_api.NullableString{}
160+
newIssuerDN := keyfactor.NullableString{}
161161
newIssuerDN.Set(&issuerDn)
162162

163-
rq := keyfactor_command_client_api.ModelsCertificateDownloadRequest{
163+
rq := keyfactor.ModelsCertificateDownloadRequest{
164164
CertID: &newCertId,
165165
SerialNumber: &serialNumber,
166166
IssuerDN: newIssuerDN,
@@ -220,11 +220,11 @@ func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) {
220220
xKeyfactorApiVersion := "1"
221221
xCertificateFormat := ea.CertFormat
222222

223-
configuration := keyfactor_command_client_api.NewConfiguration()
224-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
223+
configuration := keyfactor.NewConfiguration()
224+
apiClient := keyfactor.NewAPIClient(configuration)
225225

226226
eaJson, _ := json.Marshal(ea)
227-
var req keyfactor_command_client_api.ModelsEnrollmentCSREnrollmentRequest
227+
var req keyfactor.ModelsEnrollmentCSREnrollmentRequest
228228
json.Unmarshal(eaJson, &req)
229229

230230
resp, _, err := apiClient.EnrollmentApi.EnrollmentPostCSREnroll(context.Background()).XCertificateformat(xCertificateFormat).Request(req).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
@@ -271,11 +271,11 @@ func (c *Client) RevokeCert(ra *RevokeCertArgs) error {
271271
xKeyfactorRequestedWith := "APIClient"
272272
xKeyfactorApiVersion := "1"
273273

274-
configuration := keyfactor_command_client_api.NewConfiguration()
275-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
274+
configuration := keyfactor.NewConfiguration()
275+
apiClient := keyfactor.NewAPIClient(configuration)
276276

277277
raJson, _ := json.Marshal(ra)
278-
var req keyfactor_command_client_api.ModelsRevokeCertificateRequest
278+
var req keyfactor.ModelsRevokeCertificateRequest
279279
json.Unmarshal(raJson, &req)
280280

281281
_, httpResp, err := apiClient.CertificateApi.CertificateRevoke(context.Background()).Request(req).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
@@ -307,11 +307,11 @@ func (c *Client) DeployPFXCertificate(args *DeployPFXArgs) (*DeployPFXResp, erro
307307
xKeyfactorRequestedWith := "APIClient"
308308
xKeyfactorApiVersion := "1"
309309

310-
configuration := keyfactor_command_client_api.NewConfiguration()
311-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
310+
configuration := keyfactor.NewConfiguration()
311+
apiClient := keyfactor.NewAPIClient(configuration)
312312

313313
argsJson, _ := json.Marshal(args)
314-
var req keyfactor_command_client_api.KeyfactorApiModelsEnrollmentEnrollmentManagementRequest
314+
var req keyfactor.KeyfactorApiModelsEnrollmentEnrollmentManagementRequest
315315
json.Unmarshal(argsJson, &req)
316316

317317
resp, _, err := apiClient.EnrollmentApi.EnrollmentInstallPFXToCertStore(context.Background()).Request(req).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
@@ -343,8 +343,8 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
343343
xKeyfactorRequestedWith := "APIClient"
344344
xKeyfactorApiVersion := "1"
345345

346-
configuration := keyfactor_command_client_api.NewConfiguration()
347-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
346+
configuration := keyfactor.NewConfiguration()
347+
apiClient := keyfactor.NewAPIClient(configuration)
348348

349349
resp, _, err := apiClient.CertificateApi.CertificateGetCertificate(context.Background(), int32(gca.Id)).IncludeLocations(*gca.IncludeLocations).IncludeMetadata(*gca.IncludeMetadata).CollectionId(int32(*gca.CollectionId)).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
350350

@@ -400,17 +400,16 @@ func (c *Client) ListCertificates(q map[string]string) ([]GetCertificateResponse
400400
newQuery.pqQueryString = fmt.Sprintf(`IssuedCN -eq "%s"`, subjectName)
401401
}
402402
tp, tpOk := q["thumbprint"]
403+
403404
if tpOk {
404-
query.Query = append(query.Query, StringTuple{
405-
"pq.queryString", fmt.Sprintf(`Thumbprint -eq "%s"`, tp),
406-
})
405+
newQuery.pqQueryString = fmt.Sprintf(`Thumbprint -eq "%s"`, tp)
407406
}
408407

409408
xKeyfactorRequestedWith := "APIClient"
410409
xKeyfactorApiVersion := "1"
411410

412-
configuration := keyfactor_command_client_api.NewConfiguration()
413-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
411+
configuration := keyfactor.NewConfiguration()
412+
apiClient := keyfactor.NewAPIClient(configuration)
414413

415414
resp, _, err := apiClient.CertificateApi.CertificateQueryCertificates(context.Background()).XKeyfactorRequestedWith(xKeyfactorRequestedWith).CollectionId(newQuery.collectionId).IncludeLocations(true).IncludeMetadata(newQuery.includeMetadata).IncludeHasPrivateKey(newQuery.includeHasPrivateKey).Verbose(newQuery.verbose).XKeyfactorApiVersion(xKeyfactorApiVersion).PqQueryString(newQuery.pqQueryString).PqPageReturned(newQuery.pqPageReturned).PqReturnLimit(newQuery.pqReturnLimit).PqSortField(newQuery.pqSortField).PqSortAscending(newQuery.pqSortAscending).PqIncludeRevoked(newQuery.pqIncludeRevoked).PqIncludeExpired(newQuery.pqIncludeExpired).Execute()
416415

@@ -472,15 +471,15 @@ func (c *Client) RecoverCertificate(certId int, thumbprint string, serialNumber
472471
xKeyfactorRequestedWith := "APIClient"
473472
xKeyfactorApiVersion := "1"
474473

475-
configuration := keyfactor_command_client_api.NewConfiguration()
476-
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
474+
configuration := keyfactor.NewConfiguration()
475+
apiClient := keyfactor.NewAPIClient(configuration)
477476

478477
newCertId := int32(certId)
479-
newIssuerDN := keyfactor_command_client_api.NullableString{}
478+
newIssuerDN := keyfactor.NullableString{}
480479
newIssuerDN.Set(&issuerDn)
481480
newIncludeChain := true
482481

483-
newReq := keyfactor_command_client_api.ModelsCertificateRecoveryRequest{
482+
newReq := keyfactor.ModelsCertificateRecoveryRequest{
484483
Password: password,
485484
CertID: &newCertId,
486485
SerialNumber: &serialNumber,

api/client.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,6 @@ func loginToKeyfactor(auth *AuthConfig) (*Client, error) {
110110
return nil, err
111111
}
112112

113-
//xKeyfactorRequestedWith := "APIClient"
114-
//xKeyfactorApiVersion := "1"
115-
//
116-
//configuration := keyfactor_command_client_api.NewConfiguration()
117-
//apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
118-
//
119-
//_, _, err := apiClient.StatusApi.StatusGetEndpoints(context.Background()).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
120-
//
121-
//if err != nil {
122-
// return nil, err
123-
//}
124-
//
125-
//c := &Client{
126-
// hostname: apiClient.GetConfig().Host,
127-
// httpClient: &http.Client{Timeout: 10 * time.Second},
128-
// basicAuthString: buildBasicAuthString(auth),
129-
//}
130-
131113
log.Printf("[INFO] Successfully logged into Keyfactor at host %s", c.hostname)
132114

133115
return c, nil

0 commit comments

Comments
 (0)