From 3c7a4451e62d27bbe9dc8eb2c16e2ff5607d1b04 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sat, 7 Apr 2012 20:17:47 -0400 Subject: backup of partial progress --- .gitignore | 1 + auth.go | 40 +++++++++++++++++++++++++++++++++++++ bommom.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ core.go | 30 ++++++++++++++++++++++++++++ store.go | 22 +++++++++++++++++++++ util.go | 9 +++++++++ 6 files changed, 169 insertions(+) create mode 100644 auth.go create mode 100644 bommom.go create mode 100644 core.go create mode 100644 store.go create mode 100644 util.go diff --git a/.gitignore b/.gitignore index dbd8cb6..b71cac3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.old pkg/ bin/ +bommom diff --git a/auth.go b/auth.go new file mode 100644 index 0000000..0bbed40 --- /dev/null +++ b/auth.go @@ -0,0 +1,40 @@ +package main + +// Authentication globals +var auth AuthService +var anonUser = &User{name: "common"} + +// Basic registered user account structure, for permissions etc. +type User struct { + // TODO: more specific types for these + name, pw, email string +} + +// Minimal requirements for an authentication backend. +type AuthService interface { + CheckLogin(name, pw string) error + NewAccount(name, pw, email string) error + ChangePassword(name, oldPw, newPw string) error + GetEmail(name string) (string, error) +} + +// DummyAuth is a "wide-open" implementation of AuthService for development and +// local use. Any username/password is accepted, and a dummy email address is +// always returned. +type DummyAuth bool // TODO: what is the best "dummy" abstract base type? + +func (da *DummyAuth) CheckLogin(name, pw string) error { + return nil +} + +func (da *DummyAuth) NewAccount(name, pw, email string) error { + return nil +} + +func (da *DummyAuth) ChangePassword(name, oldPw, newPw string) error { + return nil +} + +func (da *DummyAuth) GetEmail(name string) (string, error) { + return "example@bommom.com", nil +} diff --git a/bommom.go b/bommom.go new file mode 100644 index 0000000..3b7c993 --- /dev/null +++ b/bommom.go @@ -0,0 +1,67 @@ +package main + +// CLI for bommom tools. Also used to launch web interface. + +import ( + "flag" + "fmt" + "log" +) + +// Command line flags +var ( + templatePath = flag.String("templatepath", "./templates", "path to template directory") + fileStorePath = flag.String("path", "./filestore", "path to flat file data store top-level directory") + verbose = flag.Bool("verbose", false, "print extra info") + helpFlag = flag.Bool("help", false, "print full help info") + outFormat = flag.String("format", "text", "command output format (for 'dump' etc)") +) + +func main() { + + // Parse configuration + flag.Parse() + if *verbose { + log.Println("template dir:", *templatePath) + log.Println("filestore dir:", *fileStorePath) + log.Println("anon user:", anonUser.name) + } + + // Process command + if *helpFlag { + printUsage() + return + } + if flag.NArg() < 1 { + printUsage() + fmt.Println() + log.Fatal("Error: No command specified") + } + + switch flag.Arg(0) { + default: + log.Fatal("Error: unknown command: ", flag.Arg(0)) + case "load", "dump", "serve": + log.Fatal("Error: Unimplemented, sorry") + case "init": + log.Println("Initializing...") + } +} + +func printUsage() { + fmt.Println("bommom is a tool for managing and publishing electronics BOMs") + fmt.Println("") + fmt.Println("Usage:") + fmt.Println("\tbommom command [options]") + fmt.Println("") + fmt.Println("Commands:") + fmt.Println("") + fmt.Println("\tinit \t\t initialize BOM and authentication datastores") + fmt.Println("\tload [file]\t import a BOM") + fmt.Println("\tdump [name]\t dump a BOM to stdout") + fmt.Println("\tserve\t\t serve up web interface over HTTP") + fmt.Println("") + fmt.Println("Extra command line options:") + fmt.Println("") + flag.PrintDefaults() +} diff --git a/core.go b/core.go new file mode 100644 index 0000000..4472f07 --- /dev/null +++ b/core.go @@ -0,0 +1,30 @@ +package main + +type Offer struct { +} + +type LineItem struct { +} + +type Element struct { +} + +// The main anchor of a BOM as a cohesive whole, with a name and permissions. +// Multiple BOMs are associated with a single BomStub; the currently active one +// is the 'head'. +type BomStub struct { + name *ShortName + owner string + description string + homepage *Url + isPublicView, isPublicEdit bool +} + +// An actual list of parts/elements. Intended to be immutable once persisted. +type Bom struct { + version *ShortName + date uint64 // TODO: unix timestamp? + progeny string // where did this BOM come from? + elements []Element + lineitems []LineItem +} diff --git a/store.go b/store.go new file mode 100644 index 0000000..3fb279f --- /dev/null +++ b/store.go @@ -0,0 +1,22 @@ +package main + +var bomstore BomStore + +// TODO: who owns returned BOMs? Caller? need "free" methods? +type BomStore interface { + GetStub(user, name ShortName) (*BomStub, error) + GetHead(user, name ShortName) (*Bom, error) + GetBom(user, name, version ShortName) (*Bom, error) + Persist(bom *Bom) error +} + +/* +// Dummy BomStore backed by hashtable in memory, for testing and demo purposes +type MemoryBomStore map[string] Bom +*/ + +// Basic BomStore backend using a directory structure of JSON files saved to +// disk. +type JSONFileBomStore struct { + rootPath string +} diff --git a/util.go b/util.go new file mode 100644 index 0000000..6b5049e --- /dev/null +++ b/util.go @@ -0,0 +1,9 @@ +package main + +type EmailAddress string +type Password string +type Url string + +// "Slug" string with limited ASCII character set, good for URLs. +// Lowercase alphanumeric plus '_' allowed. +type ShortName string -- cgit v1.2.3