|
| 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 | +} |
0 commit comments