Пример #1
0
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
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
func (u *Account) PreInsert(s gorp.SqlExecutor) error {
	//u.Account_id = CreateGUID()
	//u.Version = time.Now()

	var val int
	if err := s.SelectOne(&val, "select max(sort) from jzb_accounts"); err == nil {
		u.Sort = val + 1
	}
	fmt.Println(u)
	return nil
}
Пример #5
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
}
Пример #6
0
func (atb *AgentTrackerBinding) setClientKeyInDB(
	agentID, accountID string, keyBytes []byte, db gorp.SqlExecutor) error {

	_, err := db.Exec(
		"UPDATE agent SET account_id = $2, encrypted_client_key = $3 WHERE id = $1",
		agentID, accountID, keyBytes)
	if err != nil {
		return err
	}

	return nil
}
Пример #7
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
}
Пример #8
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
}
Пример #9
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
}
Пример #10
0
func (b *AccountManagerBinding) get(
	db gorp.SqlExecutor, id snowflake.Snowflake) (*AccountBinding, error) {

	var row AccountWithStaffCapability
	err := db.SelectOne(
		&row,
		"SELECT a.id, a.nonce, a.mac, a.encrypted_system_key, a.encrypted_user_key,"+
			" a.encrypted_private_key, a.public_key,"+
			" c.id AS staff_capability_id, c.nonce AS staff_capability_nonce,"+
			" c.encrypted_private_data, c.public_data"+
			" FROM account a LEFT OUTER JOIN capability c ON a.staff_capability_id = c.id"+
			" WHERE a.id = $1",
		id.String())
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, proto.ErrAccountNotFound
		}
		return nil, err
	}

	ab := row.Bind(b.Backend)

	rows, err := db.Select(
		PersonalIdentity{},
		"SELECT namespace, id, account_id, verified FROM personal_identity WHERE account_id = $1",
		id.String())
	switch err {
	case sql.ErrNoRows:
	case nil:
		ab.identities = make([]proto.PersonalIdentity, len(rows))
		for i, row := range rows {
			ab.identities[i] = &PersonalIdentityBinding{row.(*PersonalIdentity)}
		}
	default:
		return nil, err
	}

	return ab, nil
}
Пример #11
0
func (b *AccountManagerBinding) resolve(
	db gorp.SqlExecutor, namespace, id string) (*AccountBinding, error) {

	var pid PersonalIdentity
	err := db.SelectOne(
		&pid,
		"SELECT account_id FROM personal_identity WHERE namespace = $1 AND id = $2",
		namespace, id)
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, proto.ErrAccountNotFound
		}
		return nil, err
	}

	var accountID snowflake.Snowflake
	if err := accountID.FromString(pid.AccountID); err != nil {
		return nil, err
	}

	return b.get(db, accountID)
}
Пример #12
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
}