Ejemplo n.º 1
0
func init() {
	flag.StringVar(&ConfigFile, "conf", "", "path to config file")
	flag.Parse()

	c, err := config.ReadDefault(ConfigFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
		os.Exit(1)
	}

	for k, v := range map[string]*map[string]value{"shock": &Shock, "openstack": &Openstack, "nginx": &Nginx} {
		err := load(c, k, v)
		if err != nil {
			fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
			os.Exit(1)
		}
	}

}
Ejemplo n.º 2
0
func init() {
	// options
	flag.Bool("h", false, "")
	flag.Bool("help", false, "")
	Examples = flag.Bool("examples", false, "")
	Flags["attributes"] = flag.String("attributes", "", "")
	Flags["full"] = flag.String("full", "", "")
	Flags["parts"] = flag.String("parts", "", "")
	Flags["part"] = flag.String("part", "", "")
	Flags["file"] = flag.String("file", "", "")
	Flags["virtual_file"] = flag.String("virtual_file", "", "")
	Flags["remote_path"] = flag.String("remote_path", "", "")
	Flags["index"] = flag.String("index", "", "")
	Flags["index_options"] = flag.String("index_options", "", "")
	flag.StringVar(&ConfFile, "conf", DefaultPath(), "path to config file")
	flag.Parse()
	c, err := config.ReadDefault(ConfFile)
	handle(err)

	// Cache
	Cache.Dir, err = c.String("Cache", "dir")
	Cache.MaxConnections, err = c.Int("Cache", "max_connections")

	// Server
	Server.Url, err = c.String("Server", "url")
	handle(err)

	// Auth
	Auth.Type, _ = c.String("Auth", "type")
	switch Auth.Type {
	case "globus":
		Auth.TokenUrl, _ = c.String("Auth", "token_url")
		Auth.ProfileUrl, _ = c.String("Auth", "profile_url")
	case "basic":
		// nothing yet
	}
}
Ejemplo n.º 3
0
func Initialize(args []string) []string {
	// options
	fs := flag.FlagSet{}
	Flags["attributes"] = fs.String("attributes", "", "")
	Flags["full"] = fs.String("full", "", "")
	Flags["parts"] = fs.String("parts", "", "")
	Flags["part"] = fs.String("part", "", "")
	Flags["file"] = fs.String("file", "", "")
	Flags["threads"] = fs.String("threads", "", "")
	Flags["virtual_file"] = fs.String("virtual_file", "", "")
	Flags["remote_path"] = fs.String("remote_path", "", "")
	Flags["index"] = fs.String("index", "", "")
	Flags["index_options"] = fs.String("index_options", "", "")
	fs.StringVar(&ConfFile, "conf", DefaultPath(), "path to config file")
	fs.Parse(args)
	c, err := config.ReadDefault(ConfFile)
	handle(err)

	// Cache
	Cache.Dir, err = c.String("Cache", "dir")
	Cache.MaxConnections, err = c.Int("Cache", "max_connections")

	// Server
	Server.Url, err = c.String("Server", "url")
	handle(err)

	// Auth
	Auth.Type, _ = c.String("Auth", "type")
	switch Auth.Type {
	case "globus":
		Auth.TokenUrl, _ = c.String("Auth", "token_url")
		Auth.ProfileUrl, _ = c.String("Auth", "profile_url")
	case "basic":
		// nothing yet
	}
	return fs.Args()
}
Ejemplo n.º 4
0
Archivo: conf.go Proyecto: eberroca/AWE
func init() {
	flag.StringVar(&CONFIG_FILE, "conf", "", "path to config file")
	flag.StringVar(&RELOAD, "reload", "", "path or url to awe job data. WARNING this will drop all current jobs.")
	flag.BoolVar(&RECOVER, "recover", false, "path to awe job data.")
	flag.StringVar(&CLIENT_PROFILE, "profile", "", "path to awe client profile.")
	flag.IntVar(&DEBUG_LEVEL, "debug", 0, "debug level: 0-3")
	flag.BoolVar(&DEV_MODE, "dev", false, "dev or demo mode, print some msgs on screen")
	flag.Parse()

	//	fmt.Printf("in conf.init(), flag=%v", flag)

	if len(CONFIG_FILE) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: conf file not specified\n")
		INIT_SUCCESS = false
		return
	}

	c, err := config.ReadDefault(CONFIG_FILE)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
		INIT_SUCCESS = false
		return
	}

	// Ports
	SITE_PORT, _ = c.Int("Ports", "site-port")
	API_PORT, _ = c.Int("Ports", "api-port")

	// SSL
	SSL_ENABLED, _ = c.Bool("SSL", "enable")
	if SSL_ENABLED {
		SSL_KEY_FILE, _ = c.String("SSL", "key")
		SSL_CERT_FILE, _ = c.String("SSL", "cert")
	}

	// Access-Control
	ANON_WRITE, _ = c.Bool("Anonymous", "write")
	ANON_READ, _ = c.Bool("Anonymous", "read")
	ANON_CREATEUSER, _ = c.Bool("Anonymous", "create-user")

	// Auth
	AUTH_TYPE, _ = c.String("Auth", "type")
	switch AUTH_TYPE {
	case "globus":
		GLOBUS_TOKEN_URL, _ = c.String("Auth", "globus_token_url")
		GLOBUS_PROFILE_URL, _ = c.String("Auth", "globus_profile_url")
	case "oauth":
		OAUTH_REQUEST_TOKEN_URL, _ = c.String("Auth", "oauth_request_token_url")
		OAUTH_AUTH_TOKEN_URL, _ = c.String("Auth", "oauth_auth_token_url")
		OAUTH_ACCESS_TOKEN_URL, _ = c.String("Auth", "oauth_access_token_url")
	case "basic":
		// nothing yet
	}

	// Admin
	ADMIN_EMAIL, _ = c.String("Admin", "email")
	SECRET_KEY, _ = c.String("Admin", "secretkey")

	// Directories
	SITE_PATH, _ = c.String("Directories", "site")
	DATA_PATH, _ = c.String("Directories", "data")
	LOGS_PATH, _ = c.String("Directories", "logs")

	// Mongodb
	MONGODB, _ = c.String("Mongodb", "hosts")

	// Server options
	if perf_log_workunit, err := c.Bool("Server", "perf_log_workunit"); err == nil {
		PERF_LOG_WORKUNIT = perf_log_workunit
	}
	if big_data_size, err := c.Int("Server", "big_data_size"); err == nil {
		BIG_DATA_SIZE = int64(big_data_size)
	}
	/*
		if default_index, err := c.String("Server", "default_index"); err == nil {
			DEFAULT_INDEX = default_index
		}
	*/

	// Client
	WORK_PATH, _ = c.String("Client", "workpath")
	APP_PATH, _ = c.String("Client", "app_path")
	SERVER_URL, _ = c.String("Client", "serverurl")
	if clientname, err := c.String("Client", "name"); err == nil {
		CLIENT_NAME = clientname
	}
	if clientgroup, err := c.String("Client", "group"); err == nil {
		CLIENT_GROUP = clientgroup
	}
	if clientprofile, err := c.String("Client", "clientprofile"); err == nil {
		CLIENT_PROFILE = clientprofile
	}
	if print_app_msg, err := c.Bool("Client", "print_app_msg"); err == nil {
		PRINT_APP_MSG = print_app_msg
	}
	if worker_overlap, err := c.Bool("Client", "worker_overlap"); err == nil {
		WORKER_OVERLAP = worker_overlap
	}
	if auto_clean_dir, err := c.Bool("Client", "auto_clean_dir"); err == nil {
		AUTO_CLEAN_DIR = auto_clean_dir
	}
}
Ejemplo n.º 5
0
// Initialize is an explicit init. Enables outside use
// of shock-server packages. Parses config and populates
// the Conf variable.
func Initialize() {
	flag.StringVar(&CONFIG_FILE, "conf", "/usr/local/shock/conf/shock.cfg", "path to config file")
	flag.StringVar(&RELOAD, "reload", "", "path or url to shock data. WARNING this will drop all current data.")
	flag.Parse()
	c, err := config.ReadDefault(CONFIG_FILE)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
		os.Exit(1)
	}

	// Ports
	Conf["site-port"], _ = c.String("Ports", "site-port")
	Conf["api-port"], _ = c.String("Ports", "api-port")

	// URLs
	Conf["site-url"], _ = c.String("External", "site-url")
	Conf["api-url"], _ = c.String("External", "api-url")

	// SSL
	Conf["ssl"], _ = c.String("SSL", "enable")
	if Bool(Conf["ssl"]) {
		Conf["ssl-key"], _ = c.String("SSL", "key")
		Conf["ssl-cert"], _ = c.String("SSL", "cert")
	}

	// Access-Control
	Conf["anon-write"], _ = c.String("Anonymous", "write")
	Conf["anon-read"], _ = c.String("Anonymous", "read")
	Conf["anon-user"], _ = c.String("Anonymous", "create-user")

	// Auth
	Conf["basic_auth"], _ = c.String("Auth", "basic")
	Conf["globus_token_url"], _ = c.String("Auth", "globus_token_url")
	Conf["globus_profile_url"], _ = c.String("Auth", "globus_profile_url")
	Conf["mgrast_oauth_url"], _ = c.String("Auth", "mgrast_oauth_url")

	// Admin
	Conf["admin-email"], _ = c.String("Admin", "email")
	Conf["admin-secret"], _ = c.String("Admin", "secretkey")

	// Directories
	Conf["site-path"], _ = c.String("Directories", "site")
	Conf["data-path"], _ = c.String("Directories", "data")
	Conf["logs-path"], _ = c.String("Directories", "logs")
	Conf["local-paths"], _ = c.String("Directories", "local_paths")

	// Mongodb
	Conf["mongodb-hosts"], _ = c.String("Mongodb", "hosts")
	if Conf["mongodb-database"], err = c.String("Mongodb", "database"); err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: Mongodb database must be set in config file.")
		os.Exit(1)
	}
	Conf["mongodb-user"], _ = c.String("Mongodb", "user")
	Conf["mongodb-password"], _ = c.String("Mongodb", "password")

	// parse Node-Indices
	NODE_IDXS = map[string]idxOpts{}
	nodeIdx, _ := c.Options("Node-Indices")
	for _, opt := range nodeIdx {
		val, _ := c.String("Node-Indices", opt)
		opts := idxOpts{}
		for _, parts := range strings.Split(val, ",") {
			p := strings.Split(parts, ":")
			if p[0] == "unique" {
				if p[1] == "true" {
					opts.unique = true
				} else {
					opts.unique = false
				}
			} else if p[0] == "dropDups" {
				if p[1] == "true" {
					opts.dropDups = true
				} else {
					opts.dropDups = false
				}
			} else if p[0] == "sparse" {
				if p[1] == "true" {
					opts.sparse = true
				} else {
					opts.sparse = false
				}
			}
		}
		NODE_IDXS[opt] = opts
	}

	Conf["perf-log"], _ = c.String("Log", "perf_log")
}
Ejemplo n.º 6
0
func init() {
	flag.StringVar(&CONFIG_FILE, "conf", "/usr/local/shock/conf/shock.cfg", "path to config file")
	flag.StringVar(&RELOAD, "reload", "", "path or url to shock data. WARNING this will drop all current data.")
	flag.Parse()
	c, err := config.ReadDefault(CONFIG_FILE)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
		os.Exit(1)
	}

	// Ports
	SITE_PORT, _ = c.Int("Ports", "site-port")
	API_PORT, _ = c.Int("Ports", "api-port")

	// URLs
	SITE_URL, _ = c.String("External", "site-url")
	API_URL, _ = c.String("External", "api-url")

	// SSL
	SSL_ENABLED, _ = c.Bool("SSL", "enable")
	if SSL_ENABLED {
		SSL_KEY_FILE, _ = c.String("SSL", "key")
		SSL_CERT_FILE, _ = c.String("SSL", "cert")
	}

	// Access-Control
	ANON_WRITE, _ = c.Bool("Anonymous", "write")
	ANON_READ, _ = c.Bool("Anonymous", "read")
	ANON_CREATEUSER, _ = c.Bool("Anonymous", "create-user")

	// Auth
	AUTH_TYPE, _ = c.String("Auth", "type")
	switch AUTH_TYPE {
	case "globus":
		GLOBUS_TOKEN_URL, _ = c.String("Auth", "globus_token_url")
		GLOBUS_PROFILE_URL, _ = c.String("Auth", "globus_profile_url")
	case "oauth":
		OAUTH_REQUEST_TOKEN_URL, _ = c.String("Auth", "oauth_request_token_url")
		OAUTH_AUTH_TOKEN_URL, _ = c.String("Auth", "oauth_auth_token_url")
		OAUTH_ACCESS_TOKEN_URL, _ = c.String("Auth", "oauth_access_token_url")
	case "basic":
		// nothing yet
	}

	// Admin
	ADMIN_EMAIL, _ = c.String("Admin", "email")
	SECRET_KEY, _ = c.String("Admin", "secretkey")

	// Directories
	SITE_PATH, _ = c.String("Directories", "site")
	DATA_PATH, _ = c.String("Directories", "data")
	LOGS_PATH, _ = c.String("Directories", "logs")
	localPaths, _ := c.String("Directories", "local_paths")
	LOCAL_PATHS = strings.Split(localPaths, ",")

	// Mongodb
	MONGODB, _ = c.String("Mongodb", "hosts")

	// parse Node-Indices
	NODE_IDXS = map[string]idxOpts{}
	nodeIdx, _ := c.Options("Node-Indices")
	for _, opt := range nodeIdx {
		val, _ := c.String("Node-Indices", opt)
		opts := idxOpts{}
		for _, parts := range strings.Split(val, ",") {
			p := strings.Split(parts, ":")
			if p[0] == "unique" {
				if p[1] == "true" {
					opts.unique = true
				} else {
					opts.unique = false
				}
			} else if p[0] == "dropDups" {
				if p[1] == "true" {
					opts.dropDups = true
				} else {
					opts.dropDups = false
				}
			} else if p[0] == "sparse" {
				if p[1] == "true" {
					opts.sparse = true
				} else {
					opts.sparse = false
				}
			}
		}
		NODE_IDXS[opt] = opts
	}

	if perf_log, err := c.Bool("Log", "perf_log"); err == nil {
		PERF_LOG = perf_log
	}

}