Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
c14ab3c4
Commit
c14ab3c4
authored
Oct 13, 2016
by
Eric Chiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/memory: add garbage collection method
parent
d27f5e41
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
24 deletions
+20
-24
memory.go
storage/memory/memory.go
+19
-23
memory_test.go
storage/memory/memory_test.go
+1
-1
No files found.
storage/memory/memory.go
View file @
c14ab3c4
...
@@ -4,6 +4,7 @@ package memory
...
@@ -4,6 +4,7 @@ package memory
import
(
import
(
"strings"
"strings"
"sync"
"sync"
"time"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage"
)
)
...
@@ -51,6 +52,24 @@ func (s *memStorage) tx(f func()) {
...
@@ -51,6 +52,24 @@ func (s *memStorage) tx(f func()) {
func
(
s
*
memStorage
)
Close
()
error
{
return
nil
}
func
(
s
*
memStorage
)
Close
()
error
{
return
nil
}
func
(
s
*
memStorage
)
GarbageCollect
(
now
time
.
Time
)
(
result
storage
.
GCResult
,
err
error
)
{
s
.
tx
(
func
()
{
for
id
,
a
:=
range
s
.
authCodes
{
if
now
.
After
(
a
.
Expiry
)
{
delete
(
s
.
authCodes
,
id
)
result
.
AuthCodes
++
}
}
for
id
,
a
:=
range
s
.
authReqs
{
if
now
.
After
(
a
.
Expiry
)
{
delete
(
s
.
authReqs
,
id
)
result
.
AuthRequests
++
}
}
})
return
result
,
nil
}
func
(
s
*
memStorage
)
CreateClient
(
c
storage
.
Client
)
(
err
error
)
{
func
(
s
*
memStorage
)
CreateClient
(
c
storage
.
Client
)
(
err
error
)
{
s
.
tx
(
func
()
{
s
.
tx
(
func
()
{
if
_
,
ok
:=
s
.
clients
[
c
.
ID
];
ok
{
if
_
,
ok
:=
s
.
clients
[
c
.
ID
];
ok
{
...
@@ -240,29 +259,6 @@ func (s *memStorage) GetAuthCode(id string) (c storage.AuthCode, err error) {
...
@@ -240,29 +259,6 @@ func (s *memStorage) GetAuthCode(id string) (c storage.AuthCode, err error) {
return
return
}
}
func
(
s
*
memStorage
)
ClaimCode
(
id
string
)
(
err
error
)
{
s
.
tx
(
func
()
{
if
_
,
ok
:=
s
.
authCodes
[
id
];
!
ok
{
err
=
storage
.
ErrNotFound
return
}
delete
(
s
.
authCodes
,
id
)
})
return
}
func
(
s
*
memStorage
)
ClaimRefresh
(
refreshToken
string
)
(
token
storage
.
RefreshToken
,
err
error
)
{
s
.
tx
(
func
()
{
var
ok
bool
if
token
,
ok
=
s
.
refreshTokens
[
refreshToken
];
!
ok
{
err
=
storage
.
ErrNotFound
return
}
delete
(
s
.
refreshTokens
,
refreshToken
)
})
return
}
func
(
s
*
memStorage
)
UpdateClient
(
id
string
,
updater
func
(
old
storage
.
Client
)
(
storage
.
Client
,
error
))
(
err
error
)
{
func
(
s
*
memStorage
)
UpdateClient
(
id
string
,
updater
func
(
old
storage
.
Client
)
(
storage
.
Client
,
error
))
(
err
error
)
{
s
.
tx
(
func
()
{
s
.
tx
(
func
()
{
client
,
ok
:=
s
.
clients
[
id
]
client
,
ok
:=
s
.
clients
[
id
]
...
...
storage/memory/memory_test.go
View file @
c14ab3c4
...
@@ -7,5 +7,5 @@ import (
...
@@ -7,5 +7,5 @@ import (
)
)
func
TestStorage
(
t
*
testing
.
T
)
{
func
TestStorage
(
t
*
testing
.
T
)
{
conformance
.
RunTest
Suite
(
t
,
New
)
conformance
.
RunTest
s
(
t
,
New
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment