-
Notifications
You must be signed in to change notification settings - Fork 4
/
memory.go
34 lines (29 loc) · 943 Bytes
/
memory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package integration
import (
"fmt"
)
// MemoryStore implements the Auth storage interfaces and holds all state in memory
// Once the MemoryStore instance is released, all data in that storage is lost
type MemoryStore struct {
authorizations map[string]string
}
// NewMemoryStore returns a MemoryStore pointer
func NewMemoryStore() *MemoryStore {
store := MemoryStore{
authorizations: make(map[string]string, 10),
}
return &store
}
// StoreAuthToken stores the oauth token granted by slack user for a given team ID
func (m *MemoryStore) StoreAuthToken(teamID string, oauthToken string) error {
m.authorizations[teamID] = oauthToken
return nil
}
// GetAuthToken retrieves an oauth token for use with slack given a team ID
func (m *MemoryStore) GetAuthToken(teamID string) (string, error) {
token, ok := m.authorizations[teamID]
if !ok {
return "", fmt.Errorf("Auth token not found for team %v", teamID)
}
return token, nil
}