예제 #1
0
파일: main.go 프로젝트: bdarnell/cockroach
func main() {
	flag.Parse()

	username, ok := os.LookupEnv(teamcityAPIUserEnv)
	if !ok {
		log.Fatalf("teamcity API username environment variable %s is not set", teamcityAPIUserEnv)
	}
	password, ok := os.LookupEnv(teamcityAPIPasswordEnv)
	if !ok {
		log.Fatalf("teamcity API password environment variable %s is not set", teamcityAPIPasswordEnv)
	}
	importPaths := gotool.ImportPaths([]string{"github.com/cockroachdb/cockroach/..."})

	client := teamcity.New("teamcity.cockroachdb.com", username, password)
	// Queue a build per configuration per package.
	for _, params := range []map[string]string{
		{}, // uninstrumented
		{"env.GOFLAGS": "-race"},
		{"env.TAGS": "deadlock"},
	} {
		for _, importPath := range importPaths {
			params["env.PKG"] = importPath
			build, err := client.QueueBuild(*buildTypeID, *branchName, params)
			if err != nil {
				log.Fatalf("failed to create teamcity build (*buildTypeID=%s *branchName=%s, params=%+v): %s", *buildTypeID, *branchName, params, err)
			}
			log.Printf("created teamcity build (*buildTypeID=%s *branchName=%s, params=%+v): %s", *buildTypeID, *branchName, params, build)
		}
	}
}
예제 #2
0
파일: main.go 프로젝트: jmptrader/cockroach
func main() {
	flag.Parse()

	serverURL, ok := os.LookupEnv(teamcityServerURLEnv)
	if !ok {
		log.Fatalf("teamcity server URL environment variable %s is not set", teamcityServerURLEnv)
	}
	u, err := url.Parse(serverURL)
	if err != nil {
		log.Fatal(err)
	}
	username, ok := os.LookupEnv(teamcityAPIUserEnv)
	if !ok {
		log.Fatalf("teamcity API username environment variable %s is not set", teamcityAPIUserEnv)
	}
	password, ok := os.LookupEnv(teamcityAPIPasswordEnv)
	if !ok {
		log.Fatalf("teamcity API password environment variable %s is not set", teamcityAPIPasswordEnv)
	}
	client := teamcity.New(u.Host, username, password)
	runTC(func(properties map[string]string) {
		build, err := client.QueueBuild(*buildTypeID, *branchName, properties)
		if err != nil {
			log.Fatalf("failed to create teamcity build (*buildTypeID=%s *branchName=%s, properties=%+v): %s", *buildTypeID, *branchName, properties, err)
		}
		log.Printf("created teamcity build (*buildTypeID=%s *branchName=%s, properties=%+v): %s", *buildTypeID, *branchName, properties, build)
	})
}
예제 #3
0
// Right now, this is a really simple proxy that uses defaults
// nearly everywhere, and does nothing other than blindly proxy a
// request to a single server.
func main() {

	bind, provided := os.LookupEnv("BIND_ADDR")
	if !provided {
		bind = ":8090"
	}
	log.Println("Binding to", bind)

	proxyHost, provided := os.LookupEnv("PROXY_ADDR")
	if !provided {
		proxyHost = "127.0.0.1:8080"
	}
	log.Println("Proxying host", proxyHost)

	proxyPath, provided := os.LookupEnv("PROXY_PATH")
	if !provided {
		proxyPath = "/"
	}
	log.Println("Proxy Path", proxyPath)

	proxy := httputil.NewSingleHostReverseProxy(&url.URL{Host: proxyHost, Path: proxyPath, Scheme: "http"})

	if err := http.ListenAndServe(bind, proxy); err != nil {
		log.Panic("Could not start proxy", err)
	}
}
예제 #4
0
// read environment variables for data for http client construction
func InitializeAppSensorRestClient() {

	RestUrl, urlExists = os.LookupEnv("APPSENSOR_REST_ENGINE_URL")
	RestHeaderName, nameExists = os.LookupEnv("APPSENSOR_CLIENT_APPLICATION_ID_HEADER_NAME")
	RestHeaderValue, valueExists = os.LookupEnv("APPSENSOR_CLIENT_APPLICATION_ID_HEADER_VALUE")
	ClientIp, ipExists = os.LookupEnv("APPSENSOR_CLIENT_APPLICATION_IP_ADDRESS")

	missingFields := make([]string, 0)

	if !urlExists {
		missingFields = append(missingFields, "APPSENSOR_REST_ENGINE_URL")
	}

	if !nameExists {
		glog.Info("The APPSENSOR_CLIENT_APPLICATION_ID_HEADER_NAME env var not set, using default value")
		RestHeaderName = "X-Appsensor-Client-Application-Name"
	}

	if !valueExists {
		missingFields = append(missingFields, "APPSENSOR_CLIENT_APPLICATION_ID_HEADER_VALUE")
	}

	if !ipExists {
		missingFields = append(missingFields, "APPSENSOR_CLIENT_APPLICATION_ID_HEADER_VALUE")
	}

	if len(missingFields) > 0 {
		log.Fatal("The following environment variable(s) must be populated: [ " + strings.Join(missingFields, " , ") + " ]")
	}

	glog.Info("Rest client information configured properly.")

}
예제 #5
0
파일: e2e.go 프로젝트: Q-Lee/kubernetes
func KubemarkTest() error {
	// Stop previous run
	err := finishRunning("Stop kubemark", exec.Command("./test/kubemark/stop-kubemark.sh"))
	if err != nil {
		return err
	}
	// If we tried to bring the Kubemark cluster up, make a courtesy
	// attempt to bring it down so we're not leaving resources around.
	//
	// TODO: We should try calling stop-kubemark exactly once. Though to
	// stop the leaking resources for now, we want to be on the safe side
	// and call it explictly in defer if the other one is not called.
	defer xmlWrap("Deferred Stop kubemark", func() error {
		return finishRunning("Stop kubemark", exec.Command("./test/kubemark/stop-kubemark.sh"))
	})

	// Start new run
	backups := []string{"NUM_NODES", "MASTER_SIZE"}
	for _, item := range backups {
		old, present := os.LookupEnv(item)
		if present {
			defer os.Setenv(item, old)
		} else {
			defer os.Unsetenv(item)
		}
	}
	os.Setenv("NUM_NODES", os.Getenv("KUBEMARK_NUM_NODES"))
	os.Setenv("MASTER_SIZE", os.Getenv("KUBEMARK_MASTER_SIZE"))
	err = xmlWrap("Start kubemark", func() error {
		return finishRunning("Start kubemark", exec.Command("./test/kubemark/start-kubemark.sh"))
	})
	if err != nil {
		return err
	}

	// Run kubemark tests
	focus, present := os.LookupEnv("KUBEMARK_TESTS")
	if !present {
		focus = "starting\\s30\\pods"
	}
	test_args := os.Getenv("KUBEMARK_TEST_ARGS")

	err = finishRunning("Run kubemark tests", exec.Command("./test/kubemark/run-e2e-tests.sh", "--ginkgo.focus="+focus, test_args))
	if err != nil {
		return err
	}

	err = xmlWrap("Stop kubemark", func() error {
		return finishRunning("Stop kubemark", exec.Command("./test/kubemark/stop-kubemark.sh"))
	})
	if err != nil {
		return err
	}
	return nil
}
예제 #6
0
파일: main.go 프로젝트: billhathaway/catz
func main() {
	tz := "US/Pacific"
	if cattz, ok := os.LookupEnv("CATZ"); ok {
		tz = cattz
	} else {
		stdtz, ok := os.LookupEnv("TZ")
		if ok {
			tz = stdtz
		}
	}
	srcTZ := flag.String("srctz", "UTC", "input time zone")
	destTZ := flag.String("outtz", tz, "output time zone (defaults to $CATZ or $TZ env if available)")
	debug := flag.Bool("d", false, "enable debug logging")
	timeFormat := flag.String("t", "%Y-%m-%d %H", "strftime format")
	first := flag.Bool("first", false, "only replace first timestamp match per line")
	flag.Parse()

	sourceLocation, err := time.LoadLocation(*srcTZ)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR input TZ %s not known\n", *srcTZ)
		os.Exit(1)
	}

	destLocation, err := time.LoadLocation(*destTZ)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR output TZ %s not known\n", *destTZ)
		os.Exit(1)
	}
	c := &controller{
		srcLoc:  sourceLocation,
		destLoc: destLocation,
		buf:     &bytes.Buffer{},
		debug:   *debug,
	}
	// verify we know how to handle the time format
	c.format, err = strftime.New(*timeFormat)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR time format [%s] had problem converting to go format%s\n", *timeFormat, err)
		os.Exit(1)
	}
	err = c.strftimeToRE(*timeFormat)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR time format [%s] had problem to regex %s\n", *timeFormat, err)
		os.Exit(1)
	}
	// only replace first timestamp occurance, or replace all
	if *first {
		c.matchLimit = 1
	} else {
		c.matchLimit = -1
	}

	os.Exit(c.execute())
}
예제 #7
0
파일: publisher.go 프로젝트: ondaway/poc
func processEnv() {
	if val, exist := os.LookupEnv(COMMNAND_BUS_URL_ENV); exist {
		commandBusUrl = val
	}
	if val, exist := os.LookupEnv(QUEUE_NAME_ENV); exist {
		queueName = val
	}
	if val, exist := os.LookupEnv(LISTENER_PORT_ENV); exist {
		listenerPort = val
	}
}
예제 #8
0
파일: journal.go 프로젝트: cptaffe/journal
func main() {
	home, ok := os.LookupEnv("HOME")
	if !ok {
		log.Fatalf("$HOME not set")
	}
	visual, ok := os.LookupEnv("EDITOR")
	if !ok {
		log.Fatalf("$EDITOR not set")
	}
	year, month, day := time.Now().Date()
	jf := fmt.Sprintf("%s/journal/%d.%d.%d.md", home, day, month, year)
	var f *os.File
	if _, err := os.Stat(jf); os.IsNotExist(err) {
		f, err = os.Create(jf)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Fprintf(f, "%s\n\n", time.Now().Format(time.UnixDate))
	} else if err == nil {
		f, err = os.OpenFile(jf, os.O_RDWR, 0644)
		if err != nil {
			log.Fatal(err)
		}
	} else {
		log.Fatal(err)
	}
	ohash, err := hash(f)
	if err != nil {
		log.Fatal(err)
	}
	// Open editor
	cmd := exec.Command(visual, f.Name())
	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
	// Generate post-edit hash
	nhash, err := hash(f)
	// If hashes are different, ask for commit message
	if ohash != nhash {
		// Add file to git
		cmd := exec.Command("git", "-C", filepath.Dir(f.Name()), "add", f.Name())
		if err := cmd.Run(); err != nil {
			log.Fatal(err)
		}
		// Read commit message from user
		fmt.Printf("Enter a summary and then press ^D\n\n")
		// Commit file to git
		cmd = exec.Command("git", "-C", filepath.Dir(f.Name()), "commit", "--file", "-")
		cmd.Stdin = os.Stdin
		if err := cmd.Run(); err != nil {
			log.Fatal(err)
		}
	}
}
예제 #9
0
파일: rip.go 프로젝트: icholy/rip
func init() {
	if envPrefix, ok := os.LookupEnv("RIP_PREFIX"); ok {
		ripPrefix = envPrefix
		ripPattern = envPrefix + "0"
	}
	if envPattern, ok := os.LookupEnv("RIP_PATTERN"); ok {
		ripPattern = envPattern
	}
	if envRegex, ok := os.LookupEnv("RIP_REGEX"); ok {
		ripRegex = envRegex
	}
}
예제 #10
0
// Verifies that all environment variables are set. Fails if not all are set by
// returning an error.
func verifyEnvironment() error {
	_, cache := os.LookupEnv(cache_path_var)
	_, whost := os.LookupEnv(worker_host_var)
	_, wport := os.LookupEnv(worker_port_var)

	if !cache || !whost || !wport {
		return fmt.Errorf("Application settings missing!\n"+
			"Please set the %s, %s and %s environment variables.",
			cache_path_var, worker_host_var, worker_port_var)
	}

	return nil
}
예제 #11
0
파일: main.go 프로젝트: veteranlu/cockroach
func main() {
	flag.Parse()

	serverURL, ok := os.LookupEnv(teamcityServerURLEnv)
	if !ok {
		log.Fatalf("teamcity server URL environment variable %s is not set", teamcityServerURLEnv)
	}
	u, err := url.Parse(serverURL)
	if err != nil {
		log.Fatal(err)
	}
	username, ok := os.LookupEnv(teamcityAPIUserEnv)
	if !ok {
		log.Fatalf("teamcity API username environment variable %s is not set", teamcityAPIUserEnv)
	}
	password, ok := os.LookupEnv(teamcityAPIPasswordEnv)
	if !ok {
		log.Fatalf("teamcity API password environment variable %s is not set", teamcityAPIPasswordEnv)
	}
	importPaths := gotool.ImportPaths([]string{"github.com/cockroachdb/cockroach/pkg/..."})

	client := teamcity.New(u.Host, username, password)
	// Queue a build per configuration per package.
	for _, params := range []map[string]string{
		{}, // uninstrumented
		{"env.GOFLAGS": "-race"},
		{tagsKey: "deadlock"},
	} {
		if tags, ok := params[tagsKey]; ok {
			params[tagsKey] = strings.Join([]string{tags, stressTag}, " ")
		} else {
			params[tagsKey] = stressTag
		}

		for _, propEvalKV := range []bool{true, false} {
			params["env.COCKROACH_PROPOSER_EVALUATED_KV"] = strconv.FormatBool(propEvalKV)

			for _, importPath := range importPaths {
				params["env.PKG"] = importPath

				build, err := client.QueueBuild(*buildTypeID, *branchName, params)
				if err != nil {
					log.Fatalf("failed to create teamcity build (*buildTypeID=%s *branchName=%s, params=%+v): %s", *buildTypeID, *branchName, params, err)
				}
				log.Printf("created teamcity build (*buildTypeID=%s *branchName=%s, params=%+v): %s", *buildTypeID, *branchName, params, build)
			}
		}
	}
}
예제 #12
0
파일: docker.go 프로젝트: danielfireman/phd
func CreateDockerfile(tmplPath, baseImage, exprID string, serverPort int) (string, error) {
	// Docker likes absolute paths for Dockerfiles.
	dockerfilePath := filepath.Join(filepath.Dir(tmplPath), fmt.Sprintf("Dockerfile_%s", exprID))
	if !strings.HasPrefix(dockerfilePath, "/") {
		v, ok := os.LookupEnv("PWD")
		if !ok {
			return "", fmt.Errorf("Envvar PWD not set.")
		}
		dockerfilePath = filepath.Join(v, dockerfilePath)
	}
	t, err := template.New(filepath.Base(tmplPath)).ParseFiles(tmplPath)
	if err != nil {
		return "", err
	}
	dockerfile, err := os.Create(dockerfilePath)
	if err != nil {
		return "", err
	}
	defer dockerfile.Close()
	if err = t.Execute(dockerfile, struct {
		BaseImage string
		Port      string
	}{
		baseImage,
		fmt.Sprintf("%d", serverPort),
	}); err != nil {
		return "", err
	}
	return dockerfilePath, nil
}
예제 #13
0
func realMain() int {

	// important to have GOPATH defined
	if _, ok := os.LookupEnv("GOPATH"); !ok {
		fmt.Println("Environment variabe GOPATH not found!")
		return 1
	}

	// reads config from file
	config, err := ReadConfig("./config.json")
	if err != nil {
		fmt.Println("Config file reading error. Details: ", err)
		return 2
	}

	// creates Logger (can be replaced with other popular logger)
	log := log.New(os.Stdout, "BEN ", log.Ldate|log.Ltime)
	log.Println("Application launched")

	br, err := NewBenchClient(config.AuthKey, config.Email, config.BaseUrl, log)
	if err != nil {
		log.Println("BenchRunner init failed. Details: ", err)
		return 3
	}

	// Ctrl+C grcefully terminates application
	br.Run()

	log.Println("Application succesfully terminated")
	return 0
}
예제 #14
0
func (cl ConfigLoader) overrideField(sf reflect.StructField, originalVal reflect.Value) error {
	envName := sf.Tag.Get("env")
	if envName == "" {
		return nil
	}
	envVal, present := os.LookupEnv(envName)
	if !present {
		return nil
	}
	var finalVal reflect.Value
	switch originalVal.Interface().(type) {
	default:
		return fmt.Errorf("unable to override fields of type %T", originalVal.Interface())
	case string:
		finalVal = reflect.ValueOf(envVal)
	case int:
		i, err := strconv.Atoi(envVal)
		if err != nil {
			return err
		}
		finalVal = reflect.ValueOf(i)
	}
	originalVal.Set(finalVal)
	return nil
}
예제 #15
0
// invalidatePipeEnvVars stores invalid values in the Pipe specific variables
// of the current environment and returns a function to the reset any modified
// varaibles.
//
// Example:
//
//   defer invalidatePipeEnvVars()()
//   doWork...
//
func invalidatePipeEnvVars() (restore func()) {
	type val struct {
		s  string
		ok bool
	}
	lookupEnv := func(key string) val {
		s, ok := os.LookupEnv(key)
		return val{s, ok}
	}
	envVars := map[string]val{
		"__PIPE_LOG_DIR":          lookupEnv("__PIPE_LOG_DIR"),
		"__PIPE_MACHINE_IP":       lookupEnv("__PIPE_MACHINE_IP"),
		"__PIPE_NOTIFY_HTTP":      lookupEnv("__PIPE_NOTIFY_HTTP"),
		"__PIPE_SERVICE_NAME":     lookupEnv("__PIPE_SERVICE_NAME"),
		"__PIPE_SYSLOG_HOST":      lookupEnv("__PIPE_SYSLOG_HOST"),
		"__PIPE_SYSLOG_PORT":      lookupEnv("__PIPE_SYSLOG_PORT"),
		"__PIPE_SYSLOG_TRANSPORT": lookupEnv("__PIPE_SYSLOG_TRANSPORT"),
	}
	// set empty env vars
	for k := range envVars {
		os.Setenv(k, "")
	}
	// function to reset restore environemnt
	return func() {
		for k, v := range envVars {
			if v.ok {
				os.Setenv(k, v.s)
			} else {
				os.Unsetenv(k)
			}
		}
	}
}
예제 #16
0
func UpgradeTest(args string) bool {
	old, err := os.Getwd()
	if err != nil {
		log.Printf("Failed to os.Getwd(): %v", err)
		return false
	}
	defer os.Chdir(old)
	err = os.Chdir("../kubernetes_skew")
	if err != nil {
		log.Printf("Failed to cd ../kubernetes_skew: %v", err)
		return false
	}
	previous, present := os.LookupEnv("E2E_REPORT_PREFIX")
	if present {
		defer os.Setenv("E2E_REPORT_PREFIX", previous)
	} else {
		defer os.Unsetenv("E2E_REPORT_PREFIX")
	}
	os.Setenv("E2E_REPORT_PREFIX", "upgrade")
	return finishRunning("Upgrade Ginkgo tests",
		exec.Command(
			"go", "run", "./hack/e2e.go",
			"--test",
			"--test_args="+args,
			fmt.Sprintf("--v=%t", *verbose),
			fmt.Sprintf("--check_version_skew=%t", *checkVersionSkew)))
}
예제 #17
0
파일: parse.go 프로젝트: jmptrader/gnatsd
// lookupVariable will lookup a variable reference. It will use block scoping on keys
// it has seen before, with the top level scoping being the environment variables. We
// ignore array contexts and only process the map contexts..
//
// Returns true for ok if it finds something, similar to map.
func (p *parser) lookupVariable(varReference string) (interface{}, bool) {
	// Do special check to see if it is a raw bcrypt string.
	if strings.HasPrefix(varReference, bcryptPrefix) {
		return "$" + varReference, true
	}

	// Loop through contexts currently on the stack.
	for i := len(p.ctxs) - 1; i >= 0; i -= 1 {
		ctx := p.ctxs[i]
		// Process if it is a map context
		if m, ok := ctx.(map[string]interface{}); ok {
			if v, ok := m[varReference]; ok {
				return v, ok
			}
		}
	}

	// If we are here, we have exhausted our context maps and still not found anything.
	// Parse from the environment.
	if vStr, ok := os.LookupEnv(varReference); ok {
		// Everything we get here will be a string value, so we need to process as a parser would.
		if vmap, err := Parse(fmt.Sprintf("%s=%s", pkey, vStr)); err == nil {
			v, ok := vmap[pkey]
			return v, ok
		}
	}
	return nil, false
}
예제 #18
0
func getRedisMaster() string {
	master, set := os.LookupEnv("TEST_REDIS_MASTER")
	if !set {
		master = "mymaster"
	}
	return master
}
예제 #19
0
func getRedisSentinelHost() string {
	redisHost, set := os.LookupEnv("TEST_REDIS_SENTINEL_HOST")
	if !set {
		redisHost = "localhost:26379"
	}
	return redisHost
}
예제 #20
0
func getRedisHost() string {
	redisHost, set := os.LookupEnv("TEST_REDIS_HOST")
	if !set {
		redisHost = "localhost:6379"
	}
	return redisHost
}
예제 #21
0
파일: e2e.go 프로젝트: alex-mohr/kubernetes
func NewKubernetesAnywhere() (*kubernetesAnywhere, error) {
	if *kubernetesAnywherePath == "" {
		return nil, fmt.Errorf("--kubernetes-anywhere-path is required")
	}

	if *kubernetesAnywhereCluster == "" {
		return nil, fmt.Errorf("--kubernetes-anywhere-cluster is required")
	}

	project, ok := os.LookupEnv("PROJECT")
	if !ok {
		return nil, fmt.Errorf("The PROJECT environment variable is required to be set for kubernetes-anywhere")
	}

	// Set KUBERNETES_CONFORMANCE_TEST so the auth info is picked up
	// from kubectl instead of bash inference.
	if err := os.Setenv("KUBERNETES_CONFORMANCE_TEST", "yes"); err != nil {
		return nil, err
	}

	k := &kubernetesAnywhere{
		path:           *kubernetesAnywherePath,
		Phase2Provider: *kubernetesAnywherePhase2Provider,
		Project:        project,
		Cluster:        *kubernetesAnywhereCluster,
	}

	if err := k.writeConfig(); err != nil {
		return nil, err
	}
	return k, nil
}
예제 #22
0
파일: docker.go 프로젝트: hpcloud/fissile
// BuildImage builds a docker image using a directory that contains a Dockerfile
func (d *ImageManager) BuildImage(dockerfileDirPath, name string, stdoutWriter io.WriteCloser) error {

	bio := dockerclient.BuildImageOptions{
		Name:         name,
		NoCache:      true,
		ContextDir:   filepath.Dir(dockerfileDirPath),
		OutputStream: stdoutWriter,
	}

	for _, envVar := range []string{"http_proxy", "https_proxy", "no_proxy"} {
		for _, name := range []string{strings.ToLower(envVar), strings.ToUpper(envVar)} {
			if val, ok := os.LookupEnv(name); ok {
				bio.BuildArgs = append(bio.BuildArgs, dockerclient.BuildArg{
					Name:  name,
					Value: val,
				})
			}
		}
	}

	if stdoutWriter != nil {
		defer func() {
			stdoutWriter.Close()
		}()
	}

	if err := d.client.BuildImage(bio); err != nil {
		return err
	}

	return nil
}
예제 #23
0
파일: main.go 프로젝트: jasonmoo/cryp
func main() {

	key, exists := os.LookupEnv("CRYP_KEY")
	if !exists {
		log.Fatal("CRYP_KEY not set in environment")
	}

	input, err := ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, os.Stdin))
	if err != nil {
		log.Fatal(err)
	}

	if len(input) < cryp.SignatureSize {
		log.Fatal("data too short to decrypt")
	}

	// extract sig prefix from input data
	sig := string(input[:cryp.SignatureSize])
	input = input[cryp.SignatureSize:]

	output, err := cryp.Decrypt(input, sig, []byte(key))
	if err != nil {
		log.Fatal(err)
	}

	os.Stdout.Write(output)

}
예제 #24
0
파일: main.go 프로젝트: jasonmoo/cryp
func main() {

	key, exists := os.LookupEnv("CRYP_KEY")
	if !exists {
		log.Fatal("CRYP_KEY not set in environment")
	}

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}

	output, sig, err := cryp.Encrypt(data, []byte(key))
	if err != nil {
		log.Fatal(err)
	}

	// prepend sig to encrypted data before base64 encoding
	buf := make([]byte, 0, len(sig)+len(output))
	buf = append(buf, sig...)
	buf = append(buf, output...)

	fmt.Println(base64.StdEncoding.EncodeToString(buf))

}
예제 #25
0
func getWithFallBack(key string, fallback string) string {
	value, exists := os.LookupEnv(key)
	if exists {
		return value
	}
	return fallback
}
예제 #26
0
파일: config.go 프로젝트: koron/netupvim
func (c *config) getGithubUser() string {
	if c.GithubUser != "" {
		return c.GithubUser
	}
	v, _ := os.LookupEnv("NETUPVIM_GITHUB_USER")
	return v
}
예제 #27
0
파일: quilt.go 프로젝트: yuenmeiwan/quilt
func updateConfig(conn db.Conn, configPath string) error {
	pathStr, _ := os.LookupEnv(quiltPath)
	if pathStr == "" {
		pathStr = stitch.GetQuiltPath()
	}

	f, err := util.Open(configPath)
	if err != nil {
		f, err = util.Open(filepath.Join(pathStr, configPath))
		if err != nil {
			return err
		}
	}

	defer f.Close()

	sc := scanner.Scanner{
		Position: scanner.Position{
			Filename: configPath,
		},
	}

	spec, err := stitch.New(*sc.Init(bufio.NewReader(f)), pathStr, false)
	if err != nil {
		return err
	}

	return engine.UpdatePolicy(conn, spec)
}
예제 #28
0
파일: config.go 프로젝트: koron/netupvim
func (c *config) getGithubToken() string {
	if c.GithubToken != "" {
		return c.GithubToken
	}
	v, _ := os.LookupEnv("NETUPVIM_GITHUB_TOKEN")
	return v
}
예제 #29
0
func TestMain(m *testing.M) {
	var err error

	if err = configuration.Setup(""); err != nil {
		panic(fmt.Errorf("Failed to setup the configuration: %s", err.Error()))
	}

	if _, c := os.LookupEnv(resource.Database); c != false {

		DB, err = gorm.Open("postgres", configuration.GetPostgresConfigString())

		if err != nil {
			panic("Failed to connect database: " + err.Error())
		}
		defer DB.Close()

		// Make sure the database is populated with the correct types (e.g. bug etc.)
		if configuration.GetPopulateCommonTypes() {
			if err := models.Transactional(DB, func(tx *gorm.DB) error {
				return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
			}); err != nil {
				panic(err.Error())
			}

		}

		// RemoteWorkItemScheduler now available for all other test cases
		RwiScheduler = remoteworkitem.NewScheduler(DB)
	}
	os.Exit(func() int {
		c := m.Run()
		RwiScheduler.Stop()
		return c
	}())
}
예제 #30
0
// Require checks if all the given environment variables ("envVars") are set
// and if one is not set it will skip the test ("t"). The only exception is
// that the unit test resource is always considered to be available unless
// is is explicitly set to false (e.g. "no", "0", "false").
func Require(t *testing.T, envVars ...string) {
	for _, envVar := range envVars {
		v, isSet := os.LookupEnv(envVar)

		// If we don't explicitly opt out from unit tests
		// by specifying ALMIGHTY_RESOURCE_UNIT_TEST=0
		// we're going to run them
		if !isSet && envVar == UnitTest {
			continue
		}

		// Skip test if environment variable is not set.
		if !isSet {
			t.Skipf(StSkipReasonNotSet, envVar)
			return
		}
		// Try to convert to boolean value
		isTrue, err := strconv.ParseBool(v)
		if err != nil {
			t.Skipf(StSkipReasonParseError, envVar, v)
			return
		}

		if !isTrue {
			t.Skipf(StSkipReasonValueFalse, envVar, v)
			return
		}
	}
}