Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
- name: Build
run: go build -v ./...

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



26 changes: 13 additions & 13 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"fmt"
"github.com/Keyfactor/keyfactor-go-client-sdk"
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
)

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

var ids = []string{id}

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

var ids = []string{id}

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

Expand Down
28 changes: 14 additions & 14 deletions api/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package api_test
package api

import (
"fmt"
"github.com/Keyfactor/keyfactor-go-client/api"
"io"
"log"
"os"
"testing"
)

Expand All @@ -18,7 +18,7 @@ const (

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

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

func TestClient_GetAgent(t *testing.T) {
log.SetOutput(io.Discard)
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
if kfcErr != nil {
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
return
Expand All @@ -197,23 +197,23 @@ func TestClient_GetAgent(t *testing.T) {
name string
fields fields
args args
want []api.Agent
want []Agent
wantErr bool
}{
{
name: "agent_get_failure",
fields: fields{}, args: args{
id: "invalid-agent-name",
},
want: []api.Agent{},
want: []Agent{},
wantErr: true,
},
{
name: "agent_get_success",
fields: fields{}, args: args{
id: agentID,
},
want: []api.Agent{},
want: []Agent{},
wantErr: false,
},
}
Expand All @@ -239,7 +239,7 @@ func TestClient_GetAgent(t *testing.T) {
func TestClient_GetAgentList(t *testing.T) {
log.SetOutput(io.Discard)
log.SetOutput(io.Discard)
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
if kfcErr != nil {
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
return
Expand All @@ -249,13 +249,13 @@ func TestClient_GetAgentList(t *testing.T) {
tests := []struct {
name string
fields fields
want []api.Agent
want []Agent
wantErr bool
}{
{
name: "GetAgentList",
fields: fields{},
want: []api.Agent{},
want: []Agent{},
wantErr: false,
},
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestClient_GetAgentList(t *testing.T) {

func TestClient_ResetAgent(t *testing.T) {
log.SetOutput(io.Discard)
c, kfcErr := api.NewKeyfactorClient(&api.AuthConfig{})
c, kfcErr := NewKeyfactorClient(&AuthConfig{})
if kfcErr != nil {
t.Errorf("unable to connect to Keyfactor. Please check your credentials and try again. %s", kfcErr)
return
Expand Down
6 changes: 3 additions & 3 deletions api/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"encoding/json"
"github.com/Keyfactor/keyfactor-go-client-sdk"
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
)

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

Expand Down
55 changes: 27 additions & 28 deletions api/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/Keyfactor/keyfactor-go-client-sdk"
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
"github.com/spbsoluble/go-pkcs12"
"go.mozilla.org/pkcs7"
"log"
Expand Down Expand Up @@ -60,8 +60,8 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
xKeyfactorApiVersion := "1"
xCertificateFormat := ea.CertFormat

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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

req := keyfactor_command_client_api.ModelsEnrollmentPFXEnrollmentRequest{
req := keyfactor.ModelsEnrollmentPFXEnrollmentRequest{
CustomFriendlyName: &ea.CustomFriendlyName,
Password: &ea.Password,
PopulateMissingValuesFromAD: &ea.PopulateMissingValuesFromAD,
Expand Down Expand Up @@ -153,14 +153,14 @@ func (c *Client) DownloadCertificate(certId int, thumbprint string, serialNumber
xKeyfactorRequestedWith := "APIClient"
xKeyfactorApiVersion := "1"

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

newCertId := int32(certId)
newIssuerDN := keyfactor_command_client_api.NullableString{}
newIssuerDN := keyfactor.NullableString{}
newIssuerDN.Set(&issuerDn)

rq := keyfactor_command_client_api.ModelsCertificateDownloadRequest{
rq := keyfactor.ModelsCertificateDownloadRequest{
CertID: &newCertId,
SerialNumber: &serialNumber,
IssuerDN: newIssuerDN,
Expand Down Expand Up @@ -220,11 +220,11 @@ func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) {
xKeyfactorApiVersion := "1"
xCertificateFormat := ea.CertFormat

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

eaJson, _ := json.Marshal(ea)
var req keyfactor_command_client_api.ModelsEnrollmentCSREnrollmentRequest
var req keyfactor.ModelsEnrollmentCSREnrollmentRequest
json.Unmarshal(eaJson, &req)

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

raJson, _ := json.Marshal(ra)
var req keyfactor_command_client_api.ModelsRevokeCertificateRequest
var req keyfactor.ModelsRevokeCertificateRequest
json.Unmarshal(raJson, &req)

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

argsJson, _ := json.Marshal(args)
var req keyfactor_command_client_api.KeyfactorApiModelsEnrollmentEnrollmentManagementRequest
var req keyfactor.KeyfactorApiModelsEnrollmentEnrollmentManagementRequest
json.Unmarshal(argsJson, &req)

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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()

Expand Down Expand Up @@ -400,17 +400,16 @@ func (c *Client) ListCertificates(q map[string]string) ([]GetCertificateResponse
newQuery.pqQueryString = fmt.Sprintf(`IssuedCN -eq "%s"`, subjectName)
}
tp, tpOk := q["thumbprint"]

if tpOk {
query.Query = append(query.Query, StringTuple{
"pq.queryString", fmt.Sprintf(`Thumbprint -eq "%s"`, tp),
})
newQuery.pqQueryString = fmt.Sprintf(`Thumbprint -eq "%s"`, tp)
}

xKeyfactorRequestedWith := "APIClient"
xKeyfactorApiVersion := "1"

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

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()

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

configuration := keyfactor_command_client_api.NewConfiguration()
apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
configuration := keyfactor.NewConfiguration()
apiClient := keyfactor.NewAPIClient(configuration)

newCertId := int32(certId)
newIssuerDN := keyfactor_command_client_api.NullableString{}
newIssuerDN := keyfactor.NullableString{}
newIssuerDN.Set(&issuerDn)
newIncludeChain := true

newReq := keyfactor_command_client_api.ModelsCertificateRecoveryRequest{
newReq := keyfactor.ModelsCertificateRecoveryRequest{
Password: password,
CertID: &newCertId,
SerialNumber: &serialNumber,
Expand Down
18 changes: 0 additions & 18 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,6 @@ func loginToKeyfactor(auth *AuthConfig) (*Client, error) {
return nil, err
}

//xKeyfactorRequestedWith := "APIClient"
//xKeyfactorApiVersion := "1"
//
//configuration := keyfactor_command_client_api.NewConfiguration()
//apiClient := keyfactor_command_client_api.NewAPIClient(configuration)
//
//_, _, err := apiClient.StatusApi.StatusGetEndpoints(context.Background()).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
//
//if err != nil {
// return nil, err
//}
//
//c := &Client{
// hostname: apiClient.GetConfig().Host,
// httpClient: &http.Client{Timeout: 10 * time.Second},
// basicAuthString: buildBasicAuthString(auth),
//}

log.Printf("[INFO] Successfully logged into Keyfactor at host %s", c.hostname)

return c, nil
Expand Down
Loading