2015-04-07 08:20:55 +00:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/common"
|
2015-04-10 19:52:33 +00:00
|
|
|
"github.com/boltdb/bolt"
|
2015-04-07 08:20:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetToken gets a token by sha value.
|
|
|
|
func (db *DB) GetToken(sha string) (*common.Token, error) {
|
|
|
|
token := &common.Token{}
|
|
|
|
key := []byte(sha)
|
2015-04-10 19:52:33 +00:00
|
|
|
|
|
|
|
err := db.View(func (t *bolt.Tx) error {
|
|
|
|
return get(t, bucketTokens, key, token)
|
|
|
|
})
|
|
|
|
|
2015-04-07 08:20:55 +00:00
|
|
|
return token, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// InsertToken inserts a new user token in the datastore.
|
|
|
|
// If the token already exists and error is returned.
|
|
|
|
func (db *DB) InsertToken(token *common.Token) error {
|
|
|
|
key := []byte(token.Sha)
|
2015-04-10 19:52:33 +00:00
|
|
|
return db.Update(func (t *bolt.Tx) error {
|
|
|
|
return insert(t, bucketTokens, key, token)
|
|
|
|
})
|
2015-04-07 08:20:55 +00:00
|
|
|
// TODO(bradrydzewski) add token to users_token index
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteUser deletes the token.
|
|
|
|
func (db *DB) DeleteToken(token *common.Token) error {
|
|
|
|
key := []byte(token.Sha)
|
2015-04-10 19:52:33 +00:00
|
|
|
return db.Update(func (t *bolt.Tx) error {
|
|
|
|
return delete(t, bucketUser, key)
|
|
|
|
})
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|