woodpecker/pkg/store/builtin/token.go

44 lines
1.1 KiB
Go
Raw Normal View History

package builtin
import (
2015-06-13 23:48:06 +00:00
"database/sql"
"github.com/drone/drone/pkg/types"
)
type Tokenstore struct {
2015-06-13 23:48:06 +00:00
*sql.DB
}
2015-06-13 23:48:06 +00:00
func NewTokenstore(db *sql.DB) *Tokenstore {
return &Tokenstore{db}
}
// Token returns a token by ID.
2015-06-13 23:48:06 +00:00
func (db *Tokenstore) Token(id int64) (*types.Token, error) {
return getToken(db, rebind(stmtTokenSelect), id)
}
// TokenLabel returns a token by label
2015-06-13 23:48:06 +00:00
func (db *Tokenstore) TokenLabel(user *types.User, label string) (*types.Token, error) {
return getToken(db, rebind(stmtTokenSelectTokenUserLabel), user.ID, label)
}
// TokenList returns a list of all user tokens.
2015-06-13 23:48:06 +00:00
func (db *Tokenstore) TokenList(user *types.User) ([]*types.Token, error) {
return getTokens(db, rebind(stmtTokenSelectTokenUserId), user.ID)
}
// AddToken inserts a new token into the datastore.
// If the token label already exists for the user
// an error is returned.
2015-06-13 23:48:06 +00:00
func (db *Tokenstore) AddToken(token *types.Token) error {
return createToken(db, rebind(stmtTokenInsert), token)
}
// DelToken removes the DelToken from the datastore.
2015-06-13 23:48:06 +00:00
func (db *Tokenstore) DelToken(token *types.Token) error {
var _, err = db.Exec(rebind(stmtTokenDelete), token.ID)
return err
}