Exemple #1
0
func (s *Site) initializeSiteInfo() {
	params := viper.GetStringMap("Params")

	permalinks := make(PermalinkOverrides)
	for k, v := range viper.GetStringMapString("Permalinks") {
		permalinks[k] = PathPattern(v)
	}

	s.Info = SiteInfo{
		BaseURL:               template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
		Title:                 viper.GetString("Title"),
		Author:                viper.GetStringMap("author"),
		Social:                viper.GetStringMapString("social"),
		LanguageCode:          viper.GetString("languagecode"),
		Copyright:             viper.GetString("copyright"),
		DisqusShortname:       viper.GetString("DisqusShortname"),
		GoogleAnalytics:       viper.GetString("GoogleAnalytics"),
		RSSLink:               s.permalinkStr(viper.GetString("RSSUri")),
		BuildDrafts:           viper.GetBool("BuildDrafts"),
		canonifyURLs:          viper.GetBool("CanonifyURLs"),
		preserveTaxonomyNames: viper.GetBool("PreserveTaxonomyNames"),
		Pages:      &s.Pages,
		Menus:      &s.Menus,
		Params:     params,
		Permalinks: permalinks,
		Data:       &s.Data,
	}
}
Exemple #2
0
func (s *Site) initializeSiteInfo() {
	params := viper.GetStringMap("Params")

	permalinks := make(PermalinkOverrides)
	for k, v := range viper.GetStringMapString("Permalinks") {
		permalinks[k] = PathPattern(v)
	}

	s.Info = SiteInfo{
		BaseUrl:         template.URL(helpers.SanitizeUrlKeepTrailingSlash(viper.GetString("BaseUrl"))),
		Title:           viper.GetString("Title"),
		Author:          viper.GetStringMap("author"),
		LanguageCode:    viper.GetString("languagecode"),
		Copyright:       viper.GetString("copyright"),
		DisqusShortname: viper.GetString("DisqusShortname"),
		BuildDrafts:     viper.GetBool("BuildDrafts"),
		canonifyUrls:    viper.GetBool("CanonifyUrls"),
		Pages:           &s.Pages,
		Recent:          &s.Pages,
		Menus:           &s.Menus,
		Params:          params,
		Permalinks:      permalinks,
		Data:            &s.Data,
	}
}
Exemple #3
0
// Render the listing pages based on the meta data
// each unique term within a taxonomy will have a page created
func (s *Site) RenderTaxonomiesLists() error {
	wg := &sync.WaitGroup{}

	taxes := make(chan taxRenderInfo)
	results := make(chan error)

	procs := getGoMaxProcs()

	for i := 0; i < procs*4; i++ {
		wg.Add(1)
		go taxonomyRenderer(s, taxes, results, wg)
	}

	errs := make(chan error)

	go errorCollator(results, errs)

	taxonomies := viper.GetStringMapString("Taxonomies")
	for singular, plural := range taxonomies {
		for key, pages := range s.Taxonomies[plural] {
			taxes <- taxRenderInfo{key, pages, singular, plural}
		}
	}
	close(taxes)

	wg.Wait()

	close(results)

	err := <-errs
	if err != nil {
		return fmt.Errorf("Error(s) rendering taxonomies: %s", err)
	}
	return nil
}
Exemple #4
0
func main() {
	viper.SetConfigName("config")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	urls := viper.GetStringMapString("urls")
	username := viper.GetString("auth.username")
	password := viper.GetString("auth.password")

	for title, url := range urls {
		c := Checker{
			Title:    title,
			URL:      url,
			Username: username,
			Password: password,
		}

		go func() {
			for {
				if err := c.Check(); err != nil {
					log.Println(err)
				}
				time.Sleep(time.Second * 5)
			}
		}()
	}

	select {}
}
Exemple #5
0
func (aca *ACA) fetchAttributes(id, affiliation string) ([]*AttributePair, error) {
	// TODO this attributes should be readed from the outside world in place of configuration file.
	var attributes = make([]*AttributePair, 0)
	attrs := viper.GetStringMapString("aca.attributes")

	for _, flds := range attrs {
		vals := strings.Fields(flds)
		if len(vals) >= 1 {
			val := ""
			for _, eachVal := range vals {
				val = val + " " + eachVal
			}
			attributeVals := strings.Split(val, ";")
			if len(attributeVals) >= 6 {
				attrPair, err := NewAttributePair(attributeVals, nil)
				if err != nil {
					return nil, errors.New("Invalid attribute entry " + val + " " + err.Error())
				}
				if attrPair.GetID() != id || attrPair.GetAffiliation() != affiliation {
					continue
				}
				attributes = append(attributes, attrPair)
			} else {
				Error.Printf("Invalid attribute entry '%v'", vals[0])
			}
		}
	}

	fmt.Printf("%v %v", id, attributes)

	return attributes, nil
}
Exemple #6
0
// populateAffiliationGroupsTable populates affiliation groups table.
//
func (eca *ECA) populateAffiliationGroupsTable() {
	key := "eca.affiliations"
	affiliationGroups := viper.GetStringMapString(key)
	for name := range affiliationGroups {
		eca.populateAffiliationGroup(name, "", key, 1)
	}
}
Exemple #7
0
func GetStringMapString(key, mkey string) (error, string) {
	m := viper.GetStringMapString(key)[mkey]
	if m != "" {
		return nil, m
	}
	return errors.New("can't found:" + key + "," + mkey), ""
}
Exemple #8
0
// ConfigFromViper imports configuration from Viper
func ConfigFromViper() Config {
	return Config{
		AuthServers: viper.GetStringMapString("auth-servers"),
		KeyDir:      viper.GetString("key-dir"),
		UseTLS:      viper.GetBool("tls"),
	}
}
Exemple #9
0
// NewECA sets up a new ECA.
//
func NewECA() *ECA {
	var cooked string

	eca := &ECA{NewCA("eca"), nil, nil, nil, nil, nil}

	raw, err := ioutil.ReadFile(RootPath + "/obc.key")
	if err != nil {
		rand := rand.Reader
		key := make([]byte, 32) // AES-256
		rand.Read(key)
		cooked = base64.StdEncoding.EncodeToString(key)

		err = ioutil.WriteFile(RootPath+"/obc.key", []byte(cooked), 0644)
		if err != nil {
			Panic.Panicln(err)
		}
	} else {
		cooked = string(raw)
	}

	eca.obcKey, err = base64.StdEncoding.DecodeString(cooked)
	if err != nil {
		Panic.Panicln(err)
	}

	users := viper.GetStringMapString("eca.users")
	for id, pw := range users {
		eca.newUser(id, pw)
	}

	return eca
}
Exemple #10
0
// Render a page per taxonomy that lists the terms for that taxonomy
func (s *Site) RenderListsOfTaxonomyTerms() (err error) {
	taxonomies := viper.GetStringMapString("Taxonomies")
	for singular, plural := range taxonomies {
		n := s.NewNode()
		n.Title = strings.Title(plural)
		s.setUrls(n, plural)
		n.Data["Singular"] = singular
		n.Data["Plural"] = plural
		n.Data["Terms"] = s.Taxonomies[plural]
		// keep the following just for legacy reasons
		n.Data["OrderedIndex"] = n.Data["Terms"]
		n.Data["Index"] = n.Data["Terms"]
		layouts := []string{"taxonomy/" + singular + ".terms.html", "_default/terms.html", "indexes/indexes.html"}
		layouts = s.appendThemeTemplates(layouts)
		if s.layoutExists(layouts...) {
			b, err := s.renderPage("taxonomy terms for "+singular, n, layouts...)
			if err != nil {
				return err
			}
			if err := s.WriteDestPage(plural+"/index.html", b); err != nil {
				return err
			}
		}
	}

	return
}
func initDB() {
	dbConfig := viper.GetStringMapString("database")
	dsn := []string{dbConfig["dbUser"], ":", dbConfig["dbPass"], "@tcp(", dbConfig["dbHost"], ":3306)/", dbConfig["dbName"], "?charset=utf8"}

	db, _ = sql.Open("mysql", strings.Join(dsn, ""))
	//errHandle(err)
}
Exemple #12
0
Fichier : run.go Projet : dyweb/Ayi
func listAllScripts() {
	scripts := viper.GetStringMapString("scripts")
	log.Info("all avaliable scripts are listed below")
	for name := range scripts {
		fmt.Println(name)
	}
}
Exemple #13
0
func (eca *ECA) populateAffiliationGroupsTable() {
	// populate affiliation groups
	key := "eca.affiliation_groups"
	affiliation_groups := viper.GetStringMapString(key)
	for name, _ := range affiliation_groups {
		eca.populateAffiliationGroup(name, "", key)
	}
}
Exemple #14
0
func windHandler(w http.ResponseWriter, r *http.Request, db *data.Database) {
	t, _ := computeTime(r.FormValue("time"))

	var queries []map[string]string
	err := json.Unmarshal([]byte(r.FormValue("query")), &queries)
	if err != nil {
		jww.ERROR.Println(err)
		return
	}

	var result struct {
		Data  [][]float64
		Label []string
	}

	result.Data = make([][]float64, len(queries))
	result.Label = make([]string, len(queries))

	rxp := regexp.MustCompile(`\[([^]]*)\]`)
	for index, querymap := range queries {
		result.Label[index] = querymap["label"]
		result.Data[index] = make([]float64, 32)

		id := "%"
		if _, ok := querymap["id"]; ok {
			id = querymap["id"]
		}
		datatype := "%"
		if _, ok := querymap["type"]; ok {
			datatype = querymap["type"]
		}
		if _, ok := querymap["label"]; ok {
			result.Label[index] = querymap["label"]
		} else {
			result.Label[index] = "Unknown"
		}
		cols := rxp.FindStringSubmatch(datatype)
		var col string
		if len(cols) > 1 {
			col = cols[1]
		} else {
			col = "avg"
		}

		key := rxp.ReplaceAllString(datatype, "")

		for row := range db.QueryWind(t, key, col, id, 0) {
			speed := units.NewSpeedMetersPerSecond(row.Value)
			result.Data[index][int(row.Dir)], err = speed.Get(viper.GetStringMapString("units")["WindSpeed"])
			if err != nil {
				jww.ERROR.Println(err)
				return
			}
		}
	}

	json.NewEncoder(w).Encode(result)
}
Exemple #15
0
func write_config(c *cli.Context, files map[string]string) error {
	user := c.String("user")
	password := c.String("password")
	if len(user) == 0 || len(password) == 0 {
		cli.ShowSubcommandHelp(c)
		return nil
	}
	for n, b := range files {
		if err := os.MkdirAll(path.Dir(n), 0700); err != nil {
			return err
		}
		fmt.Printf("generate file %s\n", n)
		fd, err := os.OpenFile(
			n,
			os.O_WRONLY|os.O_CREATE|os.O_EXCL,
			0600)
		if err != nil {
			return err
		}
		defer fd.Close()
		t, err := template.New("").Parse(b)
		if err != nil {
			return err
		}
		driver := viper.GetString("database.driver")
		switch driver {
		case "postgres":
			driver = "pgsql"
		}
		args := viper.GetStringMapString("database.args")
		if err = t.Execute(fd, struct {
			Driver      string
			User        string
			Password    string
			Name        string
			Host        string
			Port        string
			UserTable   string
			AliasTable  string
			DomainTable string
		}{
			Driver:      driver,
			Host:        args["host"],
			Name:        args["dbname"],
			Port:        args["port"],
			Password:    password,
			User:        user,
			UserTable:   User{}.TableName(),
			AliasTable:  Alias{}.TableName(),
			DomainTable: Domain{}.TableName(),
		}); err != nil {
			return err
		}
	}

	return nil
}
Exemple #16
0
// populateAffiliationGroup populates the affiliation groups table.
//
func (eca *ECA) populateAffiliationGroup(name, parent, key string) {
	eca.registerAffiliationGroup(name, parent)
	newKey := key + "." + name
	affiliationGroups := viper.GetStringMapString(newKey)
	for childName := range affiliationGroups {
		eca.populateAffiliationGroup(childName, name, newKey)
	}

}
Exemple #17
0
func (s *Site) Stats() {
	jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))

	indexes := viper.GetStringMapString("Indexes")

	for _, pl := range indexes {
		jww.FEEDBACK.Printf("%d %s index created\n", len(s.Indexes[pl]), pl)
	}
}
Exemple #18
0
func (s *Site) Stats() {
	jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))

	taxonomies := viper.GetStringMapString("Taxonomies")

	for _, pl := range taxonomies {
		jww.FEEDBACK.Printf("%d %s created\n", len(s.Taxonomies[pl]), pl)
	}
}
Exemple #19
0
func (s *Site) BuildSiteMeta() (err error) {
	s.Indexes = make(IndexList)
	s.Sections = make(Index)

	indexes := viper.GetStringMapString("Indexes")
	jww.INFO.Printf("found indexes: %#v\n", indexes)

	for _, plural := range indexes {
		s.Indexes[plural] = make(Index)
		for _, p := range s.Pages {
			vals := p.GetParam(plural)
			weight := p.GetParam(plural + "_weight")
			if weight == nil {
				weight = 0
			}

			if vals != nil {
				v, ok := vals.([]string)
				if ok {
					for _, idx := range v {
						x := WeightedPage{weight.(int), p}

						s.Indexes[plural].Add(idx, x)
					}
				} else {
					jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
				}
			}
		}
		for k := range s.Indexes[plural] {
			s.Indexes[plural][k].Sort()
		}
	}

	for i, p := range s.Pages {
		s.Sections.Add(p.Section, WeightedPage{s.Pages[i].Weight, s.Pages[i]})
	}

	for k := range s.Sections {
		s.Sections[k].Sort()
	}

	s.Info.Indexes = s.Indexes

	if len(s.Pages) == 0 {
		return
	}
	s.Info.LastChange = s.Pages[0].Date

	// populate pages with site metadata
	for _, p := range s.Pages {
		p.Site = s.Info
	}

	return
}
Exemple #20
0
// GetTestConfig : Return test config based on package name
func GetTestConfig(packageName string) map[string]string {
	path, _ := filepath.Abs("../")
	viper.SetConfigName("test_config")
	viper.AddConfigPath(path)
	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Error : %s", err)
	}

	return viper.GetStringMapString(packageName)
}
Exemple #21
0
func (s *Site) Stats() {
	jww.FEEDBACK.Println(s.draftStats())
	jww.FEEDBACK.Println(s.futureStats())
	jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))
	jww.FEEDBACK.Printf("%d paginator pages created \n", s.Info.paginationPageCount)
	taxonomies := viper.GetStringMapString("Taxonomies")

	for _, pl := range taxonomies {
		jww.FEEDBACK.Printf("%d %s created\n", len(s.Taxonomies[pl]), pl)
	}
}
Exemple #22
0
func getConfiguredFormFieldNames(formName string) []string {
	configuredFields := viper.GetStringMapString("stormpath.web." + formName + ".form.fields")
	fieldOrder := viper.GetStringSlice("stormpath.web." + formName + ".form.fieldOrder")

	for fieldName := range configuredFields {
		if !contains(fieldOrder, fieldName) {
			fieldOrder = append(fieldOrder, fieldName)
		}
	}
	return fieldOrder
}
Exemple #23
0
func main() {
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/hermes/")
	viper.AddConfigPath("$HOME/.hermes/")
	err := viper.ReadInConfig()
	errHandle(err)
	hermesConfig := viper.GetStringMapString("hermes")
	viper.Set("URL", hermesConfig["URL"])
	//Just keeping this around so I can reference to it.  Seriously.
	//dbConfig := viper.GetStringMapString("database")
	for {
		msgBuffer()
	}
}
Exemple #24
0
func (s *Site) initializeSiteInfo() {
	params, ok := viper.Get("Params").(map[string]interface{})
	if !ok {
		params = make(map[string]interface{})
	}

	permalinks := make(PermalinkOverrides)
	for k, v := range viper.GetStringMapString("Permalinks") {
		permalinks[k] = PathPattern(v)
	}

	s.Info = SiteInfo{
		BaseUrl:         template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))),
		Title:           viper.GetString("Title"),
		Author:          viper.GetStringMapString("author"),
		LanguageCode:    viper.GetString("languagecode"),
		Copyright:       viper.GetString("copyright"),
		DisqusShortname: viper.GetString("DisqusShortname"),
		Recent:          &s.Pages,
		Menus:           &s.Menus,
		Params:          params,
		Permalinks:      permalinks,
	}
}
Exemple #25
0
func init() {
	// Default log level - Warn
	log.SetLevel(log.WarnLevel)

	// Defaults
	viper.SetDefault("port", "5000")
	viper.SetDefault("log_level", "warn")
	viper.SetDefault("redis_host", "127.0.0.1")
	viper.SetDefault("redis_port", "6379")
	viper.SetDefault("clients", map[string]string{
		"soundwave": "CHANGE_ME",
		"shockwave": "CHANGE_ME",
	})

	// From file
	viper.SetConfigName("perceptor")        // name of config file (without extension)
	viper.AddConfigPath("/etc/perceptor/")  // path to look for the config file in
	viper.AddConfigPath("$HOME/.perceptor") // call multiple times to add many search paths
	viper.AddConfigPath("$PWD/.perceptor")  // call multiple times to add many search paths
	err := viper.ReadInConfig()             // Find and read the config file
	if err != nil {                         // Handle errors reading the config file
		log.Warnf("No config file found or is not properly formatted: %s", err)
	}

	// From environment vars - Only top level are configured from env vars
	viper.SetEnvPrefix("perceptor")
	viper.AutomaticEnv()

	switch viper.GetString("log_level") {
	case "debug":
		log.SetLevel(log.DebugLevel)
	case "info":
		log.SetLevel(log.InfoLevel)
	case "warn":
		log.SetLevel(log.WarnLevel)
	case "error":
		log.SetLevel(log.ErrorLevel)
	default:
		log.SetLevel(log.WarnLevel)
	}

	// Warn of Secrets have not been set
	for k, v := range viper.GetStringMapString("clients") {
		if v == "CHANGE_ME" || v == "SECRET" {
			log.Warnf("Client key (%s) has not been set", k)
		}
	}
}
Exemple #26
0
// populateAffiliationGroup populates the affiliation groups table.
//
func (eca *ECA) populateAffiliationGroup(name, parent, key string, level int) {
	eca.registerAffiliationGroup(name, parent)
	newKey := key + "." + name

	if level == 0 {
		affiliationGroups := viper.GetStringSlice(newKey)
		for ci := range affiliationGroups {
			eca.registerAffiliationGroup(affiliationGroups[ci], name)
		}
	} else {
		affiliationGroups := viper.GetStringMapString(newKey)
		for childName := range affiliationGroups {
			eca.populateAffiliationGroup(childName, name, newKey, level-1)
		}
	}
}
Exemple #27
0
// Generate thumbnails
// if image is empty generate all thumbnails
func Generate(image string, overwrite bool) (err error) {
	viper.SetDefault("jpeg_quality", 85)
	err = viper.ReadInConfig()
	if err != nil {
		return err
	}

	folder_path = strings.TrimRight(viper.GetString("images_folder"), "/")
	thumbs_path = strings.TrimRight(viper.GetString("thumbs_folder"), "/")
	thumb_sizes = viper.GetStringMapString("sizes")

	if !Exists(folder_path) {
		err = errors.New("Images folder doesn't exists")
		return err
	} else if !IsDirectory(folder_path) {
		err = errors.New("Images folder is not a directory")
		return err
	}

	if image == "" {
		images, _ := ioutil.ReadDir(folder_path)
		for _, f := range images {
			if IsImage(folder_path + "/" + f.Name()) {
				err = generateThumbnail(f.Name(), overwrite)
				if err != nil {
					return err
				}
			}
		}
	} else {
		image_file_path := folder_path + "/" + image
		if Exists(image_file_path) {
			if IsImage(image_file_path) {
				err = generateThumbnail(image, overwrite)
				if err != nil {
					return err
				}
			} else {
				return errors.New("That file is not an image")
			}
		} else {
			return errors.New("That file doesn't exist")
		}
	}

	return err
}
Exemple #28
0
//IocAction ioc action
func IocAction(fn func(*cli.Context, *inject.Graph) error) cli.ActionFunc {
	return Action(func(ctx *cli.Context) error {
		var inj inject.Graph
		logger := Logger()
		if !IsProduction() {
			inj.Logger = logger
		}

		db, err := OpenDatabase()
		if err != nil {
			return err
		}
		rep := OpenRedis()

		wfg := viper.GetStringMapString("workers.config")
		wfg["server"] = fmt.Sprintf(
			"%s:%d",
			viper.GetString("redis.host"),
			viper.GetInt("redis.port"))
		wfg["database"] = viper.GetString("redis.db")
		workers.Configure(wfg)

		i1n := i18n.I18n{Locales: make(map[string]map[string]string)}
		if err := inj.Provide(
			&inject.Object{Value: logger},
			&inject.Object{Value: db},
			&inject.Object{Value: rep},
			&inject.Object{Value: &i18n.DatabaseProvider{}},
			&inject.Object{Value: &i1n},
		); err != nil {
			return err
		}
		Loop(func(en Engine) error {
			if e := en.Map(&inj); e != nil {
				return e
			}
			return inj.Provide(&inject.Object{Value: en})
		})
		if err := inj.Populate(); err != nil {
			return err
		}
		if err := i1n.Load("locales"); err != nil {
			return err
		}
		return fn(ctx, &inj)
	})
}
Exemple #29
0
func ReadConfig(agent *AgentCommand) *Config {
	err := viper.ReadInConfig() // Find and read the config file
	if err != nil {             // Handle errors reading the config file
		logrus.Infof("No valid config found: %s \n Applying default values.", err)
	}

	tags := viper.GetStringMapString("tags")
	server := viper.GetBool("server")
	nodeName := viper.GetString("node_name")

	if server {
		tags["dkron_server"] = "true"
	}
	tags["dkron_version"] = agent.Version

	InitLogger(viper.GetString("log_level"), nodeName)

	return &Config{
		NodeName:        nodeName,
		BindAddr:        viper.GetString("bind_addr"),
		AdvertiseAddr:   viper.GetString("advertise_addr"),
		HTTPAddr:        viper.GetString("http_addr"),
		Discover:        viper.GetString("discover"),
		Backend:         viper.GetString("backend"),
		BackendMachines: viper.GetStringSlice("backend_machine"),
		Server:          server,
		Profile:         viper.GetString("profile"),
		StartJoin:       viper.GetStringSlice("join"),
		Tags:            tags,
		Keyspace:        viper.GetString("keyspace"),
		EncryptKey:      viper.GetString("encrypt"),
		UIDir:           viper.GetString("ui_dir"),
		RPCPort:         viper.GetInt("rpc_port"),

		MailHost:     viper.GetString("mail_host"),
		MailPort:     uint16(viper.GetInt("mail_port")),
		MailUsername: viper.GetString("mail_username"),
		MailPassword: viper.GetString("mail_password"),
		MailFrom:     viper.GetString("mail_from"),
		MailPayload:  viper.GetString("mail_payload"),

		WebhookURL:     viper.GetString("webhook_url"),
		WebhookPayload: viper.GetString("webhook_payload"),
		WebhookHeaders: viper.GetStringSlice("webhook_headers"),
	}
}
Exemple #30
0
// populateUsersTable populates the users table.
//
func (eca *ECA) populateUsersTable() {
	// populate user table
	users := viper.GetStringMapString("eca.users")
	for id, flds := range users {
		vals := strings.Fields(flds)
		role, err := strconv.Atoi(vals[0])
		if err != nil {
			Panic.Panicln(err)
		}

		var affiliation, affiliationRole string
		if len(vals) >= 4 {
			affiliation = vals[2]
			affiliationRole = vals[3]
		}
		eca.registerUser(id, affiliation, affiliationRole, pb.Role(role), vals[1])
	}
}