feat: added cacerts and some tidying

This commit is contained in:
David Allen 2025-08-31 22:02:10 -06:00
parent 2112e7eefd
commit bdd85b01ff
Signed by: towk
GPG key ID: 0430CDBE22619155
8 changed files with 279 additions and 59 deletions

View file

@ -37,12 +37,14 @@ var downloadCmd = cobra.Command{
PersistentPreRun: func(cmd *cobra.Command, args []string) {
setenv(cmd, "host", "MAKESHIFT_HOST")
setenv(cmd, "path", "MAKESHIFT_PATH")
setenv(cmd, "cacert", "MAKESHIFT_CACERT")
},
Run: func(cmd *cobra.Command, args []string) {
var (
host, _ = cmd.Flags().GetString("host")
path, _ = cmd.Flags().GetString("path")
outputPath, _ = cmd.Flags().GetString("output")
cacertPath, _ = cmd.Flags().GetString("cacert")
pluginNames, _ = cmd.Flags().GetStringSlice("plugins")
profileIDs, _ = cmd.Flags().GetStringSlice("profiles")
extract, _ = cmd.Flags().GetBool("extract")
@ -72,6 +74,10 @@ var downloadCmd = cobra.Command{
Strs("plugins", pluginNames).
Send()
if cacertPath != "" {
c.LoadCertificateFromPath(cacertPath)
}
res, body, err = c.MakeRequest(client.HTTPEnvelope{
Path: query,
Method: http.MethodGet,
@ -163,6 +169,7 @@ var downloadProfileCmd = &cobra.Command{
var (
host, _ = cmd.Flags().GetString("host")
outputPath, _ = cmd.Flags().GetString("output")
cacertPath, _ = cmd.Flags().GetString("cacert")
c = client.New(host)
res *http.Response
@ -176,6 +183,10 @@ var downloadProfileCmd = &cobra.Command{
Str("output", outputPath).
Send()
if cacertPath != "" {
c.LoadCertificateFromPath(cacertPath)
}
for _, profileID := range args {
query = fmt.Sprintf("/profiles/%s", profileID)
res, body, err = c.MakeRequest(client.HTTPEnvelope{
@ -219,6 +230,7 @@ var downloadPluginCmd = &cobra.Command{
var (
host, _ = cmd.Flags().GetString("host")
outputPath, _ = cmd.Flags().GetString("output")
cacertPath, _ = cmd.Flags().GetString("cacert")
c = client.New(host)
res *http.Response
@ -232,6 +244,10 @@ var downloadPluginCmd = &cobra.Command{
Str("output", outputPath).
Send()
if cacertPath != "" {
c.LoadCertificateFromPath(cacertPath)
}
for _, pluginName := range args {
query = fmt.Sprintf("/plugins/%s/raw", pluginName)
res, body, err = c.MakeRequest(client.HTTPEnvelope{
@ -267,6 +283,7 @@ var downloadPluginCmd = &cobra.Command{
func init() {
downloadCmd.PersistentFlags().String("host", "http://localhost:5050", "Set the makeshift remote host (can be set with MAKESHIFT_HOST)")
downloadCmd.PersistentFlags().StringP("output", "o", "", "Set the output path to write files")
downloadCmd.PersistentFlags().String("cacert", "", "Set the CA certificate path to load")
downloadCmd.Flags().StringP("path", "p", ".", "Set the path to list files (can be set with MAKESHIFT_PATH)")
downloadCmd.Flags().StringSlice("profiles", []string{}, "Set the profile(s) to use to populate data store")
downloadCmd.Flags().StringSlice("plugins", []string{}, "Set the plugin(s) to run before downloading files")