示例#1
0
文件: fop_imginfo.go 项目: shtlee/qa
// upload the file and get the download url
func (self *FopImgInfo) doTestGetImgUrl() (url string, err error) {
	entry := self.BucketName + ":" + self.Key

	dt := da.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		return
	}
	authPolicy := &uptoken.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
	}
	authPolicy.Deadline += uint32(time.Now().Unix())
	token := uptoken.MakeAuthTokenString(self.Env.AccessKey, self.Env.SecretKey, authPolicy)
	_, code, err := rsservice.Upload(entry, self.SrcImg, "", "", "", token)

	if err != nil || code != 200 {
		return
	}

	getRet, code, err := rsservice.Get(entry, "", "", 3600)
	if err != nil || code != 200 {
		return
	}

	url = getRet.URL
	return
}
示例#2
0
文件: publish.go 项目: shtlee/qa
func (p *Pub) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(p, conf); err != nil {
		return
	}
	if err = config.LoadEx(&p.Env, env); err != nil {
		return
	}
	dt := da.NewTransport(p.Env.AccessKey, p.Env.SecretKey, nil)
	p.rsCli, err = rs.New(p.Env.Hosts, p.Env.Ips, dt)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.pubCli, err = pub.New(p.Env.Hosts["pu"], p.Env.Ips["pu"], dt)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.DataFile = filepath.Join(path, p.DataFile)
	domainRegexp, err := regexp.Compile(p.NormalDomainRegexp)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.isNormalDomain = domainRegexp.Match([]byte(p.Domain))

	return
}
示例#3
0
func (self *UpRPut) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		err = errors.Info(err, "UpResuPut init failed")
		return
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		err = errors.Info(err, "UpEnv init failed")
		return
	}
	self.DataFile = filepath.Join(path, self.DataFile)
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	host := self.Env.Hosts["up"]
	ip := self.Env.Ips["up"]

	self.Rscli, err = rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		err = errors.Info(err, "Rscli init failed")
		return
	}
	self.Up2cli, err = up2.New(host, ip, self.BlockBits, self.ChunkSize, self.PutRetryTimes, dt)
	if err != nil {
		err = errors.Info(err, "Up2cli init failed")
		return
	}
	return
}
示例#4
0
文件: api_test.go 项目: shtlee/qa
func Init() (err error) {

	dt := digest.NewTransport(AccessKey, SecretKey, nil)
	Up2cli, err = up2.New(hosts["up"], ips["up"], BlockBits, RPutChunkSize, RPutRetryTimes, dt)
	if err != nil {
		return
	}
	Rscli, err = rs.New(hosts, ips, dt)
	if err != nil {
		return
	}
	return
}
示例#5
0
文件: put.go 项目: shtlee/qa
func (self *PutFile) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		return err
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		return err
	}
	dt := da.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	self.Conn, err = rs.New(self.Env.Hosts, self.Env.Ips, dt)
	self.DataFile = filepath.Join(path, self.DataFile)
	return
}
示例#6
0
func doTestInit(t *testing.T) {
	var (
		c Config
	)

	// load config
	b, err := ioutil.ReadFile("qbox.conf")
	if err != nil {
		t.Fatal(err)
	}
	if err = json.Unmarshal(b, &c); err != nil {
		t.Fatal(err)
	}

	// create auth transport layer, uptoken and digest
	auth := &uptoken.AuthPolicy{}
	token := uptoken.MakeAuthTokenString(c.AccessKey, c.SecretKey, auth)
	// uptoken transport
	ut := uptoken.NewTransport(token, nil)

	// digest transport
	dt := digest.NewTransport(c.AccessKey, c.SecretKey, nil)

	if eus, err = eu.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if pubs, err = pub.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if rss, err = rs.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if ucs, err = uc.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if ups, err = up.New(&c, ut); err != nil {
		t.Fatal(err)
	}
	if ims, err = image.New(&c, dt); err != nil {
		t.Fatal(err)
	}
}
示例#7
0
func (self *UpResuPut) doTestRSGet() (msg string, err error) {
	var ret rs.GetRet

	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		return
	}
	begin := time.Now()
	ret, code, err := rsservice.Get(self.EntryURI, "", "", 3600)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestRsGet", begin, end, duration)

	if err != nil || code != 200 {
		return
	}
	self.Url = ret.URL
	return
}
示例#8
0
func (self *UpResuPut) NewRS() (*rs.Service, error) {
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	return rs.New(self.Env.Hosts, self.Env.Ips, dt)
}