Example #1
0
// initSneakerSecrets loads any remote secrets from S3.
func initSneakerSecrets() {
	secrets, err := RemoteSecrets()
	if err != nil {
		log.WithError(err).Fatal("Could not download secrets")
	}
	log.WithField("total", len(secrets)).Info("Found remote secrets")
	for name, value := range secrets {
		log.WithField("key", name).Info("Setting secret")
		os.Setenv(name, string(value))
	}
}
Example #2
0
// loadSneakerManager returns a sneaker manager if one is configured on the env.
func loadSneakerManager() *sneaker.Manager {
	path := String("SNEAKER_S3_PATH")
	if path == "" {
		return nil
	}
	u, err := url.Parse(path)
	if err != nil {
		log.WithField("path", path).Fatal("Invalid SNEAKER_S3_PATH")
		return nil
	}
	if u.Path != "" && u.Path[0] == '/' {
		u.Path = u.Path[1:]
	}

	sess := session.New()
	config := aws.NewConfig().WithRegion(String("SNEAKER_S3_REGION", "us-west-2")).WithMaxRetries(3)
	return &sneaker.Manager{
		Objects: s3.New(sess, config),
		Envelope: sneaker.Envelope{
			KMS: kms.New(sess, config),
		},
		Bucket: u.Host,
		Prefix: u.Path,
		KeyId:  String("SNEAKER_MASTER_KEY"),
	}
}
Example #3
0
File: config.go Project: snikch/api
func str(private bool, parts ...string) string {
	if len(parts) == 0 {
		return ""
	}
	name := parts[0]
	def := ""
	if len(parts) > 1 {
		def = parts[1]
	}

	l := log.WithField("name", name)

	val := os.Getenv(name)
	if val == "" {
		if !private {
			l = l.WithField("default", def)
		}
		l.Info("No ENV value, using default")
		return def
	}

	if !private {
		l = l.WithFields(logrus.Fields{
			"default": def,
			"value":   val,
		})
	}
	l.Info("Using ENV value")
	return val
}
Example #4
0
File: config.go Project: snikch/api
func int(name string, def int64, private bool) int64 {
	strVal := os.Getenv(name)
	l := log.WithField("name", name)

	// No value? Use the default value provided.
	if strVal == "" {
		if !private {
			l = l.WithField("default", def)
		}
		l.Info("No ENV value, using default")
		return def
	}

	// Attempt conversion from string to an int.
	intVal, err := strconv.Atoi(strVal)
	if err != nil {
		if !private {
			l = log.WithFields(logrus.Fields{
				"value":   strVal,
				"default": def,
			})
		}
		l.Error("Invalid value, using default")
		return def
	}

	// If we're here, it's all good. Use the new value.
	if !private {
		l = log.WithFields(logrus.Fields{
			"default": def,
			"value":   intVal,
		})
	}
	l.Info("Using ENV value")
	return int64(intVal)
}