From beb3095cf5bf2865b9cf93512c3edc68cf6d1392 Mon Sep 17 00:00:00 2001 From: Richard Kosegi Date: Sun, 3 Mar 2024 07:15:56 +0100 Subject: [PATCH] Move creation of default data into separate function Signed-off-by: Richard Kosegi --- pkg/create/create.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/create/create.go b/pkg/create/create.go index 97235a6..586ce8d 100644 --- a/pkg/create/create.go +++ b/pkg/create/create.go @@ -111,14 +111,22 @@ func validateCa(d *createCaData) error { return nil } +func defData(w io.Writer, isCA bool) commonCreateData { + d := commonCreateData{ + w: w, + bits: 4096, + dir: ".", + validYears: 1, + } + if isCA { + d.validYears = 2 + } + return d +} + func newCaSubCommand(w io.Writer) *cobra.Command { d := &createCaData{ - commonCreateData: commonCreateData{ - w: w, - bits: 4096, - dir: ".", - validYears: 2, - }, + commonCreateData: defData(w, true), } cmd := &cobra.Command{ Use: "ca", @@ -140,12 +148,7 @@ func newCaSubCommand(w io.Writer) *cobra.Command { func newLeafSubCommand(w io.Writer) *cobra.Command { d := &createLeafData{ - commonCreateData: commonCreateData{ - w: w, - bits: 4096, - dir: ".", - validYears: 2, - }, + commonCreateData: defData(w, false), } cmd := &cobra.Command{ Use: "leaf",