From 3bb945791b9d707fe8ac658b3785d7a2dd234809 Mon Sep 17 00:00:00 2001 From: spbsoluble <1661003+spbsoluble@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:57:08 -0700 Subject: [PATCH] chore(docs): Add LICENSE and deprecation notice. --- LICENSE | 201 ++++++++++++++++++++ README.md | 7 +- api/agent.go | 30 ++- api/agent_models.go | 14 ++ api/agent_test.go | 212 +++++++++++---------- api/ca.go | 14 ++ api/ca_models.go | 14 ++ api/ca_test.go | 46 +++-- api/certificate.go | 46 ++++- api/certificate_models.go | 14 ++ api/certificate_test.go | 14 ++ api/client.go | 27 ++- api/client_models.go | 14 ++ api/client_test.go | 116 +++++++----- api/metadata.go | 19 +- api/metadata_models.go | 14 ++ api/metadata_test.go | 68 ++++--- api/security.go | 34 +++- api/security_models.go | 14 ++ api/security_test.go | 250 ++++++++++++++----------- api/store.go | 52 +++++- api/store_container.go | 22 ++- api/store_container_models.go | 14 ++ api/store_container_test.go | 56 ++++-- api/store_models.go | 14 ++ api/store_test.go | 308 +++++++++++++++++-------------- api/store_type.go | 29 ++- api/store_type_models.go | 14 ++ api/store_type_test.go | 172 +++++++++-------- api/template.go | 19 +- api/template_models.go | 14 ++ api/template_test.go | 110 ++++++----- examples/createStore/main.go | 14 ++ examples/enrollPFX/main.go | 17 +- examples/security/main.go | 17 +- examples/test.go | 17 +- main.go | 16 +- v2/api/agent.go | 14 ++ v2/api/agent_models.go | 14 ++ v2/api/agent_test.go | 283 +++++++++++++++------------- v2/api/ca.go | 14 ++ v2/api/ca_models.go | 14 ++ v2/api/ca_test.go | 46 +++-- v2/api/certificate.go | 14 ++ v2/api/certificate_models.go | 14 ++ v2/api/certificate_test.go | 14 ++ v2/api/client.go | 14 ++ v2/api/client_models.go | 14 ++ v2/api/client_test.go | 114 +++++++----- v2/api/constants.go | 14 ++ v2/api/metadata.go | 14 ++ v2/api/metadata_models.go | 14 ++ v2/api/metadata_test.go | 68 ++++--- v2/api/security.go | 14 ++ v2/api/security_models.go | 14 ++ v2/api/security_test.go | 250 ++++++++++++++----------- v2/api/store.go | 14 ++ v2/api/store_container.go | 14 ++ v2/api/store_container_models.go | 14 ++ v2/api/store_container_test.go | 97 ++++++---- v2/api/store_models.go | 14 ++ v2/api/store_test.go | 308 +++++++++++++++++-------------- v2/api/store_type.go | 14 ++ v2/api/store_type_models.go | 14 ++ v2/api/store_type_test.go | 175 ++++++++++-------- v2/api/template.go | 14 ++ v2/api/template_models.go | 14 ++ v2/api/template_test.go | 110 ++++++----- v2/api/workflow.go | 22 ++- v2/api/workflow_models.go | 14 ++ v2/go.mod | 14 ++ 71 files changed, 2656 insertions(+), 1226 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f49a4e1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 24422b6..59f4aad 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,14 @@ -# Keyfactor Command Golang Client +# Keyfactor Command Golang Client (DEPRECATED) The Keyfactor Command Golang Client is a Go module that provides abstracted methods of interacting with the Keyfactor API. The primary supported functionality is the creation and modification of SSL/TLS certificates, updating certificate metadata, and creating certificate stores. -#### Integration status: Production - Ready for use in production environments. +## Integration status: Deprecated +This client is deprecated as of `2024-09` and will no longer be maintained. Please use the [Keyfactor Command Go Client SDK](https://github.com/Keyfactor/keyfactor-go-client-sdk) for future integrations. ## About the Keyfactor API Client This API client allows for programmatic management of Keyfactor resources. - - ## Support for Keyfactor Command Golang Client Keyfactor Command Golang Client is open source and there is **no SLA** for this tool/library/client. Keyfactor will address issues as resources become available. Keyfactor customers may request escalation by opening up a support ticket through their Keyfactor representative. diff --git a/api/agent.go b/api/agent.go index a335186..4971446 100644 --- a/api/agent.go +++ b/api/agent.go @@ -1,8 +1,23 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( "context" "fmt" + "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor" ) @@ -52,7 +67,10 @@ func (c *Client) GetAgent(id string) ([]Agent, error) { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, _, err := apiClient.AgentApi.AgentGetAgentDetail(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, _, err := apiClient.AgentApi.AgentGetAgentDetail( + context.Background(), + id, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() var revResp []Agent @@ -134,7 +152,10 @@ func (c *Client) ResetAgent(id string) (string, error) { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, err := apiClient.AgentApi.AgentReset1(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, err := apiClient.AgentApi.AgentReset1( + context.Background(), + id, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if resp.StatusCode == 204 { return "Reset agent successful.", nil @@ -155,7 +176,10 @@ func (c *Client) FetchAgentLogs(id string) (string, error) { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, err := apiClient.AgentApi.AgentFetchLogs(context.Background(), id).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, err := apiClient.AgentApi.AgentFetchLogs( + context.Background(), + id, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if resp.StatusCode == 204 { return "Reset agent successful.", nil diff --git a/api/agent_models.go b/api/agent_models.go index 63d8454..ade4115 100644 --- a/api/agent_models.go +++ b/api/agent_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type Agent struct { diff --git a/api/agent_test.go b/api/agent_test.go index c629b18..5e490d2 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -74,21 +88,23 @@ func TestClient_ApproveAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.args.status == ApprovedAgentStatus { - _, err := c.DisApproveAgent(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("DisApproveAgent() error = %v, wantErr %v", err, tt.wantErr) - return - } - } else { - _, err := c.ApproveAgent(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("ApproveAgent() error = %v, wantErr %v", err, tt.wantErr) - return + t.Run( + tt.name, func(t *testing.T) { + if tt.args.status == ApprovedAgentStatus { + _, err := c.DisApproveAgent(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("DisApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + return + } + } else { + _, err := c.ApproveAgent(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("ApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + return + } } - } - }) + }, + ) } } @@ -134,41 +150,43 @@ func TestClient_FetchAgentLogs(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.args.id == "" && tt.args.clientName == "" && !tt.wantErr { - t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, agentClientName) - return - } else if tt.args.id == "" { - agents, lErr := c.GetAgentList() - if lErr != nil && !tt.wantErr { - t.Errorf("unable to list agents. %s", lErr) + t.Run( + tt.name, func(t *testing.T) { + if tt.args.id == "" && tt.args.clientName == "" && !tt.wantErr { + t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, agentClientName) return - } - foundAgent := false - for _, agent := range agents { - if agent.ClientMachine == tt.args.clientName { - tt.args.id = agent.AgentId - foundAgent = true - break + } else if tt.args.id == "" { + agents, lErr := c.GetAgentList() + if lErr != nil && !tt.wantErr { + t.Errorf("unable to list agents. %s", lErr) + return + } + foundAgent := false + for _, agent := range agents { + if agent.ClientMachine == tt.args.clientName { + tt.args.id = agent.AgentId + foundAgent = true + break + } + } + if !foundAgent && !tt.wantErr { + t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) + return } } - if !foundAgent && !tt.wantErr { - t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) + got, err := c.FetchAgentLogs(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("FetchAgentLogs() error = %v, wantErr %v", err, tt.wantErr) return } - } - got, err := c.FetchAgentLogs(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("FetchAgentLogs() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check returned message - if got != tt.want { - t.Errorf("FetchAgentLogs() got = %v, want %v", got, tt.want) + if !tt.wantErr { + // Check returned message + if got != tt.want { + t.Errorf("FetchAgentLogs() got = %v, want %v", got, tt.want) + } } - } - }) + }, + ) } } @@ -218,21 +236,23 @@ func TestClient_GetAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run( + tt.name, func(t *testing.T) { - got, err := c.GetAgent(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("GetAgent() error = %v, wantErr %v", err, tt.wantErr) - return - } - // Check that length of the array is greater than 0 - if !tt.wantErr { - if len(got) == 0 { - t.Errorf("GetAgent() got %d records, want %d record(s).\n", len(got), 1) + got, err := c.GetAgent(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("GetAgent() error = %v, wantErr %v", err, tt.wantErr) return } - } - }) + // Check that length of the array is greater than 0 + if !tt.wantErr { + if len(got) == 0 { + t.Errorf("GetAgent() got %d records, want %d record(s).\n", len(got), 1) + return + } + } + }, + ) } } @@ -260,26 +280,28 @@ func TestClient_GetAgentList(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run( + tt.name, func(t *testing.T) { - got, err := c.GetAgentList() - if (err != nil) != tt.wantErr { - t.Errorf("GetAgentList() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that length of the array is greater than 0 - if len(got) == 0 { - t.Errorf("GetAgentList() got %d records, want at least %d record(s).\n", len(got), 1) + got, err := c.GetAgentList() + if (err != nil) != tt.wantErr { + t.Errorf("GetAgentList() error = %v, wantErr %v", err, tt.wantErr) return } - // Check returned agent name - if got[0].ClientMachine == "" { - t.Errorf("GetAgentList() got empty agent name, want non-empty agent name.\n") - return + if !tt.wantErr { + // Check that length of the array is greater than 0 + if len(got) == 0 { + t.Errorf("GetAgentList() got %d records, want at least %d record(s).\n", len(got), 1) + return + } + // Check returned agent name + if got[0].ClientMachine == "" { + t.Errorf("GetAgentList() got empty agent name, want non-empty agent name.\n") + return + } } - } - }) + }, + ) } } @@ -349,31 +371,33 @@ func TestClient_ResetAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var got string - var err error - if tt.args.action == AgentActionReset { - got, err = c.ResetAgent(tt.args.id) - } else if tt.args.action == AgentActionApprove { - got, err = c.ApproveAgent(tt.args.id) - } - if (err != nil) != tt.wantErr { - t.Errorf("ResetAgent() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that length of the array is greater than 0 - if got != tt.want { - t.Errorf("ResetAgent() got %s, want %s.\n", got, tt.want) - return + t.Run( + tt.name, func(t *testing.T) { + var got string + var err error + if tt.args.action == AgentActionReset { + got, err = c.ResetAgent(tt.args.id) + } else if tt.args.action == AgentActionApprove { + got, err = c.ApproveAgent(tt.args.id) } - } else { - errStr := fmt.Sprintf("%s", err) - if errStr != tt.want { - t.Errorf("ResetAgent() got %s, want %s.\n", err, tt.want) + if (err != nil) != tt.wantErr { + t.Errorf("ResetAgent() error = %v, wantErr %v", err, tt.wantErr) return } - } - }) + if !tt.wantErr { + // Check that length of the array is greater than 0 + if got != tt.want { + t.Errorf("ResetAgent() got %s, want %s.\n", got, tt.want) + return + } + } else { + errStr := fmt.Sprintf("%s", err) + if errStr != tt.want { + t.Errorf("ResetAgent() got %s, want %s.\n", err, tt.want) + return + } + } + }, + ) } } diff --git a/api/ca.go b/api/ca.go index fd4d851..108a99d 100644 --- a/api/ca.go +++ b/api/ca.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/api/ca_models.go b/api/ca_models.go index a30135a..27fc82e 100644 --- a/api/ca_models.go +++ b/api/ca_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type CA struct { diff --git a/api/ca_test.go b/api/ca_test.go index 6bd8767..4c6097a 100644 --- a/api/ca_test.go +++ b/api/ca_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -21,20 +35,22 @@ func TestClient_GetCAList(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCAList() - if (err != nil) != tt.wantErr { - t.Errorf("GetCAList() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCAList() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCAList() + if (err != nil) != tt.wantErr { + t.Errorf("GetCAList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCAList() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/api/certificate.go b/api/certificate.go index 80388fd..4b3c8b6 100644 --- a/api/certificate.go +++ b/api/certificate.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -7,14 +21,15 @@ import ( "encoding/json" "errors" "fmt" - "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor" - "github.com/spbsoluble/go-pkcs12" - "go.mozilla.org/pkcs7" "log" "net/http" "strconv" "strings" "time" + + "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor" + "github.com/spbsoluble/go-pkcs12" + "go.mozilla.org/pkcs7" ) // EnrollPFX takes arguments for EnrollPFXFctArgs to facilitate a call to Keyfactor @@ -127,7 +142,12 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) { // Returns: // - Leaf certificate // - Certificate chain -func (c *Client) DownloadCertificate(certId int, thumbprint string, serialNumber string, issuerDn string) (*x509.Certificate, []*x509.Certificate, error) { +func (c *Client) DownloadCertificate( + certId int, + thumbprint string, + serialNumber string, + issuerDn string, +) (*x509.Certificate, []*x509.Certificate, error) { log.Println("[INFO] Downloading certificate") /* The download certificate endpoint requires one of the following to retrieve a cert: @@ -285,7 +305,10 @@ func (c *Client) RevokeCert(rvargs *RevokeCertArgs) error { } if httpResp.StatusCode != http.StatusNoContent { - return fmt.Errorf("[ERROR] Something unexpected happened, POST call to /Certificates/Revoke returned status %d", httpResp.StatusCode) + return fmt.Errorf( + "[ERROR] Something unexpected happened, POST call to /Certificates/Revoke returned status %d", + httpResp.StatusCode, + ) } return nil } @@ -346,7 +369,10 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert configuration := keyfactor.NewConfiguration(make(map[string]string)) 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() + 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() if err != nil { return nil, err @@ -442,7 +468,13 @@ func (c *Client) ListCertificates(q map[string]string) ([]GetCertificateResponse // - Private key (*rsa.PrivateKey or *ecdsa.PrivateKey) // - Leaf certificate (*x509.Certificate) // - Certificate chain ([]*x509.Certificate) -func (c *Client) RecoverCertificate(certId int, thumbprint string, serialNumber string, issuerDn string, password string) (interface{}, *x509.Certificate, []*x509.Certificate, error) { +func (c *Client) RecoverCertificate( + certId int, + thumbprint string, + serialNumber string, + issuerDn string, + password string, +) (interface{}, *x509.Certificate, []*x509.Certificate, error) { log.Println("[INFO] Recovering certificate ID:", certId) /* The download certificate endpoint requires one of the following to retrieve a cert: - CertID diff --git a/api/certificate_models.go b/api/certificate_models.go index 4ae3c32..a43d157 100644 --- a/api/certificate_models.go +++ b/api/certificate_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // SANs holds arrays of strings associated with IPv4 (IP4), IPv6 (IP6), DNS, and URI SANs. diff --git a/api/certificate_test.go b/api/certificate_test.go index ffbf73e..23f9322 100644 --- a/api/certificate_test.go +++ b/api/certificate_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // diff --git a/api/client.go b/api/client.go index 80953ee..6ed34ab 100644 --- a/api/client.go +++ b/api/client.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -201,7 +215,10 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { log.Printf("[DEBUG] %s succeeded with response code %d", request.Method, resp.StatusCode) return resp, nil } else if resp.StatusCode == http.StatusNotFound { - stringMessage = fmt.Sprintf("Error %d - the requested resource was not found. Please check the request and try again.", resp.StatusCode) + stringMessage = fmt.Sprintf( + "Error %d - the requested resource was not found. Please check the request and try again.", + resp.StatusCode, + ) log.Printf("[ERROR] Call to %s returned status %d. %s", keyfactorPath, resp.StatusCode, stringMessage) return nil, errors.New(stringMessage) } else if resp.StatusCode == http.StatusUnauthorized { @@ -220,7 +237,13 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { if derr != nil { return nil, derr } - uerr := errors.New(fmt.Sprintf("%d - Unknown error connecting to Keyfactor %s, please check your connection.", resp.StatusCode, endpoint)) + uerr := errors.New( + fmt.Sprintf( + "%d - Unknown error connecting to Keyfactor %s, please check your connection.", + resp.StatusCode, + endpoint, + ), + ) return nil, uerr } diff --git a/api/client_models.go b/api/client_models.go index dcfdf07..d95e76b 100644 --- a/api/client_models.go +++ b/api/client_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // StringTuple is a struct holding two string elements used by the Keyfactor diff --git a/api/client_test.go b/api/client_test.go index 113aa32..c847c74 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -26,21 +40,23 @@ func TestClient_sendRequest(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.sendRequest(tt.args.request) - if (err != nil) != tt.wantErr { - t.Errorf("sendRequest() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("sendRequest() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.sendRequest(tt.args.request) + if (err != nil) != tt.wantErr { + t.Errorf("sendRequest() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("sendRequest() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -57,16 +73,18 @@ func TestNewKeyfactorClient(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewKeyfactorClient(tt.args.auth) - if (err != nil) != tt.wantErr { - t.Errorf("NewKeyfactorClient() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewKeyfactorClient() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + got, err := NewKeyfactorClient(tt.args.auth) + if (err != nil) != tt.wantErr { + t.Errorf("NewKeyfactorClient() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewKeyfactorClient() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -82,11 +100,13 @@ func Test_buildBasicAuthString(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := buildBasicAuthString(tt.args.auth); got != tt.want { - t.Errorf("buildBasicAuthString() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := buildBasicAuthString(tt.args.auth); got != tt.want { + t.Errorf("buildBasicAuthString() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -98,11 +118,13 @@ func Test_getTimestamp(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := getTimestamp(); got != tt.want { - t.Errorf("getTimestamp() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := getTimestamp(); got != tt.want { + t.Errorf("getTimestamp() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -119,16 +141,18 @@ func Test_loginToKeyfactor(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := loginToKeyfactor(tt.args.auth) - fmt.Print(got) - if (err != nil) != tt.wantErr { - t.Errorf("loginToKeyfactor() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("loginToKeyfactor() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + got, err := loginToKeyfactor(tt.args.auth) + fmt.Print(got) + if (err != nil) != tt.wantErr { + t.Errorf("loginToKeyfactor() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("loginToKeyfactor() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/api/metadata.go b/api/metadata.go index d21ffbe..a54d650 100644 --- a/api/metadata.go +++ b/api/metadata.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -69,7 +83,10 @@ func (c *Client) UpdateMetadata(um *UpdateMetadataArgs) error { } if resp.StatusCode != http.StatusNoContent { - return fmt.Errorf("[ERROR] Something unexpected happened, PUT call to /Certificates/Metadata returned status %d", resp.StatusCode) + return fmt.Errorf( + "[ERROR] Something unexpected happened, PUT call to /Certificates/Metadata returned status %d", + resp.StatusCode, + ) } return nil } diff --git a/api/metadata_models.go b/api/metadata_models.go index d44e98b..da90437 100644 --- a/api/metadata_models.go +++ b/api/metadata_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // UpdateMetadataArgs holds the function arguments used for calling the UpdateMetadata method. diff --git a/api/metadata_test.go b/api/metadata_test.go index e9a5da5..870ec0b 100644 --- a/api/metadata_test.go +++ b/api/metadata_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -21,21 +35,23 @@ func TestClient_GetAllMetadataFields(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetAllMetadataFields() - if (err != nil) != tt.wantErr { - t.Errorf("GetAllMetadataFields() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetAllMetadataFields() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetAllMetadataFields() + if (err != nil) != tt.wantErr { + t.Errorf("GetAllMetadataFields() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetAllMetadataFields() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -57,15 +73,17 @@ func TestClient_UpdateMetadata(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.UpdateMetadata(tt.args.um); (err != nil) != tt.wantErr { - t.Errorf("UpdateMetadata() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.UpdateMetadata(tt.args.um); (err != nil) != tt.wantErr { + t.Errorf("UpdateMetadata() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } diff --git a/api/security.go b/api/security.go index 9aa5203..24355ec 100644 --- a/api/security.go +++ b/api/security.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -95,14 +109,20 @@ func (c *Client) DeleteSecurityIdentity(id int) error { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - _, httpResp, err := apiClient.SecurityApi.SecurityIdentityPermissions(context.Background(), int32(id)).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + _, httpResp, err := apiClient.SecurityApi.SecurityIdentityPermissions( + context.Background(), + int32(id), + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return err } if httpResp.StatusCode != http.StatusNoContent { - return fmt.Errorf("[ERROR] Something unexpected happened, DELETE call to Security/Identities/{id} returned status %d", httpResp.StatusCode) + return fmt.Errorf( + "[ERROR] Something unexpected happened, DELETE call to Security/Identities/{id} returned status %d", + httpResp.StatusCode, + ) } return nil } @@ -224,14 +244,20 @@ func (c *Client) DeleteSecurityRole(id int) error { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, err := apiClient.SecurityRolesApi.SecurityRolesDeleteSecurityRole(context.Background(), int32(id)).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, err := apiClient.SecurityRolesApi.SecurityRolesDeleteSecurityRole( + context.Background(), + int32(id), + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return err } if resp.StatusCode != http.StatusNoContent { - return fmt.Errorf("[ERROR] Something unexpected happened, DELETE call to /Security/Roles/{id} returned status %d", resp.StatusCode) + return fmt.Errorf( + "[ERROR] Something unexpected happened, DELETE call to /Security/Roles/{id} returned status %d", + resp.StatusCode, + ) } return nil } diff --git a/api/security_models.go b/api/security_models.go index 72496de..78a35a3 100644 --- a/api/security_models.go +++ b/api/security_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // GetSecurityIdentityResponse holds the response data returned by /Security/Identities diff --git a/api/security_test.go b/api/security_test.go index 814e727..18712c5 100644 --- a/api/security_test.go +++ b/api/security_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_CreateSecurityIdentity(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateSecurityIdentity(tt.args.csia) - if (err != nil) != tt.wantErr { - t.Errorf("CreateSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateSecurityIdentity() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateSecurityIdentity(tt.args.csia) + if (err != nil) != tt.wantErr { + t.Errorf("CreateSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateSecurityIdentity() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -62,21 +78,23 @@ func TestClient_CreateSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateSecurityRole(tt.args.input) - if (err != nil) != tt.wantErr { - t.Errorf("CreateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateSecurityRole(tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("CreateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -98,16 +116,18 @@ func TestClient_DeleteSecurityIdentity(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteSecurityIdentity(tt.args.id); (err != nil) != tt.wantErr { - t.Errorf("DeleteSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteSecurityIdentity(tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("DeleteSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -129,16 +149,18 @@ func TestClient_DeleteSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteSecurityRole(tt.args.id); (err != nil) != tt.wantErr { - t.Errorf("DeleteSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteSecurityRole(tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("DeleteSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -157,21 +179,23 @@ func TestClient_GetSecurityIdentities(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityIdentities() - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityIdentities() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityIdentities() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityIdentities() + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityIdentities() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityIdentities() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -194,21 +218,23 @@ func TestClient_GetSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityRole(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityRole(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -227,21 +253,23 @@ func TestClient_GetSecurityRoles(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityRoles() - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityRoles() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityRoles() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityRoles() + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityRoles() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityRoles() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -264,20 +292,22 @@ func TestClient_UpdateSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateSecurityRole(tt.args.input) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateSecurityRole(tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/api/store.go b/api/store.go index a34aa79..22d7427 100644 --- a/api/store.go +++ b/api/store.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -137,14 +151,20 @@ func (c *Client) DeleteCertificateStore(storeId string) error { configuration := kfc.NewConfiguration(make(map[string]string)) apiClient := kfc.NewAPIClient(configuration) - resp, err := apiClient.CertificateStoreApi.CertificateStoreDeleteCertificateStore(context.Background(), storeId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, err := apiClient.CertificateStoreApi.CertificateStoreDeleteCertificateStore( + context.Background(), + storeId, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return err } if resp.StatusCode != http.StatusNoContent { - return fmt.Errorf("[ERROR] Something unexpected happened, DELETE call to /Certificate/Store/{id} returned status %d", resp.StatusCode) + return fmt.Errorf( + "[ERROR] Something unexpected happened, DELETE call to /Certificate/Store/{id} returned status %d", + resp.StatusCode, + ) } return nil @@ -194,7 +214,12 @@ func (c *Client) ListCertificateStores(params *map[string]interface{}) (*[]GetCe } if resp.StatusCode != http.StatusOK { - return &[]GetCertificateStoreResponse{}, fmt.Errorf("[ERROR] Something unexpected happened, %s call to %s returned status %d", keyfactorAPIStruct.Method, keyfactorAPIStruct.Endpoint, resp.StatusCode) + return &[]GetCertificateStoreResponse{}, fmt.Errorf( + "[ERROR] Something unexpected happened, %s call to %s returned status %d", + keyfactorAPIStruct.Method, + keyfactorAPIStruct.Endpoint, + resp.StatusCode, + ) } var jsonResp []GetCertificateStoreResponse err = json.NewDecoder(resp.Body).Decode(&jsonResp) @@ -250,17 +275,21 @@ func (c *Client) GetCertificateStoreByContainerID(containerID interface{}) (*[]G } switch containerID.(type) { case int: - query.Query = append(query.Query, StringTuple{ - "certificateStoreQuery.queryString", fmt.Sprintf(`ContainerId -eq "%d"`, containerID), - }) + query.Query = append( + query.Query, StringTuple{ + "certificateStoreQuery.queryString", fmt.Sprintf(`ContainerId -eq "%d"`, containerID), + }, + ) case string: ct, ctErr := c.GetStoreContainer(containerID.(string)) if ctErr != nil { return nil, ctErr } - query.Query = append(query.Query, StringTuple{ - "certificateStoreQuery.queryString", fmt.Sprintf(`ContainerId -eq %d`, *ct.Id), - }) + query.Query = append( + query.Query, StringTuple{ + "certificateStoreQuery.queryString", fmt.Sprintf(`ContainerId -eq %d`, *ct.Id), + }, + ) } // Set Keyfactor-specific headers @@ -405,7 +434,10 @@ func (c *Client) GetCertStoreInventory(storeId string) (*[]CertStoreInventory, e configuration := kfc.NewConfiguration(make(map[string]string)) apiClient := kfc.NewAPIClient(configuration) - resp, _, err := apiClient.CertificateStoreApi.CertificateStoreGetCertificateStoreInventory(context.Background(), storeId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, _, err := apiClient.CertificateStoreApi.CertificateStoreGetCertificateStoreInventory( + context.Background(), + storeId, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return nil, err diff --git a/api/store_container.go b/api/store_container.go index cbabf14..3d1500f 100644 --- a/api/store_container.go +++ b/api/store_container.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -71,9 +85,11 @@ func (c *Client) GetStoreContainer(id interface{}) (*CertStoreContainer, error) query = apiQuery{ Query: []StringTuple{}, } - query.Query = append(query.Query, StringTuple{ - "pq.queryString", fmt.Sprintf(`Name -eq "%s"`, id), - }) + query.Query = append( + query.Query, StringTuple{ + "pq.queryString", fmt.Sprintf(`Name -eq "%s"`, id), + }, + ) jsonResp = &[]CertStoreContainer{} } var keyfactorAPIStruct *request diff --git a/api/store_container_models.go b/api/store_container_models.go index c2bb371..3f5c0f9 100644 --- a/api/store_container_models.go +++ b/api/store_container_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // CertStoreContainer holds the function arguments used for calling the GetStoreContainers method. diff --git a/api/store_container_test.go b/api/store_container_test.go index 1a034cb..37ad5f1 100644 --- a/api/store_container_test.go +++ b/api/store_container_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -75,13 +89,15 @@ func TestClient_GetStoreContainer(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - _, err := c.GetStoreContainer(tt.args.id) // GET Store container by ID - if (err != nil) != tt.wantErr { - t.Errorf("GetStoreContainer() error = %v, wantErr %v", err, tt.wantErr) - return - } - }) + t.Run( + tt.name, func(t *testing.T) { + _, err := c.GetStoreContainer(tt.args.id) // GET Store container by ID + if (err != nil) != tt.wantErr { + t.Errorf("GetStoreContainer() error = %v, wantErr %v", err, tt.wantErr) + return + } + }, + ) } } @@ -109,18 +125,20 @@ func TestClient_GetStoreContainers(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := c.GetStoreContainers() - if (err != nil) != tt.wantErr { - t.Errorf("GetStoreContainers() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that we got at least one store container - if len(*got) == 0 { - t.Errorf("GetStoreContainers() got = %v, want %v", got, tt.want) + t.Run( + tt.name, func(t *testing.T) { + got, err := c.GetStoreContainers() + if (err != nil) != tt.wantErr { + t.Errorf("GetStoreContainers() error = %v, wantErr %v", err, tt.wantErr) + return } - } - }) + if !tt.wantErr { + // Check that we got at least one store container + if len(*got) == 0 { + t.Errorf("GetStoreContainers() got = %v, want %v", got, tt.want) + } + } + }, + ) } } diff --git a/api/store_models.go b/api/store_models.go index ffbc3af..9e027e6 100644 --- a/api/store_models.go +++ b/api/store_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // CreateStoreFctArgs holds the function arguments used for calling the CreateStore method. diff --git a/api/store_test.go b/api/store_test.go index 27244cc..3af9e62 100644 --- a/api/store_test.go +++ b/api/store_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_AddCertificateToStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.AddCertificateToStores(tt.args.config) - if (err != nil) != tt.wantErr { - t.Errorf("AddCertificateToStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("AddCertificateToStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.AddCertificateToStores(tt.args.config) + if (err != nil) != tt.wantErr { + t.Errorf("AddCertificateToStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("AddCertificateToStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -62,21 +78,23 @@ func TestClient_CreateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateStore(tt.args.ca) - if (err != nil) != tt.wantErr { - t.Errorf("CreateStore() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateStore() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateStore(tt.args.ca) + if (err != nil) != tt.wantErr { + t.Errorf("CreateStore() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateStore() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -98,16 +116,18 @@ func TestClient_DeleteCertificateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteCertificateStore(tt.args.storeId); (err != nil) != tt.wantErr { - t.Errorf("DeleteCertificateStore() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteCertificateStore(tt.args.storeId); (err != nil) != tt.wantErr { + t.Errorf("DeleteCertificateStore() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -130,21 +150,23 @@ func TestClient_GetCertStoreInventory(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCertStoreInventory(tt.args.storeId) - if (err != nil) != tt.wantErr { - t.Errorf("GetCertStoreInventory() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCertStoreInventory() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCertStoreInventory(tt.args.storeId) + if (err != nil) != tt.wantErr { + t.Errorf("GetCertStoreInventory() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCertStoreInventory() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -167,21 +189,23 @@ func TestClient_GetCertificateStoreByID(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCertificateStoreByID(tt.args.storeId) - if (err != nil) != tt.wantErr { - t.Errorf("GetCertificateStoreByID() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCertificateStoreByID() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCertificateStoreByID(tt.args.storeId) + if (err != nil) != tt.wantErr { + t.Errorf("GetCertificateStoreByID() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCertificateStoreByID() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -200,21 +224,23 @@ func TestClient_ListCertificateStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.ListCertificateStores() - if (err != nil) != tt.wantErr { - t.Errorf("ListCertificateStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListCertificateStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.ListCertificateStores() + if (err != nil) != tt.wantErr { + t.Errorf("ListCertificateStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ListCertificateStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -237,21 +263,23 @@ func TestClient_RemoveCertificateFromStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.RemoveCertificateFromStores(tt.args.config) - if (err != nil) != tt.wantErr { - t.Errorf("RemoveCertificateFromStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RemoveCertificateFromStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.RemoveCertificateFromStores(tt.args.config) + if (err != nil) != tt.wantErr { + t.Errorf("RemoveCertificateFromStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("RemoveCertificateFromStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -274,21 +302,23 @@ func TestClient_UpdateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateStore(tt.args.ua) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateStore() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateStore() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateStore(tt.args.ua) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateStore() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateStore() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -304,11 +334,13 @@ func Test_buildPropertiesInterface(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := buildPropertiesInterface(tt.args.properties); !reflect.DeepEqual(got, tt.want) { - t.Errorf("buildPropertiesInterface() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := buildPropertiesInterface(tt.args.properties); !reflect.DeepEqual(got, tt.want) { + t.Errorf("buildPropertiesInterface() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -324,11 +356,13 @@ func Test_unmarshalPropertiesString(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := unmarshalPropertiesString(tt.args.properties); !reflect.DeepEqual(got, tt.want) { - t.Errorf("unmarshalPropertiesString() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := unmarshalPropertiesString(tt.args.properties); !reflect.DeepEqual(got, tt.want) { + t.Errorf("unmarshalPropertiesString() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -344,11 +378,13 @@ func Test_validateCreateStoreArgs(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := validateCreateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { - t.Errorf("validateCreateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if err := validateCreateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { + t.Errorf("validateCreateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -364,10 +400,12 @@ func Test_validateUpdateStoreArgs(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := validateUpdateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { - t.Errorf("validateUpdateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if err := validateUpdateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { + t.Errorf("validateUpdateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } diff --git a/api/store_type.go b/api/store_type.go index 82689f4..b7c49d5 100644 --- a/api/store_type.go +++ b/api/store_type.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -67,7 +81,10 @@ func (c *Client) GetCertificateStoreTypeByName(name string) (*CertificateStoreTy configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, _, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeGetCertificateStoreType1(context.Background(), name).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, _, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeGetCertificateStoreType1( + context.Background(), + name, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return nil, err @@ -98,7 +115,10 @@ func (c *Client) GetCertificateStoreTypeById(id int) (*CertificateStoreType, err configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, _, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeGetCertificateStoreType0(context.Background(), int32(id)).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, _, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeGetCertificateStoreType0( + context.Background(), + int32(id), + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return nil, err @@ -219,7 +239,10 @@ func (c *Client) DeleteCertificateStoreType(id int) (*DeleteStoreType, error) { configuration := keyfactor.NewConfiguration(make(map[string]string)) apiClient := keyfactor.NewAPIClient(configuration) - resp, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeDeleteCertificateStoreType(context.Background(), int32(id)).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, err := apiClient.CertificateStoreTypeApi.CertificateStoreTypeDeleteCertificateStoreType( + context.Background(), + int32(id), + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return nil, err diff --git a/api/store_type_models.go b/api/store_type_models.go index b7424cd..dd6d2ad 100644 --- a/api/store_type_models.go +++ b/api/store_type_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type CertificateStoreType struct { diff --git a/api/store_type_test.go b/api/store_type_test.go index 5e93ee3..f115cd3 100644 --- a/api/store_type_test.go +++ b/api/store_type_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -62,48 +76,39 @@ var testStoreType = &CertificateStoreType{ func runStoreTypeTests(t *testing.T, tests []storeTypeTest, c *Client) { for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - switch tt.args.action { - case ActionCreate: - got, err := c.CreateStoreType(tt.args.storeType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.CreateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name != tt.want.Name { - t.Errorf("Client.CreateStoreType() = %v, want %v", got, tt.want) + t.Run( + tt.name, func(t *testing.T) { + switch tt.args.action { + case ActionCreate: + got, err := c.CreateStoreType(tt.args.storeType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.CreateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return } - } - case ActionDelete: - s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) - if gErr != nil { - t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) - return - } - got, err := c.DeleteCertificateStoreType(s.StoreType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.DeleteStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.ID <= 0 { - t.Errorf("Client.DeleteStoreType() = %v, want %v", got, tt.want) + if !tt.wantErr { + if got.Name != tt.want.Name { + t.Errorf("Client.CreateStoreType() = %v, want %v", got, tt.want) + } } - } - case ActionGet: - // Test Get by Name first - got, err := c.GetCertificateStoreType(tt.args.name) - if (err != nil) != tt.wantErr { - t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name != tt.want.Name { - t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) + case ActionDelete: + s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) + if gErr != nil { + t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) + return + } + got, err := c.DeleteCertificateStoreType(s.StoreType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.DeleteStoreType() error = %v, wantErr %v", err, tt.wantErr) + return } - // Test Get by ID - got, err = c.GetCertificateStoreType(got.StoreType) + if !tt.wantErr { + if got.ID <= 0 { + t.Errorf("Client.DeleteStoreType() = %v, want %v", got, tt.want) + } + } + case ActionGet: + // Test Get by Name first + got, err := c.GetCertificateStoreType(tt.args.name) if (err != nil) != tt.wantErr { t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) return @@ -112,47 +117,66 @@ func runStoreTypeTests(t *testing.T, tests []storeTypeTest, c *Client) { if got.Name != tt.want.Name { t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) } + // Test Get by ID + got, err = c.GetCertificateStoreType(got.StoreType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !tt.wantErr { + if got.Name != tt.want.Name { + t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) + } + } } - } - case ActionList: - got, err := c.ListCertificateStoreTypes() - if (err != nil) != tt.wantErr { - t.Errorf("Client.ListCertificateStoreTypes() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if len(*got) <= 0 { - t.Errorf("Client.ListCertificateStoreTypes() = %v, want > %v", got, 1) + case ActionList: + got, err := c.ListCertificateStoreTypes() + if (err != nil) != tt.wantErr { + t.Errorf("Client.ListCertificateStoreTypes() error = %v, wantErr %v", err, tt.wantErr) + return } - } - case ActionUpdate: - s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) - if gErr != nil { - t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) - return - } - tt.args.storeType.StoreType = s.StoreType - tt.args.storeType.ImportType = s.ImportType - got, err := c.UpdateStoreType(tt.args.storeType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.UpdateCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name == testStoreType.Name { - t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got.Name, tt.want.Name) - } else if got.Name != tt.want.Name { - t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got, tt.want) + if !tt.wantErr { + if len(*got) <= 0 { + t.Errorf("Client.ListCertificateStoreTypes() = %v, want > %v", got, 1) + } } - if got.PowerShell == testStoreType.PowerShell { - t.Errorf("Client.UpdateCertificateStoreType() PowerShell = %v, want %v", got.PowerShell, !testStoreType.PowerShell) - } else if got.PowerShell != tt.want.PowerShell { - t.Errorf("Client.UpdateCertificateStoreType() PowerShell = %v, want %v", got.PowerShell, tt.want.PowerShell) + case ActionUpdate: + s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) + if gErr != nil { + t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) + return + } + tt.args.storeType.StoreType = s.StoreType + tt.args.storeType.ImportType = s.ImportType + got, err := c.UpdateStoreType(tt.args.storeType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.UpdateCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !tt.wantErr { + if got.Name == testStoreType.Name { + t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got.Name, tt.want.Name) + } else if got.Name != tt.want.Name { + t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got, tt.want) + } + if got.PowerShell == testStoreType.PowerShell { + t.Errorf( + "Client.UpdateCertificateStoreType() PowerShell = %v, want %v", + got.PowerShell, + !testStoreType.PowerShell, + ) + } else if got.PowerShell != tt.want.PowerShell { + t.Errorf( + "Client.UpdateCertificateStoreType() PowerShell = %v, want %v", + got.PowerShell, + tt.want.PowerShell, + ) + } } } - } - }) + }, + ) } } diff --git a/api/template.go b/api/template.go index 2cefd28..677cf04 100644 --- a/api/template.go +++ b/api/template.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -24,7 +38,10 @@ func (c *Client) GetTemplate(Id interface{}) (*GetTemplateResponse, error) { newId := Id.(int32) - resp, _, err := apiClient.TemplateApi.TemplateGetTemplate(context.Background(), newId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() + resp, _, err := apiClient.TemplateApi.TemplateGetTemplate( + context.Background(), + newId, + ).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute() if err != nil { return nil, err diff --git a/api/template_models.go b/api/template_models.go index c791142..526b8c4 100644 --- a/api/template_models.go +++ b/api/template_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type GetTemplateResponse struct { diff --git a/api/template_test.go b/api/template_test.go index e7f4afc..57ba533 100644 --- a/api/template_test.go +++ b/api/template_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_GetTemplate(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetTemplate(tt.args.Id) - if (err != nil) != tt.wantErr { - t.Errorf("GetTemplate() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetTemplate() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetTemplate(tt.args.Id) + if (err != nil) != tt.wantErr { + t.Errorf("GetTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetTemplate() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -58,21 +74,23 @@ func TestClient_GetTemplates(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetTemplates() - if (err != nil) != tt.wantErr { - t.Errorf("GetTemplates() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetTemplates() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetTemplates() + if (err != nil) != tt.wantErr { + t.Errorf("GetTemplates() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetTemplates() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -95,20 +113,22 @@ func TestClient_UpdateTemplate(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateTemplate(tt.args.uta) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateTemplate() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateTemplate() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateTemplate(tt.args.uta) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateTemplate() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/examples/createStore/main.go b/examples/createStore/main.go index 3d9ed52..4fe9325 100644 --- a/examples/createStore/main.go +++ b/examples/createStore/main.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package examples // diff --git a/examples/enrollPFX/main.go b/examples/enrollPFX/main.go index f00e8b0..d3fadff 100644 --- a/examples/enrollPFX/main.go +++ b/examples/enrollPFX/main.go @@ -1,9 +1,24 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package examples import ( "fmt" - "github.com/Keyfactor/keyfactor-go-client/api" "log" + + "github.com/Keyfactor/keyfactor-go-client/api" ) var HOSTNAME = "example.com" diff --git a/examples/security/main.go b/examples/security/main.go index 578ae5b..cdd2dfe 100644 --- a/examples/security/main.go +++ b/examples/security/main.go @@ -1,9 +1,24 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package examples import ( "fmt" - "github.com/Keyfactor/keyfactor-go-client/api" "log" + + "github.com/Keyfactor/keyfactor-go-client/api" ) var HOSTNAME = "" diff --git a/examples/test.go b/examples/test.go index 1ac9867..c8cd9b2 100644 --- a/examples/test.go +++ b/examples/test.go @@ -1,10 +1,25 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package examples import ( "fmt" - main2 "github.com/Keyfactor/keyfactor-go-client/api" "log" "os" + + main2 "github.com/Keyfactor/keyfactor-go-client/api" ) func main() { diff --git a/main.go b/main.go index 9829781..80d05bd 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( @@ -9,7 +23,7 @@ import ( func main() { var showVersion bool - version := "2.1.0" + version := "2.2.12" flag.BoolVar(&showVersion, "version", false, "Print version information.") flag.BoolVar(&showVersion, "v", false, "Print version information.") flag.Parse() diff --git a/v2/api/agent.go b/v2/api/agent.go index b7b0d06..bc0a870 100644 --- a/v2/api/agent.go +++ b/v2/api/agent.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/agent_models.go b/v2/api/agent_models.go index cbf2e97..ae84304 100644 --- a/v2/api/agent_models.go +++ b/v2/api/agent_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type Agent9x struct { diff --git a/v2/api/agent_test.go b/v2/api/agent_test.go index cf3f83d..c967bde 100644 --- a/v2/api/agent_test.go +++ b/v2/api/agent_test.go @@ -1,12 +1,27 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api_test import ( "fmt" - "github.com/Keyfactor/keyfactor-go-client/api" "io" "log" "os" "testing" + + "github.com/Keyfactor/keyfactor-go-client/api" ) const ( @@ -63,39 +78,41 @@ func TestClient_ApproveAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - agents, lErr := c.GetAgentList() - if lErr != nil { - t.Errorf("unable to list agents. %s", lErr) - return - } - foundAgent := false - var orchestrator api.Agent - for _, agent := range agents { - if agent.AgentId == tt.args.id || agent.ClientMachine == tt.args.clientName { - orchestrator = agent - foundAgent = true - break - } - } - if !foundAgent { - t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) - return - } - if orchestrator.Status == ApprovedAgentStatus { - _, err := c.DisApproveAgent(orchestrator.AgentId) - if (err != nil) != tt.wantErr { - t.Errorf("DisApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + t.Run( + tt.name, func(t *testing.T) { + agents, lErr := c.GetAgentList() + if lErr != nil { + t.Errorf("unable to list agents. %s", lErr) return } - } else { - _, err := c.ApproveAgent(orchestrator.AgentId) - if (err != nil) != tt.wantErr { - t.Errorf("ApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + foundAgent := false + var orchestrator api.Agent + for _, agent := range agents { + if agent.AgentId == tt.args.id || agent.ClientMachine == tt.args.clientName { + orchestrator = agent + foundAgent = true + break + } + } + if !foundAgent { + t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) return } - } - }) + if orchestrator.Status == ApprovedAgentStatus { + _, err := c.DisApproveAgent(orchestrator.AgentId) + if (err != nil) != tt.wantErr { + t.Errorf("DisApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + return + } + } else { + _, err := c.ApproveAgent(orchestrator.AgentId) + if (err != nil) != tt.wantErr { + t.Errorf("ApproveAgent() error = %v, wantErr %v", err, tt.wantErr) + return + } + } + }, + ) } } @@ -140,41 +157,43 @@ func TestClient_FetchAgentLogs(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.args.id == "" && tt.args.clientName == "" && !tt.wantErr { - t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, agentClientName) - return - } else if tt.args.id == "" { - agents, lErr := c.GetAgentList() - if lErr != nil && !tt.wantErr { - t.Errorf("unable to list agents. %s", lErr) + t.Run( + tt.name, func(t *testing.T) { + if tt.args.id == "" && tt.args.clientName == "" && !tt.wantErr { + t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, agentClientName) return - } - foundAgent := false - for _, agent := range agents { - if agent.ClientMachine == tt.args.clientName { - tt.args.id = agent.AgentId - foundAgent = true - break + } else if tt.args.id == "" { + agents, lErr := c.GetAgentList() + if lErr != nil && !tt.wantErr { + t.Errorf("unable to list agents. %s", lErr) + return + } + foundAgent := false + for _, agent := range agents { + if agent.ClientMachine == tt.args.clientName { + tt.args.id = agent.AgentId + foundAgent = true + break + } + } + if !foundAgent && !tt.wantErr { + t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) + return } } - if !foundAgent && !tt.wantErr { - t.Errorf("unable to find agent with id %s or client name %s", tt.args.id, tt.args.clientName) + got, err := c.FetchAgentLogs(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("FetchAgentLogs() error = %v, wantErr %v", err, tt.wantErr) return } - } - got, err := c.FetchAgentLogs(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("FetchAgentLogs() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check returned message - if got != tt.want { - t.Errorf("FetchAgentLogs() got = %v, want %v", got, tt.want) + if !tt.wantErr { + // Check returned message + if got != tt.want { + t.Errorf("FetchAgentLogs() got = %v, want %v", got, tt.want) + } } - } - }) + }, + ) } } @@ -216,26 +235,28 @@ func TestClient_GetAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run( + tt.name, func(t *testing.T) { - got, err := c.GetAgent(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("GetAgent() error = %v, wantErr %v", err, tt.wantErr) - return - } - // Check that length of the array is greater than 0 - if !tt.wantErr { - if len(got) == 0 { - t.Errorf("GetAgent() got %d records, want %d record(s).\n", len(got), 1) + got, err := c.GetAgent(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("GetAgent() error = %v, wantErr %v", err, tt.wantErr) return } - // Check returned agent name - if got[0].ClientMachine != tt.args.id { - t.Errorf("GetAgent() got %s, want %s.\n", got[0].ClientMachine, tt.args.id) - return + // Check that length of the array is greater than 0 + if !tt.wantErr { + if len(got) == 0 { + t.Errorf("GetAgent() got %d records, want %d record(s).\n", len(got), 1) + return + } + // Check returned agent name + if got[0].ClientMachine != tt.args.id { + t.Errorf("GetAgent() got %s, want %s.\n", got[0].ClientMachine, tt.args.id) + return + } } - } - }) + }, + ) } } @@ -263,26 +284,28 @@ func TestClient_GetAgentList(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run( + tt.name, func(t *testing.T) { - got, err := c.GetAgentList() - if (err != nil) != tt.wantErr { - t.Errorf("GetAgentList() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that length of the array is greater than 0 - if len(got) == 0 { - t.Errorf("GetAgentList() got %d records, want at least %d record(s).\n", len(got), 1) + got, err := c.GetAgentList() + if (err != nil) != tt.wantErr { + t.Errorf("GetAgentList() error = %v, wantErr %v", err, tt.wantErr) return } - // Check returned agent name - if got[0].ClientMachine == "" { - t.Errorf("GetAgentList() got empty agent name, want non-empty agent name.\n") - return + if !tt.wantErr { + // Check that length of the array is greater than 0 + if len(got) == 0 { + t.Errorf("GetAgentList() got %d records, want at least %d record(s).\n", len(got), 1) + return + } + // Check returned agent name + if got[0].ClientMachine == "" { + t.Errorf("GetAgentList() got empty agent name, want non-empty agent name.\n") + return + } } - } - }) + }, + ) } } @@ -344,49 +367,51 @@ func TestClient_ResetAgent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.args.id == "" && tt.args.clientName == "" { - t.Errorf("TestClient_ResetAgent() missing agent ID or agent name. Please set TEST_KEYFACTOR_AGENT_ID and TEST_KEYFACTOR_AGENT_NAME environment variables and try again.") - return - } + t.Run( + tt.name, func(t *testing.T) { + if tt.args.id == "" && tt.args.clientName == "" { + t.Errorf("TestClient_ResetAgent() missing agent ID or agent name. Please set TEST_KEYFACTOR_AGENT_ID and TEST_KEYFACTOR_AGENT_NAME environment variables and try again.") + return + } - aID, aErr := c.GetAgent(tt.args.clientName) - if aErr != nil && !tt.wantErr { - t.Errorf("ResetAgent() error = %v, wantErr %v", aErr, tt.wantErr) - return - } - var got string - var err error - if tt.args.action == AgentActionReset { - if aID != nil && len(aID) > 0 { - got, err = c.ResetAgent(aID[0].AgentId) - } else { - got, err = c.ResetAgent(tt.args.id) + aID, aErr := c.GetAgent(tt.args.clientName) + if aErr != nil && !tt.wantErr { + t.Errorf("ResetAgent() error = %v, wantErr %v", aErr, tt.wantErr) + return } - } else if tt.args.action == AgentActionApprove { - if aID != nil && len(aID) > 0 { - got, err = c.ApproveAgent(aID[0].AgentId) - } else { - got, err = c.ApproveAgent(tt.args.id) + var got string + var err error + if tt.args.action == AgentActionReset { + if aID != nil && len(aID) > 0 { + got, err = c.ResetAgent(aID[0].AgentId) + } else { + got, err = c.ResetAgent(tt.args.id) + } + } else if tt.args.action == AgentActionApprove { + if aID != nil && len(aID) > 0 { + got, err = c.ApproveAgent(aID[0].AgentId) + } else { + got, err = c.ApproveAgent(tt.args.id) + } } - } - if (err != nil) != tt.wantErr { - t.Errorf("ResetAgent() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that length of the array is greater than 0 - if got != tt.want { - t.Errorf("ResetAgent() got %s, want %s.\n", got, tt.want) + if (err != nil) != tt.wantErr { + t.Errorf("ResetAgent() error = %v, wantErr %v", err, tt.wantErr) return } - } else { - errStr := fmt.Sprintf("%s", err) - if errStr != tt.want { - t.Errorf("ResetAgent() got %s, want %s.\n", err, tt.want) - return + if !tt.wantErr { + // Check that length of the array is greater than 0 + if got != tt.want { + t.Errorf("ResetAgent() got %s, want %s.\n", got, tt.want) + return + } + } else { + errStr := fmt.Sprintf("%s", err) + if errStr != tt.want { + t.Errorf("ResetAgent() got %s, want %s.\n", err, tt.want) + return + } } - } - }) + }, + ) } } diff --git a/v2/api/ca.go b/v2/api/ca.go index f852a7a..7f75bff 100644 --- a/v2/api/ca.go +++ b/v2/api/ca.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/ca_models.go b/v2/api/ca_models.go index a30135a..27fc82e 100644 --- a/v2/api/ca_models.go +++ b/v2/api/ca_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type CA struct { diff --git a/v2/api/ca_test.go b/v2/api/ca_test.go index 8a3bf20..593397d 100644 --- a/v2/api/ca_test.go +++ b/v2/api/ca_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -21,20 +35,22 @@ func TestClient_GetCAList(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCAList() - if (err != nil) != tt.wantErr { - t.Errorf("GetCAList() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCAList() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCAList() + if (err != nil) != tt.wantErr { + t.Errorf("GetCAList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCAList() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/v2/api/certificate.go b/v2/api/certificate.go index ab7c280..7a80faf 100644 --- a/v2/api/certificate.go +++ b/v2/api/certificate.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/certificate_models.go b/v2/api/certificate_models.go index bbb1394..98604f6 100644 --- a/v2/api/certificate_models.go +++ b/v2/api/certificate_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // SANs holds arrays of strings associated with IPv4 (IP4), IPv6 (IP6), DNS, and URI SANs. diff --git a/v2/api/certificate_test.go b/v2/api/certificate_test.go index 783233b..5c4c9b3 100644 --- a/v2/api/certificate_test.go +++ b/v2/api/certificate_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // diff --git a/v2/api/client.go b/v2/api/client.go index a94667f..f4e6bd2 100644 --- a/v2/api/client.go +++ b/v2/api/client.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/client_models.go b/v2/api/client_models.go index fc9132c..8a21fca 100644 --- a/v2/api/client_models.go +++ b/v2/api/client_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // StringTuple is a struct holding two string elements used by the Keyfactor diff --git a/v2/api/client_test.go b/v2/api/client_test.go index a8aade9..e7fcd01 100644 --- a/v2/api/client_test.go +++ b/v2/api/client_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_sendRequest(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.sendRequest(tt.args.request) - if (err != nil) != tt.wantErr { - t.Errorf("sendRequest() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("sendRequest() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.sendRequest(tt.args.request) + if (err != nil) != tt.wantErr { + t.Errorf("sendRequest() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("sendRequest() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -56,16 +72,18 @@ func TestNewKeyfactorClient(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewKeyfactorClient(tt.args.auth) - if (err != nil) != tt.wantErr { - t.Errorf("NewKeyfactorClient() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewKeyfactorClient() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + got, err := NewKeyfactorClient(tt.args.auth) + if (err != nil) != tt.wantErr { + t.Errorf("NewKeyfactorClient() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewKeyfactorClient() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -81,11 +99,13 @@ func Test_buildBasicAuthString(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := buildBasicAuthString(tt.args.auth); got != tt.want { - t.Errorf("buildBasicAuthString() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := buildBasicAuthString(tt.args.auth); got != tt.want { + t.Errorf("buildBasicAuthString() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -97,11 +117,13 @@ func Test_getTimestamp(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := getTimestamp(); got != tt.want { - t.Errorf("getTimestamp() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := getTimestamp(); got != tt.want { + t.Errorf("getTimestamp() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -118,15 +140,17 @@ func Test_loginToKeyfactor(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := loginToKeyfactor(tt.args.auth) - if (err != nil) != tt.wantErr { - t.Errorf("loginToKeyfactor() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("loginToKeyfactor() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + got, err := loginToKeyfactor(tt.args.auth) + if (err != nil) != tt.wantErr { + t.Errorf("loginToKeyfactor() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("loginToKeyfactor() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/v2/api/constants.go b/v2/api/constants.go index 179698f..56804cf 100644 --- a/v2/api/constants.go +++ b/v2/api/constants.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api const ( diff --git a/v2/api/metadata.go b/v2/api/metadata.go index 1cdffdd..f494a57 100644 --- a/v2/api/metadata.go +++ b/v2/api/metadata.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/metadata_models.go b/v2/api/metadata_models.go index d44e98b..da90437 100644 --- a/v2/api/metadata_models.go +++ b/v2/api/metadata_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // UpdateMetadataArgs holds the function arguments used for calling the UpdateMetadata method. diff --git a/v2/api/metadata_test.go b/v2/api/metadata_test.go index 60708b1..ab80d9e 100644 --- a/v2/api/metadata_test.go +++ b/v2/api/metadata_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -21,21 +35,23 @@ func TestClient_GetAllMetadataFields(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetAllMetadataFields() - if (err != nil) != tt.wantErr { - t.Errorf("GetAllMetadataFields() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetAllMetadataFields() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetAllMetadataFields() + if (err != nil) != tt.wantErr { + t.Errorf("GetAllMetadataFields() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetAllMetadataFields() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -57,15 +73,17 @@ func TestClient_UpdateMetadata(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.UpdateMetadata(tt.args.um); (err != nil) != tt.wantErr { - t.Errorf("UpdateMetadata() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.UpdateMetadata(tt.args.um); (err != nil) != tt.wantErr { + t.Errorf("UpdateMetadata() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } diff --git a/v2/api/security.go b/v2/api/security.go index 7285714..1a6cb92 100644 --- a/v2/api/security.go +++ b/v2/api/security.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/security_models.go b/v2/api/security_models.go index 078360a..61fab40 100644 --- a/v2/api/security_models.go +++ b/v2/api/security_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // GetSecurityIdentityResponse holds the response data returned by /Security/Identities diff --git a/v2/api/security_test.go b/v2/api/security_test.go index 032b583..72c49bf 100644 --- a/v2/api/security_test.go +++ b/v2/api/security_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_CreateSecurityIdentity(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateSecurityIdentity(tt.args.csia) - if (err != nil) != tt.wantErr { - t.Errorf("CreateSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateSecurityIdentity() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateSecurityIdentity(tt.args.csia) + if (err != nil) != tt.wantErr { + t.Errorf("CreateSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateSecurityIdentity() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -62,21 +78,23 @@ func TestClient_CreateSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateSecurityRole(tt.args.input) - if (err != nil) != tt.wantErr { - t.Errorf("CreateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateSecurityRole(tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("CreateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -98,16 +116,18 @@ func TestClient_DeleteSecurityIdentity(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteSecurityIdentity(tt.args.id); (err != nil) != tt.wantErr { - t.Errorf("DeleteSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteSecurityIdentity(tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("DeleteSecurityIdentity() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -129,16 +149,18 @@ func TestClient_DeleteSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteSecurityRole(tt.args.id); (err != nil) != tt.wantErr { - t.Errorf("DeleteSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteSecurityRole(tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("DeleteSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -157,21 +179,23 @@ func TestClient_GetSecurityIdentities(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityIdentities() - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityIdentities() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityIdentities() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityIdentities() + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityIdentities() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityIdentities() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -194,21 +218,23 @@ func TestClient_GetSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityRole(tt.args.id) - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityRole(tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -227,21 +253,23 @@ func TestClient_GetSecurityRoles(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetSecurityRoles() - if (err != nil) != tt.wantErr { - t.Errorf("GetSecurityRoles() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetSecurityRoles() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetSecurityRoles() + if (err != nil) != tt.wantErr { + t.Errorf("GetSecurityRoles() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetSecurityRoles() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -264,20 +292,22 @@ func TestClient_UpdateSecurityRole(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateSecurityRole(tt.args.input) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateSecurityRole() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateSecurityRole(tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateSecurityRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateSecurityRole() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/v2/api/store.go b/v2/api/store.go index 306459a..1624b8b 100644 --- a/v2/api/store.go +++ b/v2/api/store.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/store_container.go b/v2/api/store_container.go index 812ddbe..844811b 100644 --- a/v2/api/store_container.go +++ b/v2/api/store_container.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/store_container_models.go b/v2/api/store_container_models.go index c2bb371..3f5c0f9 100644 --- a/v2/api/store_container_models.go +++ b/v2/api/store_container_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // CertStoreContainer holds the function arguments used for calling the GetStoreContainers method. diff --git a/v2/api/store_container_test.go b/v2/api/store_container_test.go index 590fbba..821a838 100644 --- a/v2/api/store_container_test.go +++ b/v2/api/store_container_test.go @@ -1,12 +1,27 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api_test import ( - "github.com/Keyfactor/keyfactor-go-client/api" "io" "log" "os" "strconv" "testing" + + "github.com/Keyfactor/keyfactor-go-client/api" ) func TestClient_GetStoreContainer(t *testing.T) { @@ -68,36 +83,38 @@ func TestClient_GetStoreContainer(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var idInt int - _, cErr := strconv.Atoi(tt.args.id.(string)) - var got *api.CertStoreContainer - var err error - if cErr == nil { - idInt, _ = strconv.Atoi(tt.args.id.(string)) - got, err = c.GetStoreContainer(idInt) // GET Store container by ID - } else { - got, err = c.GetStoreContainer(tt.args.id) // GET Store container by name - } - - if (err != nil) != tt.wantErr { - t.Errorf("GetStoreContainer() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { + t.Run( + tt.name, func(t *testing.T) { + var idInt int + _, cErr := strconv.Atoi(tt.args.id.(string)) + var got *api.CertStoreContainer + var err error if cErr == nil { - // Check that ID is correct - if *got.Id != idInt { - t.Errorf("GetStoreContainer() got = %v, want %v", got.Id, idInt) - } + idInt, _ = strconv.Atoi(tt.args.id.(string)) + got, err = c.GetStoreContainer(idInt) // GET Store container by ID } else { - // Check that name is correct - if got.Name != tt.args.id { - t.Errorf("GetStoreContainer() got = %v, want %v", got.Name, tt.args.id) + got, err = c.GetStoreContainer(tt.args.id) // GET Store container by name + } + + if (err != nil) != tt.wantErr { + t.Errorf("GetStoreContainer() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !tt.wantErr { + if cErr == nil { + // Check that ID is correct + if *got.Id != idInt { + t.Errorf("GetStoreContainer() got = %v, want %v", got.Id, idInt) + } + } else { + // Check that name is correct + if got.Name != tt.args.id { + t.Errorf("GetStoreContainer() got = %v, want %v", got.Name, tt.args.id) + } } } - } - }) + }, + ) } } @@ -125,18 +142,20 @@ func TestClient_GetStoreContainers(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := c.GetStoreContainers() - if (err != nil) != tt.wantErr { - t.Errorf("GetStoreContainers() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - // Check that we got at least one store container - if len(*got) == 0 { - t.Errorf("GetStoreContainers() got = %v, want %v", got, tt.want) + t.Run( + tt.name, func(t *testing.T) { + got, err := c.GetStoreContainers() + if (err != nil) != tt.wantErr { + t.Errorf("GetStoreContainers() error = %v, wantErr %v", err, tt.wantErr) + return } - } - }) + if !tt.wantErr { + // Check that we got at least one store container + if len(*got) == 0 { + t.Errorf("GetStoreContainers() got = %v, want %v", got, tt.want) + } + } + }, + ) } } diff --git a/v2/api/store_models.go b/v2/api/store_models.go index 4c76139..5938e6a 100644 --- a/v2/api/store_models.go +++ b/v2/api/store_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api // CreateStoreFctArgs holds the function arguments used for calling the CreateStore method. diff --git a/v2/api/store_test.go b/v2/api/store_test.go index 2886cb6..9da8e1e 100644 --- a/v2/api/store_test.go +++ b/v2/api/store_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_AddCertificateToStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.AddCertificateToStores(tt.args.config) - if (err != nil) != tt.wantErr { - t.Errorf("AddCertificateToStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("AddCertificateToStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.AddCertificateToStores(tt.args.config) + if (err != nil) != tt.wantErr { + t.Errorf("AddCertificateToStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("AddCertificateToStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -62,21 +78,23 @@ func TestClient_CreateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.CreateStore(tt.args.ca) - if (err != nil) != tt.wantErr { - t.Errorf("CreateStore() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateStore() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.CreateStore(tt.args.ca) + if (err != nil) != tt.wantErr { + t.Errorf("CreateStore() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateStore() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -98,16 +116,18 @@ func TestClient_DeleteCertificateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - if err := c.DeleteCertificateStore(tt.args.storeId); (err != nil) != tt.wantErr { - t.Errorf("DeleteCertificateStore() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + if err := c.DeleteCertificateStore(tt.args.storeId); (err != nil) != tt.wantErr { + t.Errorf("DeleteCertificateStore() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -130,21 +150,23 @@ func TestClient_GetCertStoreInventory(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCertStoreInventory(tt.args.storeId) - if (err != nil) != tt.wantErr { - t.Errorf("GetCertStoreInventory() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCertStoreInventory() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCertStoreInventory(tt.args.storeId) + if (err != nil) != tt.wantErr { + t.Errorf("GetCertStoreInventory() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCertStoreInventory() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -167,21 +189,23 @@ func TestClient_GetCertificateStoreByID(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetCertificateStoreByID(tt.args.storeId) - if (err != nil) != tt.wantErr { - t.Errorf("GetCertificateStoreByID() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCertificateStoreByID() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetCertificateStoreByID(tt.args.storeId) + if (err != nil) != tt.wantErr { + t.Errorf("GetCertificateStoreByID() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCertificateStoreByID() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -200,21 +224,23 @@ func TestClient_ListCertificateStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.ListCertificateStores(nil) - if (err != nil) != tt.wantErr { - t.Errorf("ListCertificateStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListCertificateStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.ListCertificateStores(nil) + if (err != nil) != tt.wantErr { + t.Errorf("ListCertificateStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ListCertificateStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -237,21 +263,23 @@ func TestClient_RemoveCertificateFromStores(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.RemoveCertificateFromStores(tt.args.config) - if (err != nil) != tt.wantErr { - t.Errorf("RemoveCertificateFromStores() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RemoveCertificateFromStores() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.RemoveCertificateFromStores(tt.args.config) + if (err != nil) != tt.wantErr { + t.Errorf("RemoveCertificateFromStores() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("RemoveCertificateFromStores() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -274,21 +302,23 @@ func TestClient_UpdateStore(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateStore(tt.args.ua) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateStore() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateStore() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateStore(tt.args.ua) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateStore() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateStore() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -304,11 +334,13 @@ func Test_buildPropertiesInterface(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := buildPropertiesInterface(tt.args.properties); !reflect.DeepEqual(got, tt.want) { - t.Errorf("buildPropertiesInterface() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := buildPropertiesInterface(tt.args.properties); !reflect.DeepEqual(got, tt.want) { + t.Errorf("buildPropertiesInterface() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -324,11 +356,13 @@ func Test_unmarshalPropertiesString(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := unmarshalPropertiesString(tt.args.properties); !reflect.DeepEqual(got, tt.want) { - t.Errorf("unmarshalPropertiesString() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := unmarshalPropertiesString(tt.args.properties); !reflect.DeepEqual(got, tt.want) { + t.Errorf("unmarshalPropertiesString() = %v, want %v", got, tt.want) + } + }, + ) } } @@ -344,11 +378,13 @@ func Test_validateCreateStoreArgs(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := validateCreateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { - t.Errorf("validateCreateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if err := validateCreateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { + t.Errorf("validateCreateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -364,10 +400,12 @@ func Test_validateUpdateStoreArgs(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := validateUpdateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { - t.Errorf("validateUpdateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if err := validateUpdateStoreArgs(tt.args.ca); (err != nil) != tt.wantErr { + t.Errorf("validateUpdateStoreArgs() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } diff --git a/v2/api/store_type.go b/v2/api/store_type.go index 92bec09..acca701 100644 --- a/v2/api/store_type.go +++ b/v2/api/store_type.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/store_type_models.go b/v2/api/store_type_models.go index 0e2b813..e116024 100644 --- a/v2/api/store_type_models.go +++ b/v2/api/store_type_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type CertificateStoreTypeGeneric struct { diff --git a/v2/api/store_type_test.go b/v2/api/store_type_test.go index 5bf9b87..2201d90 100644 --- a/v2/api/store_type_test.go +++ b/v2/api/store_type_test.go @@ -1,10 +1,25 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api_test import ( - "github.com/Keyfactor/keyfactor-go-client/api" "io" "log" "testing" + + "github.com/Keyfactor/keyfactor-go-client/api" ) const ( @@ -62,48 +77,39 @@ var testStoreType = &api.CertificateStoreType{ func runStoreTypeTests(t *testing.T, tests []storeTypeTest, c *api.Client) { for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - switch tt.args.action { - case ActionCreate: - got, err := c.CreateStoreType(tt.args.storeType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.CreateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name != tt.want.Name { - t.Errorf("Client.CreateStoreType() = %v, want %v", got, tt.want) + t.Run( + tt.name, func(t *testing.T) { + switch tt.args.action { + case ActionCreate: + got, err := c.CreateStoreType(tt.args.storeType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.CreateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return } - } - case ActionDelete: - s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) - if gErr != nil { - t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) - return - } - got, err := c.DeleteCertificateStoreType(s.StoreType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.DeleteStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.ID <= 0 { - t.Errorf("Client.DeleteStoreType() = %v, want %v", got, tt.want) + if !tt.wantErr { + if got.Name != tt.want.Name { + t.Errorf("Client.CreateStoreType() = %v, want %v", got, tt.want) + } } - } - case ActionGet: - // Test Get by Name first - got, err := c.GetCertificateStoreType(tt.args.name) - if (err != nil) != tt.wantErr { - t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name != tt.want.Name { - t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) + case ActionDelete: + s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) + if gErr != nil { + t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) + return + } + got, err := c.DeleteCertificateStoreType(s.StoreType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.DeleteStoreType() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !tt.wantErr { + if got.ID <= 0 { + t.Errorf("Client.DeleteStoreType() = %v, want %v", got, tt.want) + } } - // Test Get by ID - got, err = c.GetCertificateStoreType(got.StoreType) + case ActionGet: + // Test Get by Name first + got, err := c.GetCertificateStoreType(tt.args.name) if (err != nil) != tt.wantErr { t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) return @@ -112,47 +118,66 @@ func runStoreTypeTests(t *testing.T, tests []storeTypeTest, c *api.Client) { if got.Name != tt.want.Name { t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) } + // Test Get by ID + got, err = c.GetCertificateStoreType(got.StoreType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.GetCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !tt.wantErr { + if got.Name != tt.want.Name { + t.Errorf("Client.GetCertificateStoreType() = %v, want %v", got, tt.want) + } + } } - } - case ActionList: - got, err := c.ListCertificateStoreTypes() - if (err != nil) != tt.wantErr { - t.Errorf("Client.ListCertificateStoreTypes() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if len(*got) <= 0 { - t.Errorf("Client.ListCertificateStoreTypes() = %v, want > %v", got, 1) + case ActionList: + got, err := c.ListCertificateStoreTypes() + if (err != nil) != tt.wantErr { + t.Errorf("Client.ListCertificateStoreTypes() error = %v, wantErr %v", err, tt.wantErr) + return } - } - case ActionUpdate: - s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) - if gErr != nil { - t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) - return - } - tt.args.storeType.StoreType = s.StoreType - tt.args.storeType.ImportType = s.ImportType - got, err := c.UpdateStoreType(tt.args.storeType) - if (err != nil) != tt.wantErr { - t.Errorf("Client.UpdateCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !tt.wantErr { - if got.Name == testStoreType.Name { - t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got.Name, tt.want.Name) - } else if got.Name != tt.want.Name { - t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got, tt.want) + if !tt.wantErr { + if len(*got) <= 0 { + t.Errorf("Client.ListCertificateStoreTypes() = %v, want > %v", got, 1) + } + } + case ActionUpdate: + s, gErr := c.GetCertificateStoreType(tt.args.storeType.ShortName) + if gErr != nil { + t.Errorf("Unable to cleanup created store %s. error = %v", tt.args.storeType.Name, gErr) + return + } + tt.args.storeType.StoreType = s.StoreType + tt.args.storeType.ImportType = s.ImportType + got, err := c.UpdateStoreType(tt.args.storeType) + if (err != nil) != tt.wantErr { + t.Errorf("Client.UpdateCertificateStoreType() error = %v, wantErr %v", err, tt.wantErr) + return } - if got.PowerShell == testStoreType.PowerShell { - t.Errorf("Client.UpdateCertificateStoreType() PowerShell = %v, want %v", got.PowerShell, !testStoreType.PowerShell) - } else if got.PowerShell != tt.want.PowerShell { - t.Errorf("Client.UpdateCertificateStoreType() PowerShell = %v, want %v", got.PowerShell, tt.want.PowerShell) + if !tt.wantErr { + if got.Name == testStoreType.Name { + t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got.Name, tt.want.Name) + } else if got.Name != tt.want.Name { + t.Errorf("Client.UpdateCertificateStoreType() = %v, want %v", got, tt.want) + } + if got.PowerShell == testStoreType.PowerShell { + t.Errorf( + "Client.UpdateCertificateStoreType() PowerShell = %v, want %v", + got.PowerShell, + !testStoreType.PowerShell, + ) + } else if got.PowerShell != tt.want.PowerShell { + t.Errorf( + "Client.UpdateCertificateStoreType() PowerShell = %v, want %v", + got.PowerShell, + tt.want.PowerShell, + ) + } } } - } - }) + }, + ) } } diff --git a/v2/api/template.go b/v2/api/template.go index 0d54e66..73e7423 100644 --- a/v2/api/template.go +++ b/v2/api/template.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( diff --git a/v2/api/template_models.go b/v2/api/template_models.go index c791142..526b8c4 100644 --- a/v2/api/template_models.go +++ b/v2/api/template_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api type GetTemplateResponse struct { diff --git a/v2/api/template_test.go b/v2/api/template_test.go index 1807d79..2012a07 100644 --- a/v2/api/template_test.go +++ b/v2/api/template_test.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -25,21 +39,23 @@ func TestClient_GetTemplate(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetTemplate(tt.args.Id) - if (err != nil) != tt.wantErr { - t.Errorf("GetTemplate() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetTemplate() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetTemplate(tt.args.Id) + if (err != nil) != tt.wantErr { + t.Errorf("GetTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetTemplate() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -58,21 +74,23 @@ func TestClient_GetTemplates(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.GetTemplates() - if (err != nil) != tt.wantErr { - t.Errorf("GetTemplates() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetTemplates() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.GetTemplates() + if (err != nil) != tt.wantErr { + t.Errorf("GetTemplates() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetTemplates() got = %v, want %v", got, tt.want) + } + }, + ) } } @@ -95,20 +113,22 @@ func TestClient_UpdateTemplate(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Client{ - Hostname: tt.fields.hostname, - httpClient: tt.fields.httpClient, - basicAuthString: tt.fields.basicAuthString, - } - got, err := c.UpdateTemplate(tt.args.uta) - if (err != nil) != tt.wantErr { - t.Errorf("UpdateTemplate() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateTemplate() got = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := &Client{ + Hostname: tt.fields.hostname, + httpClient: tt.fields.httpClient, + basicAuthString: tt.fields.basicAuthString, + } + got, err := c.UpdateTemplate(tt.args.uta) + if (err != nil) != tt.wantErr { + t.Errorf("UpdateTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateTemplate() got = %v, want %v", got, tt.want) + } + }, + ) } } diff --git a/v2/api/workflow.go b/v2/api/workflow.go index 7b78f07..a999b95 100644 --- a/v2/api/workflow.go +++ b/v2/api/workflow.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import ( @@ -28,9 +42,11 @@ func (c *Client) ListWorkflowCert(endpoint string) ([]WorkflowCertificate, error query := apiQuery{ Query: []StringTuple{}, } - query.Query = append(query.Query, StringTuple{ - "pagedQuery.returnLimit", "1000", - }) + query.Query = append( + query.Query, StringTuple{ + "pagedQuery.returnLimit", "1000", + }, + ) keyfactorAPIStruct := &request{ Method: "GET", diff --git a/v2/api/workflow_models.go b/v2/api/workflow_models.go index 26cbe18..27221ab 100644 --- a/v2/api/workflow_models.go +++ b/v2/api/workflow_models.go @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package api import "time" diff --git a/v2/go.mod b/v2/go.mod index e92e68f..1a8329e 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -1,3 +1,17 @@ +// Copyright 2024 Keyfactor +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + module github.com/Keyfactor/keyfactor-go-client/v2 go 1.21