Removed --overwrite flag.
This commit is contained in:
13
ca.go
13
ca.go
@@ -291,14 +291,9 @@ func parseValidity(validity string) (time.Duration, error) {
|
||||
}
|
||||
|
||||
func SavePEM(filename string, data []byte, secure bool) error {
|
||||
if !overwrite {
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
return fmt.Errorf("file %s already exists (overwrite not allowed)", filename)
|
||||
} else if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("could not check file %s: %v", filename, err)
|
||||
}
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
return fmt.Errorf("file %s already exists", filename)
|
||||
}
|
||||
|
||||
if secure {
|
||||
return os.WriteFile(filename, data, 0600)
|
||||
} else {
|
||||
@@ -608,7 +603,7 @@ Certificate:
|
||||
}
|
||||
|
||||
// A prototype of certificate provisioning function
|
||||
func ProvisionCertificates(filePath string, overwrite bool, dryRun bool, verbose bool) error {
|
||||
func ProvisionCertificates(filePath string) error {
|
||||
err := LoadCA()
|
||||
|
||||
if err != nil {
|
||||
@@ -685,7 +680,7 @@ func ProvisionCertificates(filePath string, overwrite bool, dryRun bool, verbose
|
||||
return nil
|
||||
}
|
||||
|
||||
func IssueCertificate(certDef CertificateDefinition, overwrite bool, dryRun bool, verbose bool) error {
|
||||
func IssueCertificate(certDef CertificateDefinition) error {
|
||||
err := LoadCA()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
|
6
main.go
6
main.go
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
// Global flags available to all commands
|
||||
var overwrite bool
|
||||
var dryRun bool
|
||||
var verbose bool
|
||||
|
||||
@@ -46,7 +45,6 @@ func main() {
|
||||
}
|
||||
|
||||
// Define persistent flags (global for all commands)
|
||||
rootCmd.PersistentFlags().BoolVar(&overwrite, "overwrite", false, "Allow overwriting existing files")
|
||||
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Print detailed information about each processed certificate")
|
||||
rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Validate and show what would be created, but do not write files (batch mode)")
|
||||
rootCmd.PersistentFlags().StringVar(&caConfigPath, "config", "ca_config.hcl", "Path to CA configuration file")
|
||||
@@ -95,7 +93,7 @@ func main() {
|
||||
Type: certType,
|
||||
Validity: validity,
|
||||
SAN: san,
|
||||
}, overwrite, dryRun, verbose)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
@@ -120,7 +118,7 @@ func main() {
|
||||
Short: "Provision certificates from a batch file (HCL)",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
err := ProvisionCertificates(provisionFile, overwrite, false, verbose)
|
||||
err := ProvisionCertificates(provisionFile)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
|
Reference in New Issue
Block a user