当前位置: 首页>>代码示例>>Golang>>正文


Golang Settings.Username方法代码示例

本文整理汇总了Golang中github.com/catalyzeio/catalyze/models.Settings.Username方法的典型用法代码示例。如果您正苦于以下问题:Golang Settings.Username方法的具体用法?Golang Settings.Username怎么用?Golang Settings.Username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/catalyzeio/catalyze/models.Settings的用法示例。


在下文中一共展示了Settings.Username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetSettings

// GetSettings returns a Settings object for the current context
func GetSettings(required bool, promptForEnv bool, envName string, baasHost string, paasHost string, username string, password string) *models.Settings {
	HomeDir, err := homedir.Dir()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	file, err := os.Open(filepath.Join(HomeDir, SettingsFile))
	if os.IsNotExist(err) {
		file, err = os.Create(filepath.Join(HomeDir, SettingsFile))
	}
	defer file.Close()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	var settings models.Settings
	json.NewDecoder(file).Decode(&settings)
	// would be best to default this to an initialized map rather than nil
	if settings.Environments == nil {
		settings.Environments = make(map[string]models.AssociatedEnv)
	}

	// try and set the given env first, if it exists
	if envName != "" {
		setGivenEnv(envName, &settings)
		if settings.EnvironmentID == "" || settings.ServiceID == "" {
			fmt.Printf("No environment named \"%s\" has been associated. Run \"catalyze associated\" to see what environments have been associated or run \"catalyze associate\" from a local git repo to create a new association\n", envName)
			os.Exit(1)
		}
	}

	// if no env name was given, try and fetch the local env
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		setLocalEnv(required, &settings)
	}

	// if its not there, fetch the default
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		setDefaultEnv(&settings)
	}

	// if no default, fetch the first associated env and print warning
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		// warn and ask
		setFirstAssociatedEnv(required, promptForEnv, &settings)
	}

	// if no env found, warn and quit
	if required && (settings.EnvironmentID == "" || settings.ServiceID == "") {
		fmt.Println("No Catalyze environment has been associated. Run \"catalyze associate\" from a local git repo first")
		os.Exit(1)
	}

	settings.BaasHost = baasHost
	settings.PaasHost = paasHost
	settings.Username = username
	settings.Password = password
	return &settings
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:61,代码来源:settings.go

示例2: promptForCredentials

func promptForCredentials(settings *models.Settings) {
	var username string
	fmt.Print("Username: ")
	fmt.Scanln(&username)
	settings.Username = username
	fmt.Print("Password: ")
	var fd uintptr
	if runtime.GOOS == "windows" {
		stdIn, _, _ := term.StdStreams()
		fd, _ = term.GetFdInfo(stdIn)
	}
	bytes, _ := terminal.ReadPassword(int(fd))
	fmt.Println("")
	settings.Password = string(bytes)
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:15,代码来源:session.go

示例3: Logs

// Logs is a way to stream logs from Kibana to your local terminal. This is
// useful because Kibana is hard to look at because it splits every single
// log statement into a separate block that spans multiple lines so it's
// not very cohesive. This is intended to be similar to the `heroku logs`
// command.
func Logs(queryString string, tail bool, hours int, minutes int, seconds int, settings *models.Settings) {
	if settings.Username == "" || settings.Password == "" {
		// sometimes this will be filled in from env variables
		// if it is, just use that and don't prompt them
		settings.Username = ""
		settings.Password = ""
		fmt.Println("Please enter your logging dashboard credentials")
	}
	// if we remove the session token, the CLI will prompt for the
	// username/password normally. It will also set the username/password
	// on the settings object.
	sessionToken := settings.SessionToken
	settings.SessionToken = ""

	helpers.SignIn(settings)

	env := helpers.RetrieveEnvironment("pod", settings)
	var domain = env.Data.DNSName
	if domain == "" {
		domain = fmt.Sprintf("%s.catalyze.io", env.Data.Namespace)
	}

	urlString := fmt.Sprintf("https://%s/__es", domain)

	offset := time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second
	timestamp := time.Now().In(time.UTC).Add(-1 * offset)

	from := 0
	query := &models.LogQuery{
		Fields: []string{"@timestamp", "message"},
		Query: &models.Query{
			Wildcard: map[string]string{
				"message": queryString,
			},
		},
		Filter: &models.FilterRange{
			Range: &models.RangeTimestamp{
				Timestamp: map[string]string{
					"gt": fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", timestamp.Year(), timestamp.Month(), timestamp.Day(), timestamp.Hour(), timestamp.Minute(), timestamp.Second()),
				},
			},
		},
		Sort: &models.LogSort{
			Timestamp: map[string]string{
				"order": "asc",
			},
			Message: map[string]string{
				"order": "asc",
			},
		},
		From: from,
		Size: 50,
	}

	var tr = &http.Transport{
		TLSClientConfig: &tls.Config{
			MinVersion: tls.VersionTLS12,
		},
	}

	client := &http.Client{
		Transport: tr,
	}

	settings.SessionToken = sessionToken
	config.SaveSettings(settings)

	fmt.Println("        @timestamp       -        message")
	for {
		query.From = from
		b, err := json.Marshal(*query)
		if err != nil {
			panic(err)
		}
		reader := bytes.NewReader(b)

		req, _ := http.NewRequest("GET", fmt.Sprintf("%s/_search", urlString), reader)
		req.SetBasicAuth(settings.Username, settings.Password)

		resp, err := client.Do(req)
		if err != nil {
			fmt.Println(err.Error())
		}
		respBody, _ := ioutil.ReadAll(resp.Body)
		resp.Body.Close()
		if resp.StatusCode < 200 || resp.StatusCode >= 300 {
			fmt.Println(fmt.Errorf("%d %s", resp.StatusCode, string(respBody)).Error())
			os.Exit(1)
		}
		var logs models.Logs
		json.Unmarshal(respBody, &logs)
		for _, lh := range *logs.Hits.Hits {
			fmt.Printf("%s - %s\n", lh.Fields["@timestamp"][0], lh.Fields["message"][0])
		}
		if !tail {
//.........这里部分代码省略.........
开发者ID:jkoelndorfer,项目名称:cli,代码行数:101,代码来源:logs.go


注:本文中的github.com/catalyzeio/catalyze/models.Settings.Username方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。