Skip to content

Commit 7a7be14

Browse files
committed
feat(cli): Added scaffolding for store containers, orchs(orchestrators/agents), and status
1 parent 3d4a2f7 commit 7a7be14

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed

cmd/containers.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// containersCmd represents the containers command
14+
var containersCmd = &cobra.Command{
15+
Use: "containers",
16+
Short: "Keyfactor CertificateStoreContainer API and utilities.",
17+
Long: `A collections of APIs and utilities for interacting with Keyfactor certificate store containers.`,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
fmt.Println("containers called")
20+
},
21+
}
22+
23+
var containersCreateCmd = &cobra.Command{
24+
Use: "create",
25+
Short: "Create certificate store container.",
26+
Long: `Create certificate store container.`,
27+
Run: func(cmd *cobra.Command, args []string) {
28+
fmt.Println("containers create called")
29+
},
30+
}
31+
32+
var containersGetCmd = &cobra.Command{
33+
Use: "get",
34+
Short: "Get certificate store container by ID or name.",
35+
Long: `Get certificate store container by ID or name.`,
36+
Run: func(cmd *cobra.Command, args []string) {
37+
fmt.Println("containers get called")
38+
},
39+
}
40+
41+
var containersUpdateCmd = &cobra.Command{
42+
Use: "update",
43+
Short: "Update certificate store container by ID or name.",
44+
Long: `Update certificate store container by ID or name.`,
45+
Run: func(cmd *cobra.Command, args []string) {
46+
fmt.Println("containers update called")
47+
},
48+
}
49+
50+
var containersDeleteCmd = &cobra.Command{
51+
Use: "delete",
52+
Short: "Delete certificate store container by ID or name.",
53+
Long: `Delete certificate store container by ID or name.`,
54+
Run: func(cmd *cobra.Command, args []string) {
55+
fmt.Println("containers delete called")
56+
},
57+
}
58+
59+
var containersListCmd = &cobra.Command{
60+
Use: "list",
61+
Short: "List certificate store containers.",
62+
Long: `List certificate store containers.`,
63+
Run: func(cmd *cobra.Command, args []string) {
64+
fmt.Println("containers list called")
65+
},
66+
}
67+
68+
func init() {
69+
rootCmd.AddCommand(containersCmd)
70+
71+
// LIST containers command
72+
containersCmd.AddCommand(containersListCmd)
73+
// GET containers command
74+
containersCmd.AddCommand(containersGetCmd)
75+
// CREATE containers command
76+
containersCmd.AddCommand(containersCreateCmd)
77+
// UPDATE containers command
78+
containersCmd.AddCommand(containersUpdateCmd)
79+
// DELETE containers command
80+
containersCmd.AddCommand(containersDeleteCmd)
81+
82+
// Utility functions
83+
}

cmd/orchs.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
"io/ioutil"
11+
"log"
12+
13+
"github.com/spf13/cobra"
14+
)
15+
16+
// orchsCmd represents the orchs command
17+
var orchsCmd = &cobra.Command{
18+
Use: "orchs",
19+
Short: "Keyfactor agents APIs and utilities.",
20+
Long: `A collections of APIs and utilities for interacting with Keyfactor orchestrators.`,
21+
}
22+
23+
var getOrchestratorCmd = &cobra.Command{
24+
Use: "get",
25+
Short: "Get orchestrator by ID or machine/host name.",
26+
Long: `Get orchestrator by ID or machine/host name.`,
27+
Run: func(cmd *cobra.Command, args []string) {
28+
fmt.Println("orchestrator get called")
29+
},
30+
}
31+
32+
var approveOrchestratorCmd = &cobra.Command{
33+
Use: "approve",
34+
Short: "Approve orchestrator by ID or machine/host name.",
35+
Long: `Approve orchestrator by ID or machine/host name.`,
36+
Run: func(cmd *cobra.Command, args []string) {
37+
fmt.Println("orchestrator approve called")
38+
},
39+
}
40+
41+
var disapproveOrchestratorCmd = &cobra.Command{
42+
Use: "disapprove",
43+
Short: "Disapprove orchestrator by ID or machine/host name.",
44+
Long: `Disapprove orchestrator by ID or machine/host name.`,
45+
Run: func(cmd *cobra.Command, args []string) {
46+
fmt.Println("orchestrator disapprove called")
47+
},
48+
}
49+
50+
var resetOrchestratorCmd = &cobra.Command{
51+
Use: "reset",
52+
Short: "Reset orchestrator by ID or machine/host name.",
53+
Long: `Reset orchestrator by ID or machine/host name.`,
54+
Run: func(cmd *cobra.Command, args []string) {
55+
fmt.Println("orchestrator reset called")
56+
},
57+
}
58+
59+
var getLogsOrchestratorCmd = &cobra.Command{
60+
Use: "logs",
61+
Short: "Get orchestrator logs by ID or machine/host name.",
62+
Long: `Get orchestrator logs by ID or machine/host name.`,
63+
Run: func(cmd *cobra.Command, args []string) {
64+
fmt.Println("orchestrator logs called")
65+
},
66+
}
67+
68+
var listOrchestratorsCmd = &cobra.Command{
69+
Use: "list",
70+
Short: "List orchestrators.",
71+
Long: `Returns a JSON list of Keyfactor orchestrators.`,
72+
Run: func(cmd *cobra.Command, args []string) {
73+
log.SetOutput(ioutil.Discard)
74+
kfClient, _ := initClient()
75+
agents, err := kfClient.GetAgentList()
76+
if err != nil {
77+
log.Printf("Error: %s", err)
78+
}
79+
output, jErr := json.Marshal(agents)
80+
if jErr != nil {
81+
log.Printf("Error: %s", jErr)
82+
}
83+
fmt.Printf("%s", output)
84+
},
85+
}
86+
87+
func init() {
88+
rootCmd.AddCommand(orchsCmd)
89+
90+
// LIST orchestrators command
91+
orchsCmd.AddCommand(listOrchestratorsCmd)
92+
// GET orchestrator command
93+
orchsCmd.AddCommand(getOrchestratorCmd)
94+
// CREATE orchestrator command TODO: API NOT SUPPORTED
95+
//orchsCmd.AddCommand(createOrchestratorCmd)
96+
// UPDATE orchestrator command TODO: API NOT SUPPORTED
97+
//orchsCmd.AddCommand(updateOrchestratorCmd)
98+
// DELETE orchestrator command TODO: API NOT SUPPORTED
99+
//orchsCmd.AddCommand(deleteOrchestratorCmd)
100+
// APPROVE orchestrator command
101+
orchsCmd.AddCommand(approveOrchestratorCmd)
102+
// DISAPPROVE orchestrator command
103+
orchsCmd.AddCommand(disapproveOrchestratorCmd)
104+
// RESET orchestrator command
105+
orchsCmd.AddCommand(resetOrchestratorCmd)
106+
// GET orchestrator logs command
107+
orchsCmd.AddCommand(getLogsOrchestratorCmd)
108+
// SET orchestrator auth certificate reenrollment command TODO: Not implemented
109+
//orchsCmd.AddCommand(setOrchestratorAuthCertReenrollCmd)
110+
// Utility commands
111+
//orchsCmd.AddCommand(downloadOrchestrator) TODO: Not implemented
112+
}

cmd/rot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ func init() {
735735
rotReconcileCmd.Flags().IntVarP(&maxLeaves, "max-leaf-certs", "n", -1,
736736
"The max number of non-root-certs that should be in a store to be considered a 'root' store. If set to `-1` then all stores will be considered.")
737737
rotReconcileCmd.Flags().BoolP("dry-run", "d", false, "Dry run mode")
738+
rotReconcileCmd.Flags().BoolP("import-csv", "v", false, "Dry run mode")
738739
//rotReconcileCmd.MarkFlagsRequiredTogether("add-certs", "stores")
739740
//rotReconcileCmd.MarkFlagsRequiredTogether("remove-certs", "stores")
740741
rotReconcileCmd.MarkFlagsMutuallyExclusive("add-certs", "actions")

cmd/status.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// statusCmd represents the status command
13+
var statusCmd = &cobra.Command{
14+
Use: "status",
15+
Short: "List the status of Keyfactor services.",
16+
Long: `Returns a list of all API endpoints.`,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
//log.SetOutput(ioutil.Discard)
19+
//kfClient, _ := initClient()
20+
//status, err := kfClient.GetStatus()
21+
//if err != nil {
22+
// log.Printf("Error: %s", err)
23+
//}
24+
//output, jErr := json.Marshal(status)
25+
//if jErr != nil {
26+
// log.Printf("Error: %s", jErr)
27+
//}
28+
//fmt.Printf("%s", output)
29+
//
30+
fmt.Println("status called")
31+
},
32+
}
33+
34+
func init() {
35+
rootCmd.AddCommand(statusCmd)
36+
37+
// Here you will define your flags and configuration settings.
38+
39+
// Cobra supports Persistent Flags which will work for this command
40+
// and all subcommands, e.g.:
41+
// statusCmd.PersistentFlags().String("foo", "", "A help for foo")
42+
43+
// Cobra supports local flags which will only run when this command
44+
// is called directly, e.g.:
45+
// statusCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
46+
}

0 commit comments

Comments
 (0)