func main() { var ( logfilename string logw reopener pubtktKey string fedoraAddr string configFile string config config showVersion bool ) flag.StringVar(&logfilename, "log", "", "name of log file. Defaults to stdout") flag.StringVar(&pubtktKey, "pubtkt-key", "", "filename of PEM encoded public key to use for pubtkt authentication") flag.StringVar(&fedoraAddr, "fedora", "", "url to use for fedora, includes username and password, if needed") flag.StringVar(&configFile, "config", "", "name of config file to use") flag.StringVar(&pidfilename, "pid", "", "file to store pid of server") flag.BoolVar(&showVersion, "version", false, "Display the version and exit") flag.Parse() if showVersion { fmt.Printf("disadis version %s\n", Version) return } // the config file stuff was grafted onto the command line options // this should be made pretty if configFile != "" { err := gcfg.ReadFileInto(&config, configFile) if err != nil { log.Println(err) } logfilename = config.General.Log_filename fedoraAddr = config.General.Fedora_addr pubtktKey = config.Pubtkt.Key_file } /* first set up the log file */ log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds) logw = newReopener(logfilename) logw.Reopen() log.Println("-----Starting Disadis Server", Version) /* set up signal handlers */ sig := make(chan os.Signal, 5) signal.Notify(sig, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2) go signalHandler(sig, logw) /* Now set up the handler chains */ if fedoraAddr == "" { log.Printf("Error: Fedora address must be set. (--fedora <server addr>)") os.Exit(1) } fedora := fedora.NewRemote(fedoraAddr, "") ha := auth.NewHydraAuth(fedoraAddr, "") ha.Admin = config.General.Admin log.Println("Admin users:", ha.Admin) switch { case pubtktKey != "": log.Printf("Using pubtkt %s", pubtktKey) ha.CurrentUser = auth.NewPubtktAuthFromKeyFile(pubtktKey) default: log.Printf("Warning: No authorization method given.") } if len(config.Handler) == 0 { log.Printf("No Handlers are defined. Exiting.") return } if pidfilename != "" { writePID(pidfilename) } runHandlers(config, fedora, ha) if pidfilename != "" { os.Remove(pidfilename) } }
// NewHydraAuth makes a new HydraAuth using the given fedoraPath // and object namespace. The namespace is prefixed to any objects identifiers // before lookup in Fedora. func NewHydraAuth(fedoraPath, namespace string) *HydraAuth { return &HydraAuth{ fedora: fedora.NewRemote(fedoraPath, namespace), cache: timecache.New(250, 5*time.Minute), } }