aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bommom.go52
-rw-r--r--core.go10
-rw-r--r--formats.go22
-rw-r--r--store.go50
4 files changed, 67 insertions, 67 deletions
diff --git a/bommom.go b/bommom.go
index 623e477..4441353 100644
--- a/bommom.go
+++ b/bommom.go
@@ -77,7 +77,7 @@ func openBomStore() {
}
}
-func dumpOut(fname string, bs *BomMeta, b *Bom) {
+func dumpOut(fname string, bm *BomMeta, b *Bom) {
var outFile io.Writer
if fname == "" {
outFile = os.Stdout
@@ -107,20 +107,20 @@ func dumpOut(fname string, bs *BomMeta, b *Bom) {
switch *outFormat {
case "text", "":
- DumpBomAsText(bs, b, outFile)
+ DumpBomAsText(bm, b, outFile)
case "json":
- DumpBomAsJSON(bs, b, outFile)
+ DumpBomAsJSON(bm, b, outFile)
case "csv":
DumpBomAsCSV(b, outFile)
case "xml":
- DumpBomAsXML(bs, b, outFile)
+ DumpBomAsXML(bm, b, outFile)
default:
log.Fatal("Error: unknown/unimplemented format: " + *outFormat)
}
}
-func loadIn(fname string) (bs *BomMeta, b *Bom) {
+func loadIn(fname string) (bm *BomMeta, b *Bom) {
if inFormat == "" {
switch ext := path.Ext(fname); ext {
@@ -143,37 +143,37 @@ func loadIn(fname string) (bs *BomMeta, b *Bom) {
switch inFormat {
case "json":
- bs, b, err = LoadBomFromJSON(infile)
+ bm, b, err = LoadBomFromJSON(infile)
case "csv":
b, err = LoadBomFromCSV(infile)
case "xml":
- bs, b, err = LoadBomFromXML(infile)
+ bm, b, err = LoadBomFromXML(infile)
default:
log.Fatal("Error: unknown/unimplemented format: " + *outFormat)
}
if err != nil {
log.Fatal(err)
}
- return bs, b
+ return bm, b
}
func initCmd() {
openBomStore()
- bs, err := bomstore.GetBomMeta(ShortName("common"), ShortName("gizmo"))
+ bm, err := bomstore.GetBomMeta(ShortName("common"), ShortName("gizmo"))
if err == nil {
// dummy BomMeta already exists?
return
}
b := makeTestBom()
b.Version = "v001"
- bs = &BomMeta{Name: "gizmo",
+ bm = &BomMeta{Name: "gizmo",
Owner: "common",
Description: "fancy stuff",
HeadVersion: b.Version,
IsPublicView: true,
IsPublicEdit: true}
- bomstore.Persist(bs, b, "v001")
+ bomstore.Persist(bm, b, "v001")
}
func dumpCmd() {
@@ -201,12 +201,12 @@ func dumpCmd() {
if auth == nil {
auth = DummyAuth(true)
}
- bs, b, err := bomstore.GetHead(ShortName(userStr), ShortName(nameStr))
+ bm, b, err := bomstore.GetHead(ShortName(userStr), ShortName(nameStr))
if err != nil {
log.Fatal(err)
}
- dumpOut(fname, bs, b)
+ dumpOut(fname, bm, b)
}
func loadCmd() {
@@ -224,20 +224,20 @@ func loadCmd() {
log.Fatal("user, name, and version must be ShortNames")
}
- bs, b := loadIn(inFname)
- if inFormat == "csv" && bs == nil {
+ bm, b := loadIn(inFname)
+ if inFormat == "csv" && bm == nil {
// TODO: from inname? if ShortName?
- bs = &BomMeta{}
+ bm = &BomMeta{}
}
- bs.Owner = userName
- bs.Name = bomName
+ bm.Owner = userName
+ bm.Name = bomName
b.Progeny = "File import from " + inFname + " (" + inFormat + ")"
b.Created = time.Now()
openBomStore()
- bomstore.Persist(bs, b, ShortName(version))
+ bomstore.Persist(bm, b, ShortName(version))
}
func convertCmd() {
@@ -251,14 +251,14 @@ func convertCmd() {
inFname := flag.Arg(1)
outFname := flag.Arg(2)
- bs, b := loadIn(inFname)
+ bm, b := loadIn(inFname)
if b == nil {
log.Fatal("null bom")
}
- if inFormat == "csv" && bs == nil {
+ if inFormat == "csv" && bm == nil {
// TODO: from inname? if ShortName?
- bs = &BomMeta{Name: "untitled",
+ bm = &BomMeta{Name: "untitled",
Owner: anonUser.name}
b.Version = "unversioned"
}
@@ -266,14 +266,14 @@ func convertCmd() {
b.Created = time.Now()
b.Progeny = "File import from " + inFname + " (" + inFormat + ")"
- if err := bs.Validate(); err != nil {
+ if err := bm.Validate(); err != nil {
log.Fatal("loaded bommeta not valid: " + err.Error())
}
if err := b.Validate(); err != nil {
log.Fatal("loaded bom not valid: " + err.Error())
}
- dumpOut(outFname, bs, b)
+ dumpOut(outFname, bm, b)
}
func listCmd() {
@@ -300,8 +300,8 @@ func listCmd() {
log.Fatal(err)
}
}
- for _, bs := range bomMetas {
- fmt.Println(bs.Owner + "/" + bs.Name)
+ for _, bm := range bomMetas {
+ fmt.Println(bm.Owner + "/" + bm.Name)
}
}
diff --git a/core.go b/core.go
index f7f0555..e15f397 100644
--- a/core.go
+++ b/core.go
@@ -87,12 +87,12 @@ func (b *Bom) Validate() error {
return nil
}
-func (bs *BomMeta) Validate() error {
- if !isShortName(bs.Name) {
- return Error("name not a ShortName: \"" + bs.Name + "\"")
+func (bm *BomMeta) Validate() error {
+ if !isShortName(bm.Name) {
+ return Error("name not a ShortName: \"" + bm.Name + "\"")
}
- if !isShortName(bs.Owner) {
- return Error("owner name not a ShortName: \"" + bs.Owner + "\"")
+ if !isShortName(bm.Owner) {
+ return Error("owner name not a ShortName: \"" + bm.Owner + "\"")
}
return nil
}
diff --git a/formats.go b/formats.go
index da22bd0..9309d96 100644
--- a/formats.go
+++ b/formats.go
@@ -20,20 +20,20 @@ type BomContainer struct {
// --------------------- text (CLI only ) -----------------------
-func DumpBomAsText(bs *BomMeta, b *Bom, out io.Writer) {
+func DumpBomAsText(bm *BomMeta, b *Bom, out io.Writer) {
fmt.Fprintln(out)
- fmt.Fprintf(out, "Name:\t\t%s\n", bs.Name)
+ fmt.Fprintf(out, "Name:\t\t%s\n", bm.Name)
fmt.Fprintf(out, "Version:\t%s\n", b.Version)
- fmt.Fprintf(out, "Creator:\t%s\n", bs.Owner)
+ fmt.Fprintf(out, "Creator:\t%s\n", bm.Owner)
fmt.Fprintf(out, "Timestamp:\t%s\n", b.Created)
- if bs.Homepage != "" {
- fmt.Fprintf(out, "Homepage:\t%s\n", bs.Homepage)
+ if bm.Homepage != "" {
+ fmt.Fprintf(out, "Homepage:\t%s\n", bm.Homepage)
}
if b.Progeny != "" {
fmt.Fprintf(out, "Source:\t\t%s\n", b.Progeny)
}
- if bs.Description != "" {
- fmt.Fprintf(out, "Description:\t%s\n", bs.Description)
+ if bm.Description != "" {
+ fmt.Fprintf(out, "Description:\t%s\n", bm.Description)
}
fmt.Println()
// "by line item"
@@ -95,9 +95,9 @@ func LoadBomFromCSV(out io.Writer) (*Bom, error) {
// --------------------- JSON -----------------------
-func DumpBomAsJSON(bs *BomMeta, b *Bom, out io.Writer) {
+func DumpBomAsJSON(bm *BomMeta, b *Bom, out io.Writer) {
- container := &BomContainer{BomMetadata: bs, Bom: b}
+ container := &BomContainer{BomMetadata: bm, Bom: b}
enc := json.NewEncoder(out)
if err := enc.Encode(&container); err != nil {
@@ -118,9 +118,9 @@ func LoadBomFromJSON(input io.Reader) (*BomMeta, *Bom, error) {
// --------------------- XML -----------------------
-func DumpBomAsXML(bs *BomMeta, b *Bom, out io.Writer) {
+func DumpBomAsXML(bm *BomMeta, b *Bom, out io.Writer) {
- container := &BomContainer{BomMetadata: bs, Bom: b}
+ container := &BomContainer{BomMetadata: bm, Bom: b}
enc := xml.NewEncoder(out)
// generic XML header
diff --git a/store.go b/store.go
index 6187f78..54d4bb0 100644
--- a/store.go
+++ b/store.go
@@ -12,7 +12,7 @@ type BomStore interface {
GetBomMeta(user, name ShortName) (*BomMeta, error)
GetHead(user, name ShortName) (*BomMeta, *Bom, error)
GetBom(user, name, version ShortName) (*Bom, error)
- Persist(bs *BomMeta, b *Bom, version ShortName) error
+ Persist(bm *BomMeta, b *Bom, version ShortName) error
ListBoms(user ShortName) ([]BomMeta, error)
}
@@ -40,24 +40,24 @@ func OpenJSONFileBomStore(fpath string) (*JSONFileBomStore, error) {
func (jfbs *JSONFileBomStore) GetBomMeta(user, name ShortName) (*BomMeta, error) {
fpath := jfbs.Rootfpath + "/" + string(user) + "/" + string(name) + "/_meta.json"
- bs := BomMeta{}
- if err := readJsonBomMeta(fpath, &bs); err != nil {
+ bm := BomMeta{}
+ if err := readJsonBomMeta(fpath, &bm); err != nil {
return nil, err
}
- return &bs, nil
+ return &bm, nil
}
func (jfbs *JSONFileBomStore) GetHead(user, name ShortName) (*BomMeta, *Bom, error) {
- bs, err := jfbs.GetBomMeta(user, name)
+ bm, err := jfbs.GetBomMeta(user, name)
if err != nil {
return nil, nil, err
}
- version := bs.HeadVersion
+ version := bm.HeadVersion
if version == "" {
log.Fatal("Tried to read undefined HEAD for " + string(user) + "/" + string(name))
}
b, err := jfbs.GetBom(user, name, ShortName(version))
- return bs, b, err
+ return bm, b, err
}
func (jfbs *JSONFileBomStore) GetBom(user, name, version ShortName) (*Bom, error) {
@@ -79,7 +79,7 @@ func (jfbs *JSONFileBomStore) ListBoms(user ShortName) ([]BomMeta, error) {
log.Fatal(err)
}
defer rootDir.Close()
- bsList := []BomMeta{}
+ bmList := []BomMeta{}
dirInfo, err := rootDir.Readdir(0)
for _, node := range dirInfo {
if !node.IsDir() || !isShortName(node.Name()) {
@@ -89,19 +89,19 @@ func (jfbs *JSONFileBomStore) ListBoms(user ShortName) ([]BomMeta, error) {
if err != nil {
log.Fatal(err)
}
- bsList = append(bsList, uList...)
+ bmList = append(bmList, uList...)
}
- return bsList, nil
+ return bmList, nil
}
func (jfbs *JSONFileBomStore) listBomsForUser(user ShortName) ([]BomMeta, error) {
- bsList := []BomMeta{}
+ bmList := []BomMeta{}
uDirPath := jfbs.Rootfpath + "/" + string(user)
uDir, err := os.Open(uDirPath)
if err != nil {
if e, ok := err.(*os.PathError); ok && e.Err.Error() == "no such file or directory" {
// XXX: should probably check for a specific syscall error? same below
- return bsList, nil
+ return bmList, nil
}
return nil, err
}
@@ -115,36 +115,36 @@ func (jfbs *JSONFileBomStore) listBomsForUser(user ShortName) ([]BomMeta, error)
continue
}
fpath := jfbs.Rootfpath + "/" + string(user) + "/" + node.Name() + "/_meta.json"
- bs := BomMeta{}
- if err := readJsonBomMeta(fpath, &bs); err != nil {
+ bm := BomMeta{}
+ if err := readJsonBomMeta(fpath, &bm); err != nil {
if e, ok := err.(*os.PathError); ok && e.Err.Error() == "no such file or directory" {
// no _meta.json in there
continue
}
return nil, err
}
- bsList = append(bsList, bs)
+ bmList = append(bmList, bm)
}
- return bsList, nil
+ return bmList, nil
}
-func (jfbs *JSONFileBomStore) Persist(bs *BomMeta, b *Bom, version ShortName) error {
+func (jfbs *JSONFileBomStore) Persist(bm *BomMeta, b *Bom, version ShortName) error {
- if err := bs.Validate(); err != nil {
+ if err := bm.Validate(); err != nil {
return err
}
if err := b.Validate(); err != nil {
return err
}
- b_fpath := jfbs.Rootfpath + "/" + string(bs.Owner) + "/" + string(bs.Name) + "/" + string(version) + ".json"
- bs_fpath := jfbs.Rootfpath + "/" + string(bs.Owner) + "/" + string(bs.Name) + "/_meta.json"
+ b_fpath := jfbs.Rootfpath + "/" + string(bm.Owner) + "/" + string(bm.Name) + "/" + string(version) + ".json"
+ bm_fpath := jfbs.Rootfpath + "/" + string(bm.Owner) + "/" + string(bm.Name) + "/_meta.json"
if f, err := os.Open(b_fpath); err == nil {
f.Close()
return Error("bom with same owner, name, and version already exists")
}
- if err := writeJsonBomMeta(bs_fpath, bs); err != nil {
+ if err := writeJsonBomMeta(bm_fpath, bm); err != nil {
log.Fatal(err)
}
if err := writeJsonBom(b_fpath, b); err != nil {
@@ -153,20 +153,20 @@ func (jfbs *JSONFileBomStore) Persist(bs *BomMeta, b *Bom, version ShortName) er
return nil
}
-func readJsonBomMeta(fpath string, bs *BomMeta) error {
+func readJsonBomMeta(fpath string, bm *BomMeta) error {
f, err := os.Open(path.Clean(fpath))
if err != nil {
return err
}
defer f.Close()
dec := json.NewDecoder(f)
- if err = dec.Decode(&bs); err != nil {
+ if err = dec.Decode(&bm); err != nil {
return err
}
return nil
}
-func writeJsonBomMeta(fpath string, bs *BomMeta) error {
+func writeJsonBomMeta(fpath string, bm *BomMeta) error {
err := os.MkdirAll(path.Dir(fpath), os.ModePerm|os.ModeDir)
if err != nil && !os.IsExist(err) {
return err
@@ -177,7 +177,7 @@ func writeJsonBomMeta(fpath string, bs *BomMeta) error {
}
defer f.Close()
enc := json.NewEncoder(f)
- if err = enc.Encode(&bs); err != nil {
+ if err = enc.Encode(&bm); err != nil {
return err
}
return nil