-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename command to 'authority download-cert'
- Loading branch information
Showing
4 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package authority | ||
|
||
import ( | ||
"github.com/alpacanetworks/alpacon-cli/api/cert" | ||
"github.com/alpacanetworks/alpacon-cli/client" | ||
"github.com/alpacanetworks/alpacon-cli/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var authorityDownloadCmd = &cobra.Command{ | ||
Use: "download-crt [AUTHORITY ID]", | ||
Aliases: []string{"download-cert"}, | ||
Short: "Download a root certificate", | ||
Long: ` | ||
Download a root certificate from the server and save it to a specified file path. | ||
The path argument should include the file name and extension where the certificate will be stored. | ||
For example, '/path/to/root.crt'. The recommended file extension for certificates is '.crt'.`, | ||
Example: ` | ||
alpacon authority download-crt [AUTHORITY ID] --out=/path/to/root.crt | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
authorityId := args[0] | ||
filePath, _ := cmd.Flags().GetString("out") | ||
if filePath == "" { | ||
filePath = promptForCertificate() | ||
} | ||
|
||
alpaconClient, err := client.NewAlpaconAPIClient() | ||
if err != nil { | ||
utils.CliError("Connection to Alpacon API failed: %s. Consider re-logging.", err) | ||
} | ||
|
||
err = cert.DownloadRootCertificate(alpaconClient, authorityId, filePath) | ||
if err != nil { | ||
utils.CliError("Failed to download the root certificate from authority: %s", err) | ||
} | ||
|
||
utils.CliInfo("Root certificate downloaded successfully: '%s'", filePath) | ||
}, | ||
} | ||
|
||
func init() { | ||
var filePath string | ||
authorityDownloadCmd.Flags().StringVarP(&filePath, "out", "o", "", "path where root certificate should be stored") | ||
|
||
} | ||
|
||
func promptForCertificate() string { | ||
return utils.PromptForRequiredInput("Path to root certificate (e.g., /path/to/root.crt, recommended extension: .crt): ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters