44 "context"
55 "encoding/json"
66 "fmt"
7- keyfactor_command_client_api "github.com/Keyfactor/keyfactor-go-client-sdk"
7+ "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor "
88 "github.com/Keyfactor/keyfactor-go-client/api"
99 "github.com/spf13/cobra"
1010 "log"
@@ -26,21 +26,21 @@ var fSecurityRoles bool
2626var fAll bool
2727
2828type exportModelsReport struct {
29- Id * int32 `json:"-"`
30- Scheduled * int32 `json:"Scheduled,omitempty"`
31- DisplayName * string `json:"DisplayName,omitempty"`
32- Description * string `json:"Description,omitempty"`
33- ReportPath * string `json:"ReportPath,omitempty"`
34- VersionNumber * string `json:"VersionNumber,omitempty"`
35- Categories * string `json:"Categories,omitempty"`
36- ShortName * string `json:"ShortName,omitempty"`
37- InNavigator * bool `json:"InNavigator,omitempty"`
38- Favorite * bool `json:"Favorite,omitempty"`
39- RemoveDuplicates * bool `json:"RemoveDuplicates,omitempty"`
40- UsesCollection * bool `json:"UsesCollection,omitempty"`
41- ReportParameter []keyfactor_command_client_api .ModelsReportParameters `json:"ReportParameter,omitempty"`
42- Schedules []keyfactor_command_client_api .ModelsReportSchedule `json:"Schedules,omitempty"`
43- AcceptedScheduleFormats []string `json:"AcceptedScheduleFormats,omitempty"`
29+ Id * int32 `json:"-"`
30+ Scheduled * int32 `json:"Scheduled,omitempty"`
31+ DisplayName * string `json:"DisplayName,omitempty"`
32+ Description * string `json:"Description,omitempty"`
33+ ReportPath * string `json:"ReportPath,omitempty"`
34+ VersionNumber * string `json:"VersionNumber,omitempty"`
35+ Categories * string `json:"Categories,omitempty"`
36+ ShortName * string `json:"ShortName,omitempty"`
37+ InNavigator * bool `json:"InNavigator,omitempty"`
38+ Favorite * bool `json:"Favorite,omitempty"`
39+ RemoveDuplicates * bool `json:"RemoveDuplicates,omitempty"`
40+ UsesCollection * bool `json:"UsesCollection,omitempty"`
41+ ReportParameter []keyfactor .ModelsReportParameters `json:"ReportParameter,omitempty"`
42+ Schedules []keyfactor .ModelsReportSchedule `json:"Schedules,omitempty"`
43+ AcceptedScheduleFormats []string `json:"AcceptedScheduleFormats,omitempty"`
4444}
4545
4646type exportKeyfactorApiModelsWorkflowsDefinitionCreateRequest struct {
@@ -57,17 +57,17 @@ type exportKeyfactorApiModelsWorkflowsDefinitionCreateRequest struct {
5757}
5858
5959type outJson struct {
60- Collections []keyfactor_command_client_api .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest `json:"Collections"`
61- MetadataFields []keyfactor_command_client_api .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest `json:"MetadataFields"`
62- ExpirationAlerts []keyfactor_command_client_api .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest `json:"ExpirationAlerts"`
63- IssuedCertAlerts []keyfactor_command_client_api .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest `json:"IssuedCertAlerts"`
64- DeniedCertAlerts []keyfactor_command_client_api .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest `json:"DeniedCertAlerts"`
65- PendingCertAlerts []keyfactor_command_client_api .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest `json:"PendingCertAlerts"`
66- Networks []keyfactor_command_client_api .KeyfactorApiModelsSslCreateNetworkRequest `json:"Networks"`
67- WorkflowDefinitions []exportKeyfactorApiModelsWorkflowsDefinitionCreateRequest `json:"WorkflowDefinitions"`
68- BuiltInReports []exportModelsReport `json:"BuiltInReports"`
69- CustomReports []keyfactor_command_client_api .ModelsCustomReportCreationRequest `json:"CustomReports"`
70- SecurityRoles []api.CreateSecurityRoleArg `json:"SecurityRoles"`
60+ Collections []keyfactor .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest `json:"Collections"`
61+ MetadataFields []keyfactor .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest `json:"MetadataFields"`
62+ ExpirationAlerts []keyfactor .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest `json:"ExpirationAlerts"`
63+ IssuedCertAlerts []keyfactor .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest `json:"IssuedCertAlerts"`
64+ DeniedCertAlerts []keyfactor .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest `json:"DeniedCertAlerts"`
65+ PendingCertAlerts []keyfactor .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest `json:"PendingCertAlerts"`
66+ Networks []keyfactor .KeyfactorApiModelsSslCreateNetworkRequest `json:"Networks"`
67+ WorkflowDefinitions []exportKeyfactorApiModelsWorkflowsDefinitionCreateRequest `json:"WorkflowDefinitions"`
68+ BuiltInReports []exportModelsReport `json:"BuiltInReports"`
69+ CustomReports []keyfactor .ModelsCustomReportCreationRequest `json:"CustomReports"`
70+ SecurityRoles []api.CreateSecurityRoleArg `json:"SecurityRoles"`
7171}
7272
7373func exportToJSON (out outJson , exportPath string ) {
@@ -93,16 +93,16 @@ var exportCmd = &cobra.Command{
9393 Run : func (cmd * cobra.Command , args []string ) {
9494 // initialize each entry as an empty list in the event it is not requested by the flags
9595 out := outJson {
96- Collections : []keyfactor_command_client_api .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest {},
97- MetadataFields : []keyfactor_command_client_api .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest {},
98- ExpirationAlerts : []keyfactor_command_client_api .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest {},
99- IssuedCertAlerts : []keyfactor_command_client_api .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest {},
100- DeniedCertAlerts : []keyfactor_command_client_api .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {},
101- PendingCertAlerts : []keyfactor_command_client_api .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest {},
102- Networks : []keyfactor_command_client_api .KeyfactorApiModelsSslCreateNetworkRequest {},
96+ Collections : []keyfactor .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest {},
97+ MetadataFields : []keyfactor .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest {},
98+ ExpirationAlerts : []keyfactor .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest {},
99+ IssuedCertAlerts : []keyfactor .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest {},
100+ DeniedCertAlerts : []keyfactor .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {},
101+ PendingCertAlerts : []keyfactor .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest {},
102+ Networks : []keyfactor .KeyfactorApiModelsSslCreateNetworkRequest {},
103103 WorkflowDefinitions : []exportKeyfactorApiModelsWorkflowsDefinitionCreateRequest {},
104104 BuiltInReports : []exportModelsReport {},
105- CustomReports : []keyfactor_command_client_api .ModelsCustomReportCreationRequest {},
105+ CustomReports : []keyfactor .ModelsCustomReportCreationRequest {},
106106 SecurityRoles : []api.CreateSecurityRoleArg {},
107107 }
108108 exportPath := cmd .Flag ("file" ).Value .String ()
@@ -153,16 +153,16 @@ var exportCmd = &cobra.Command{
153153 },
154154}
155155
156- func getCollections () []keyfactor_command_client_api .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest {
156+ func getCollections () []keyfactor .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest {
157157 kfClient := initGenClient ()
158158 collections , _ , reqErr := kfClient .CertificateCollectionApi .CertificateCollectionGetCollections (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
159159 if reqErr != nil {
160160 fmt .Printf ("%s Error! Unable to get collections %s%s\n " , colorRed , reqErr , colorWhite )
161161 }
162- var lCollectionReq []keyfactor_command_client_api .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest
162+ var lCollectionReq []keyfactor .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest
163163 for _ , collection := range collections {
164164 cJson , _ := json .Marshal (collection )
165- var collectionReq keyfactor_command_client_api .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest
165+ var collectionReq keyfactor .KeyfactorApiModelsCertificateCollectionsCertificateCollectionCreateRequest
166166 jErr := json .Unmarshal (cJson , & collectionReq )
167167 if jErr != nil {
168168 fmt .Printf ("Error: %s\n " , jErr )
@@ -175,16 +175,16 @@ func getCollections() []keyfactor_command_client_api.KeyfactorApiModelsCertifica
175175 return lCollectionReq
176176}
177177
178- func getMetadata () []keyfactor_command_client_api .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest {
178+ func getMetadata () []keyfactor .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest {
179179 kfClient := initGenClient ()
180180 metadata , _ , reqErr := kfClient .MetadataFieldApi .MetadataFieldGetAllMetadataFields (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
181181 if reqErr != nil {
182182 fmt .Printf ("%s Error! Unable to get metadata %s%s\n " , colorRed , reqErr , colorWhite )
183183 }
184- var lMetadataReq []keyfactor_command_client_api .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest
184+ var lMetadataReq []keyfactor .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest
185185 for _ , metadataItem := range metadata {
186186 mJson , _ := json .Marshal (metadataItem )
187- var metadataReq keyfactor_command_client_api .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest
187+ var metadataReq keyfactor .KeyfactorApiModelsMetadataFieldMetadataFieldCreateRequest
188188 jErr := json .Unmarshal (mJson , & metadataReq )
189189 if jErr != nil {
190190 fmt .Printf ("Error: %s\n " , jErr )
@@ -196,16 +196,16 @@ func getMetadata() []keyfactor_command_client_api.KeyfactorApiModelsMetadataFiel
196196 return lMetadataReq
197197}
198198
199- func getExpirationAlerts () []keyfactor_command_client_api .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest {
199+ func getExpirationAlerts () []keyfactor .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest {
200200 kfClient := initGenClient ()
201201 alerts , _ , reqErr := kfClient .ExpirationAlertApi .ExpirationAlertGetExpirationAlerts (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
202202 if reqErr != nil {
203203 fmt .Printf ("%s Error! Unable to get expiration alerts %s%s\n " , colorRed , reqErr , colorWhite )
204204 }
205- var lAlertReq []keyfactor_command_client_api .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest
205+ var lAlertReq []keyfactor .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest
206206 for _ , alert := range alerts {
207207 mJson , _ := json .Marshal (alert )
208- var alertReq keyfactor_command_client_api .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest
208+ var alertReq keyfactor .KeyfactorApiModelsAlertsExpirationExpirationAlertCreationRequest
209209 jErr := json .Unmarshal (mJson , & alertReq )
210210 if jErr != nil {
211211 fmt .Printf ("Error: %s\n " , jErr )
@@ -216,16 +216,16 @@ func getExpirationAlerts() []keyfactor_command_client_api.KeyfactorApiModelsAler
216216 return lAlertReq
217217}
218218
219- func getIssuedAlerts () []keyfactor_command_client_api .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest {
219+ func getIssuedAlerts () []keyfactor .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest {
220220 kfClient := initGenClient ()
221221 alerts , _ , reqErr := kfClient .IssuedAlertApi .IssuedAlertGetIssuedAlerts (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
222222 if reqErr != nil {
223223 fmt .Printf ("%s Error! Unable to get issued cert alerts %s%s\n " , colorRed , reqErr , colorWhite )
224224 }
225- var lAlertReq []keyfactor_command_client_api .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest
225+ var lAlertReq []keyfactor .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest
226226 for _ , alert := range alerts {
227227 mJson , _ := json .Marshal (alert )
228- var alertReq keyfactor_command_client_api .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest
228+ var alertReq keyfactor .KeyfactorApiModelsAlertsIssuedIssuedAlertCreationRequest
229229 jErr := json .Unmarshal (mJson , & alertReq )
230230 if jErr != nil {
231231 fmt .Printf ("Error: %s\n " , jErr )
@@ -237,16 +237,16 @@ func getIssuedAlerts() []keyfactor_command_client_api.KeyfactorApiModelsAlertsIs
237237 return lAlertReq
238238}
239239
240- func getDeniedAlerts () []keyfactor_command_client_api .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {
240+ func getDeniedAlerts () []keyfactor .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {
241241 kfClient := initGenClient ()
242242 alerts , _ , reqErr := kfClient .DeniedAlertApi .DeniedAlertGetDeniedAlerts (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
243243 if reqErr != nil {
244244 fmt .Printf ("%s Error! Unable to get denied cert alerts %s%s\n " , colorRed , reqErr , colorWhite )
245245 }
246- var lAlertReq []keyfactor_command_client_api .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest
246+ var lAlertReq []keyfactor .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest
247247 for _ , alert := range alerts {
248248 mJson , _ := json .Marshal (alert )
249- var alertReq keyfactor_command_client_api .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest
249+ var alertReq keyfactor .KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest
250250 jErr := json .Unmarshal (mJson , & alertReq )
251251 if jErr != nil {
252252 fmt .Printf ("Error: %s\n " , jErr )
@@ -258,16 +258,16 @@ func getDeniedAlerts() []keyfactor_command_client_api.KeyfactorApiModelsAlertsDe
258258 return lAlertReq
259259}
260260
261- func getPendingAlerts () []keyfactor_command_client_api .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest {
261+ func getPendingAlerts () []keyfactor .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest {
262262 kfClient := initGenClient ()
263263 alerts , _ , reqErr := kfClient .PendingAlertApi .PendingAlertGetPendingAlerts (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
264264 if reqErr != nil {
265265 fmt .Printf ("%s Error! Unable to get pending cert alerts %s%s\n " , colorRed , reqErr , colorWhite )
266266 }
267- var lAlertReq []keyfactor_command_client_api .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest
267+ var lAlertReq []keyfactor .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest
268268 for _ , alert := range alerts {
269269 mJson , _ := json .Marshal (alert )
270- var alertReq keyfactor_command_client_api .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest
270+ var alertReq keyfactor .KeyfactorApiModelsAlertsPendingPendingAlertCreationRequest
271271 jErr := json .Unmarshal (mJson , & alertReq )
272272 if jErr != nil {
273273 fmt .Printf ("Error: %s\n " , jErr )
@@ -279,16 +279,16 @@ func getPendingAlerts() []keyfactor_command_client_api.KeyfactorApiModelsAlertsP
279279 return lAlertReq
280280}
281281
282- func getSslNetworks () []keyfactor_command_client_api .KeyfactorApiModelsSslCreateNetworkRequest {
282+ func getSslNetworks () []keyfactor .KeyfactorApiModelsSslCreateNetworkRequest {
283283 kfClient := initGenClient ()
284284 networks , _ , reqErr := kfClient .SslApi .SslGetNetworks (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
285285 if reqErr != nil {
286286 fmt .Printf ("%s Error! Unable to get SSL networks %s%s\n " , colorRed , reqErr , colorWhite )
287287 }
288- var lNetworkReq []keyfactor_command_client_api .KeyfactorApiModelsSslCreateNetworkRequest
288+ var lNetworkReq []keyfactor .KeyfactorApiModelsSslCreateNetworkRequest
289289 for _ , network := range networks {
290290 mJson , _ := json .Marshal (network )
291- var networkReq keyfactor_command_client_api .KeyfactorApiModelsSslCreateNetworkRequest
291+ var networkReq keyfactor .KeyfactorApiModelsSslCreateNetworkRequest
292292 jErr := json .Unmarshal (mJson , & networkReq )
293293 if jErr != nil {
294294 fmt .Printf ("Error: %s\n " , jErr )
@@ -326,7 +326,7 @@ func getWorkflowDefinitions() []exportKeyfactorApiModelsWorkflowsDefinitionCreat
326326 return lWorkflowReq
327327}
328328
329- func getReports () ([]exportModelsReport , []keyfactor_command_client_api .ModelsCustomReportCreationRequest ) {
329+ func getReports () ([]exportModelsReport , []keyfactor .ModelsCustomReportCreationRequest ) {
330330 kfClient := initGenClient ()
331331 //Gets all built-in reports
332332 bReports , _ , bErr := kfClient .ReportsApi .ReportsQueryReports (context .Background ()).XKeyfactorRequestedWith (xKeyfactorRequestedWith ).XKeyfactorApiVersion (xKeyfactorApiVersion ).Execute ()
@@ -350,10 +350,10 @@ func getReports() ([]exportModelsReport, []keyfactor_command_client_api.ModelsCu
350350 if cErr != nil {
351351 fmt .Printf ("%s Error! Unable to get custom reports %s%s\n " , colorRed , cErr , colorWhite )
352352 }
353- var lcReportReq []keyfactor_command_client_api .ModelsCustomReportCreationRequest
353+ var lcReportReq []keyfactor .ModelsCustomReportCreationRequest
354354 for _ , cReport := range cReports {
355355 mJson , _ := json .Marshal (cReport )
356- var cReportReq keyfactor_command_client_api .ModelsCustomReportCreationRequest
356+ var cReportReq keyfactor .ModelsCustomReportCreationRequest
357357 jErr := json .Unmarshal (mJson , & cReportReq )
358358 if jErr != nil {
359359 fmt .Printf ("Error: %s\n " , jErr )
@@ -387,7 +387,7 @@ func getRoles() []api.CreateSecurityRoleArg {
387387func init () {
388388 RootCmd .AddCommand (exportCmd )
389389
390- exportCmd .Flags ().StringVarP (& exportPath , "file" , "f" , "" , "export JSON to a specified filepath " )
390+ exportCmd .Flags ().StringVarP (& exportPath , "file" , "f" , "" , "path to JSON output file with exported data " )
391391 exportCmd .MarkFlagRequired ("file" )
392392
393393 exportCmd .Flags ().BoolVarP (& fAll , "all" , "a" , false , "export all exportable data to JSON file" )
0 commit comments