Example #1
0
func CmdVersion() error {
	versionString := fmt.Sprintf("version %s %s", config.VERSION, config.ArchString())
	logrus.Println(versionString)
	return nil
}
Example #2
0
func InitGlobalOpts(app *cli.Cli, settings *models.Settings) {
	accountsHost := os.Getenv(config.AccountsHostEnvVar)
	if accountsHost == "" {
		accountsHost = config.AccountsHost
	}
	authHost := os.Getenv(config.AuthHostEnvVar)
	if authHost == "" {
		authHost = config.AuthHost
	}
	paasHost := os.Getenv(config.PaasHostEnvVar)
	if paasHost == "" {
		paasHost = config.PaasHost
	}
	username := app.String(cli.StringOpt{
		Name:      "U username",
		Desc:      "Catalyze Username",
		EnvVar:    config.CatalyzeUsernameEnvVar,
		HideValue: true,
	})
	password := app.String(cli.StringOpt{
		Name:      "P password",
		Desc:      "Catalyze Password",
		EnvVar:    config.CatalyzePasswordEnvVar,
		HideValue: true,
	})
	givenEnvName := app.String(cli.StringOpt{
		Name:      "E env",
		Desc:      "The local alias of the environment in which this command will be run",
		EnvVar:    config.CatalyzeEnvironmentEnvVar,
		HideValue: true,
	})
	if loggingLevel := os.Getenv(config.LogLevelEnvVar); loggingLevel != "" {
		if lvl, err := logrus.ParseLevel(loggingLevel); err == nil {
			logrus.SetLevel(lvl)
		}
	}

	app.Before = func() {
		r := config.FileSettingsRetriever{}
		*settings = *r.GetSettings(*givenEnvName, "", accountsHost, authHost, "", paasHost, "", *username, *password)
		logrus.Debugf("%+v", settings)

		if settings.Pods == nil || len(*settings.Pods) == 0 || settings.PodCheck < time.Now().Unix() {
			settings.PodCheck = time.Now().Unix() + 86400
			p := pods.New(settings)
			pods, err := p.List()
			if err == nil {
				settings.Pods = pods
				logrus.Debugf("%+v", settings.Pods)
			} else {
				settings.Pods = &[]models.Pod{}
				logrus.Debugf("Error listing pods: %s", err.Error())
			}
		}
	}
	app.After = func() {
		config.SaveSettings(settings)
	}

	versionString := fmt.Sprintf("version %s %s", config.VERSION, config.ArchString())
	logrus.Debugln(versionString)
	app.Version("v version", versionString)
}
Example #3
0
// GetHeaders builds a map of headers for a new request.
func GetHeaders(sessionToken, version, pod, userID string) map[string][]string {
	b := make([]byte, 32)
	rand.Read(b)
	nonce := base64.StdEncoding.EncodeToString(b)
	timestamp := time.Now().Unix()
	return map[string][]string{
		"Accept":              {"application/json"},
		"Content-Type":        {"application/json"},
		"Authorization":       {fmt.Sprintf("Bearer %s", sessionToken)},
		"X-CLI-Version":       {version},
		"X-Pod-ID":            {pod},
		"X-Request-Nonce":     {nonce},
		"X-Request-Timestamp": {fmt.Sprintf("%d", timestamp)},
		"User-Agent":          {fmt.Sprintf("catalyze-cli-%s %s %s %s", version, runtime.GOOS, config.ArchString(), userID)},
	}
}