예제 #1
0
파일: agent.go 프로젝트: ArkaneMoose/heim
func (atb *AgentTrackerBinding) getFromDB(agentID string, db gorp.SqlExecutor) (*proto.Agent, error) {
	idBytes, err := base64.URLEncoding.DecodeString(agentID)
	if err != nil {
		return nil, fmt.Errorf("invalid agent id %s: %s", agentID, err)
	}

	row, err := db.Get(Agent{}, agentID)
	if err != nil {
		return nil, err
	}
	if row == nil {
		return nil, proto.ErrAgentNotFound
	}

	agentRow := row.(*Agent)
	agent := &proto.Agent{
		ID:  idBytes,
		IV:  agentRow.IV,
		MAC: agentRow.MAC,
		EncryptedClientKey: &security.ManagedKey{
			KeyType:    proto.AgentKeyType,
			IV:         agentRow.IV,
			Ciphertext: agentRow.EncryptedClientKey,
		},
		AccountID: agentRow.AccountID.String,
		Created:   agentRow.Created,
	}
	return agent, nil
}
예제 #2
0
파일: booking.go 프로젝트: mweiss/samples
func (b *Booking) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

	obj, err = exe.Get(User{}, b.UserId)
	if err != nil {
		return fmt.Errorf("Error loading a booking's user (%d): %s", b.UserId, err)
	}
	b.User = obj.(*User)

	obj, err = exe.Get(Hotel{}, b.HotelId)
	if err != nil {
		return fmt.Errorf("Error loading a booking's hotel (%d): %s", b.HotelId, err)
	}
	b.Hotel = obj.(*Hotel)

	if b.CheckInDate, err = time.Parse(SQL_DATE_FORMAT, b.CheckInStr); err != nil {
		return fmt.Errorf("Error parsing check in date '%s':", b.CheckInStr, err)
	}
	if b.CheckOutDate, err = time.Parse(SQL_DATE_FORMAT, b.CheckOutStr); err != nil {
		return fmt.Errorf("Error parsing check out date '%s':", b.CheckOutStr, err)
	}
	return nil
}
예제 #3
0
func (self *Host) PostGet(exe gorp.SqlExecutor) error {
	if self.CategoryId != nil {
		obj, err := exe.Get(Category{}, *self.CategoryId)
		if err != nil {
			return err
		}
		self.Category = obj.(*Category)
	}
	return nil
}
예제 #4
0
//Called after select statement
func (b *Post) PostGet(s gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)
	obj, err = s.Get(User{}, b.UserId)
	if err != nil {
		return fmt.Errorf("Error post's user does not exist (%d): %s", b.UserId, err)
	}
	b.User = obj.(*User)
	return nil
}
예제 #5
0
func (r *RequestCount) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

	obj, err = exe.Get(User{}, r.UserId)
	if err != nil {
		return fmt.Errorf("Error loading a requested user (%d): %s", r.UserId, err)
	}
	r.User = obj.(*User)

	return nil
}
예제 #6
0
func (self *Virus) PostGet(exe gorp.SqlExecutor) error {
	obj, err := exe.Get(Log{}, self.Id)
	if err != nil {
		return err
	}
	self.Log = obj.(*Log)

	obj, err = exe.Get(VirusDef{}, self.VirusDefId)
	if err != nil {
		return err
	}
	self.VirusDef = obj.(*VirusDef)

	return nil
}
예제 #7
0
func (r *Requests) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

	obj, err = exe.Get(User{}, r.UserId)
	if err != nil {
		return fmt.Errorf("Error loading a requested user (%d): %s", r.UserId, err)
	}
	r.User = obj.(*User)

	if r.RequestTime, err = time.Parse(SQL_DATE_FORMAT, r.RequestTimeStr); err != nil {
		return fmt.Errorf("Error parsing request date '%s':", r.RequestTimeStr, err)
	}

	return nil
}
예제 #8
0
func (self *Log) PostGet(exe gorp.SqlExecutor) error {
	obj, err := exe.Get(File{}, self.FileId)
	if err != nil {
		return err
	}
	self.File = obj.(*File)

	obj, err = exe.Get(LogType{}, self.LogtypeId)
	if err != nil {
		return err
	}
	self.LogType = obj.(*LogType)

	obj, err = exe.Get(Device{}, self.DeviceId)
	if err != nil {
		return err
	}
	self.Device = obj.(*Device)

	obj, err = exe.Get(LogLevel{}, self.LevelId)
	if err != nil {
		return err
	}
	self.Level = obj.(*LogLevel)

	obj, err = exe.Get(User{}, self.UserId)
	if err != nil {
		return err
	}
	self.User = obj.(*User)

	obj, err = exe.Get(Service{}, self.ServiceId)
	if err != nil {
		return err
	}
	self.Service = obj.(*Service)
	return nil
}