Пример #1
0
func NewTask(ui common.UI) (workers.WorkerTask, error) {
	c := ui.ConfigGet()
	conf := c.GetSwiftConfig()
	if conf == nil {
		panic("Invalid Configuration object for swift worker")
	}

	conn := swift.Connection{
		UserName: conf.Username,
		ApiKey:   conf.ApiKey,
		AuthUrl:  conf.AuthUrl,
		// https://auth.api.rackspacecloud.com/v1.0
		Region:    conf.Region,
		UserAgent: fmt.Sprintf("hurl/1 http load tester; https://github.com/pquerna/hurl;  username=%s", conf.Username),
	}

	if authTokenCache != "" && storageUrlCache != "" {
		conn.AuthToken = authTokenCache
		conn.StorageUrl = storageUrlCache
	} else {
		err := conn.Authenticate()
		if err != nil {
			return nil, err
		}
		authTokenCache = conn.AuthToken
		storageUrlCache = conn.StorageUrl
	}

	return &Task{
		conf: conf,
		conn: &conn}, nil
}