func SaveCertFiles(certPem string, keyPem string) error {
	suffix := findHighestSuffix(config.Server.Server.CertFile, config.Server.Server.KeyFile)

	var (
		newPath string
		oldPath string
		err     error
	)

	newPath = fmt.Sprintf("%s.%03d", config.Server.Server.CertFile, suffix)
	oldPath = config.Server.Server.CertFile
	_, err = fs.Stat(oldPath)
	if err == nil {
		fmt.Printf("   - moving old cert file to %s: ", newPath)
		err := fs.Rename(oldPath, newPath)
		if err != nil {
			return err
		}
		fmt.Println("ok")
	}

	newPath = fmt.Sprintf("%s.%03d", config.Server.Server.KeyFile, suffix)
	oldPath = config.Server.Server.KeyFile
	_, err = fs.Stat(oldPath)
	if err == nil {
		fmt.Printf("   - moving old key file to %s: ", newPath)
		err = fs.Rename(oldPath, newPath)
		if err != nil {
			return err
		}
		fmt.Println("ok")
	}

	fmt.Printf("   - Writing new cert file %s: ", config.Server.Server.CertFile)
	newPath = config.Server.Server.CertFile
	err = afero.WriteFile(fs, newPath, []byte(certPem), 0600)
	if err != nil {
		return err
	}
	fmt.Println("ok")

	fmt.Printf("   - Writing new key file %s: ", config.Server.Server.CertFile)
	newPath = config.Server.Server.KeyFile
	err = afero.WriteFile(fs, newPath, []byte(keyPem), 0600)
	if err != nil {
		return err
	}
	fmt.Println("ok")

	return nil
}
// SaveCertFiles saves the given cert and key PEM strings into the configured cert and key file. Old files are backed
// as .001 (or .002 etc) if the files already exists.
SaveCertFiles saves the given cert and key PEM strings into the configured cert and key file. Old files are backed
as .001 (or .002 etc) if the files already exists.
// SaveCertFiles saves the given cert and key PEM strings into the configured cert and key file . Old files are backed // as . 001 ( or . 002 etc ) if the files already exists .
func SaveCertFiles(certPem string, keyPem string) error {
	suffix := findHighestSuffix(config.Server.Server.CertFile, config.Server.Server.KeyFile)
	var (
		newPath string
		oldPath string
		err     error
	)
	newPath = fmt.Sprintf("%s.%03d", config.Server.Server.CertFile, suffix)
	oldPath = config.Server.Server.CertFile
	_, err = fs.Stat(oldPath)
	if err == nil {
		fmt.Printf("   - moving old cert file to %s: ", newPath)
		err := fs.Rename(oldPath, newPath)
		if err != nil {
			return err
		}
		fmt.Println("ok")
	}
	newPath = fmt.Sprintf("%s.%03d", config.Server.Server.KeyFile, suffix)
	oldPath = config.Server.Server.KeyFile
	_, err = fs.Stat(oldPath)
	if err == nil {
		fmt.Printf("   - moving old key file to %s: ", newPath)
		err = fs.Rename(oldPath, newPath)
		if err != nil {
			return err
		}
		fmt.Println("ok")
	}
	fmt.Printf("   - Writing new cert file %s: ", config.Server.Server.CertFile)
	newPath = config.Server.Server.CertFile
	err = afero.WriteFile(fs, newPath, []byte(certPem), 0600)
	if err != nil {
		return err
	}
	fmt.Println("ok")
	fmt.Printf("   - Writing new key file %s: ", config.Server.Server.CertFile)
	newPath = config.Server.Server.KeyFile
	err = afero.WriteFile(fs, newPath, []byte(keyPem), 0600)
	if err != nil {
		return err
	}
	fmt.Println("ok")
	return nil
}
func SaveCertFiles ( certPem string , keyPem string ) error { suffix := findHighestSuffix ( config . Server . Server . CertFile , config . Server . Server . KeyFile ) var ( newPath string oldPath string err error ) newPath = fmt . Sprintf ( " " , config . Server . Server . CertFile , suffix ) oldPath = config . Server . Server . CertFile _ , err = fs . Stat ( oldPath ) if err == nil { fmt . Printf ( " " , newPath ) err := fs . Rename ( oldPath , newPath ) if err != nil { return err } fmt . Println ( " " ) } newPath = fmt . Sprintf ( " " , config . Server . Server . KeyFile , suffix ) oldPath = config . Server . Server . KeyFile _ , err = fs . Stat ( oldPath ) if err == nil { fmt . Printf ( " " , newPath ) err = fs . Rename ( oldPath , newPath ) if err != nil { return err } fmt . Println ( " " ) } fmt . Printf ( " " , config . Server . Server . CertFile ) newPath = config . Server . Server . CertFile err = afero . WriteFile ( fs , newPath , [ ] byte ( certPem ) , 0600 ) if err != nil { return err } fmt . Println ( " " ) fmt . Printf ( " " , config . Server . Server . CertFile ) newPath = config . Server . Server . KeyFile err = afero . WriteFile ( fs , newPath , [ ] byte ( keyPem ) , 0600 ) if err != nil { return err } fmt . Println ( " " ) return nil }
SaveCertFiles saves the given cert and key PEM strings into the configured cert and key file.
SaveCertFiles saves the given cert and key PEM strings into the configured cert and key file .