Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
aggregated file creation in pki structure init
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-clerc committed Sep 12, 2015
1 parent e76f84e commit 7a2991a
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions pkg/easyca/easyca.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,50 +376,38 @@ func GeneratePKIStructure(pkiroot string) error {
}
}

serial, err := os.Create(filepath.Join(pkiroot, "serial"))
if err != nil {
return fmt.Errorf("create serial: %v", err)
}
defer serial.Close()
n, err := fmt.Fprintln(serial, "01")
if err != nil {
return fmt.Errorf("write serial: %v", err)
}
if n == 0 {
return fmt.Errorf("write serial, written 0 bytes")
}
files := []struct {
Name string
Content string
File *os.File
}{
{Name: "serial", Content: "01"},
{Name: "crlnumber", Content: "01"},
{Name: "index.txt", Content: ""},
{Name: "index.txt.attr", Content: "unique_subject = no"},
}
for _, f := range files {
// if using := here i get needs identifier, hm ?
var err error
f.File, err = os.Create(filepath.Join(pkiroot, f.Name))
if err != nil {
return fmt.Errorf("create %v: %v", f.Name, err)
}
defer f.File.Close()

crlnumber, err := os.Create(filepath.Join(pkiroot, "crlnumber"))
if err != nil {
return fmt.Errorf("create crlnumber: %v", err)
}
defer crlnumber.Close()
n, err = fmt.Fprintln(crlnumber, "01")
if err != nil {
return fmt.Errorf("write crlnumber: %v", err)
}
if n == 0 {
return fmt.Errorf("write crlnumber, written 0 bytes")
}
if len(f.Content) == 0 {
continue
}

index, err := os.Create(filepath.Join(pkiroot, "index.txt"))
if err != nil {
return fmt.Errorf("create index: %v", err)
n, err := fmt.Fprintln(f.File, f.Content)
if err != nil {
return fmt.Errorf("write %v: %v", f.Name, err)
}
if n == 0 {
return fmt.Errorf("write %v, written 0 bytes", f.Name)
}
}
defer index.Close()

indexattr, err := os.Create(filepath.Join(pkiroot, "index.txt.attr"))
if err != nil {
return fmt.Errorf("create index.txt.attr: %v", err)
}
defer indexattr.Close()
n, err = fmt.Fprintln(indexattr, "unique_subject = no")
if err != nil {
return fmt.Errorf("write index.txt.attr: %v", err)
}
if n == 0 {
return fmt.Errorf("write index.txt.attr, written 0 bytes")
}
return nil
}

Expand Down

0 comments on commit 7a2991a

Please sign in to comment.