mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Split token.Get into method and function.
This commit is contained in:
parent
368791648f
commit
e8ea707904
1 changed files with 12 additions and 8 deletions
|
@ -57,25 +57,29 @@ func SetStatefulFilename(filename string) {
|
||||||
tokens.modTime = time.Time{}
|
tokens.modTime = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetches a stateful token.
|
func (state *state) Get(token string) (*Stateful, error) {
|
||||||
// It returns os.ErrNotExist if the token doesn't exist.
|
state.mu.Lock()
|
||||||
func Get(token string) (*Stateful, error) {
|
defer state.mu.Unlock()
|
||||||
tokens.mu.Lock()
|
err := state.load()
|
||||||
defer tokens.mu.Unlock()
|
|
||||||
err := tokens.load()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if tokens.tokens == nil {
|
if state.tokens == nil {
|
||||||
return nil, os.ErrNotExist
|
return nil, os.ErrNotExist
|
||||||
}
|
}
|
||||||
t := tokens.tokens[token]
|
t := state.tokens[token]
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil, os.ErrNotExist
|
return nil, os.ErrNotExist
|
||||||
}
|
}
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get fetches a stateful token.
|
||||||
|
// It returns os.ErrNotExist if the token doesn't exist.
|
||||||
|
func Get(token string) (*Stateful, error) {
|
||||||
|
return tokens.Get(token)
|
||||||
|
}
|
||||||
|
|
||||||
func (token *Stateful) Check(host, group string, username *string) (string, []string, error) {
|
func (token *Stateful) Check(host, group string, username *string) (string, []string, error) {
|
||||||
if token.Group == "" || group != token.Group {
|
if token.Group == "" || group != token.Group {
|
||||||
return "", nil, errors.New("token for bad group")
|
return "", nil, errors.New("token for bad group")
|
||||||
|
|
Loading…
Reference in a new issue