Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
8012e564
Commit
8012e564
authored
8 years ago
by
Eric Chiang
Browse files
Options
Downloads
Patches
Plain Diff
storage/sql: add password resource
parent
138f55be
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
storage/sql/crud.go
+77
-7
77 additions, 7 deletions
storage/sql/crud.go
storage/sql/migrate.go
+7
-0
7 additions, 0 deletions
storage/sql/migrate.go
with
84 additions
and
7 deletions
storage/sql/crud.go
+
77
−
7
View file @
8012e564
...
...
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"github.com/coreos/dex/storage"
)
...
...
@@ -137,7 +138,7 @@ func (c *conn) UpdateAuthRequest(id string, updater func(a storage.AuthRequest)
a
.
Claims
.
UserID
,
a
.
Claims
.
Username
,
a
.
Claims
.
Email
,
a
.
Claims
.
EmailVerified
,
encoder
(
a
.
Claims
.
Groups
),
a
.
ConnectorID
,
a
.
ConnectorData
,
a
.
Expiry
,
a
.
ID
,
a
.
Expiry
,
r
.
ID
,
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"update auth request: %v"
,
err
)
...
...
@@ -462,14 +463,83 @@ func scanClient(s scanner) (cli storage.Client, err error) {
return
cli
,
nil
}
func
(
c
*
conn
)
DeleteAuthRequest
(
id
string
)
error
{
return
c
.
delete
(
"auth_request"
,
id
)
}
func
(
c
*
conn
)
DeleteAuthCode
(
id
string
)
error
{
return
c
.
delete
(
"auth_code"
,
id
)
}
func
(
c
*
conn
)
DeleteClient
(
id
string
)
error
{
return
c
.
delete
(
"client"
,
id
)
}
func
(
c
*
conn
)
DeleteRefresh
(
id
string
)
error
{
return
c
.
delete
(
"refresh_token"
,
id
)
}
func
(
c
*
conn
)
CreatePassword
(
p
storage
.
Password
)
error
{
p
.
Email
=
strings
.
ToLower
(
p
.
Email
)
_
,
err
:=
c
.
Exec
(
`
insert into password (
email, hash, username, user_id
)
values (
$1, $2, $3, $4
);
`
,
p
.
Email
,
p
.
Hash
,
p
.
Username
,
p
.
UserID
,
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"insert password: %v"
,
err
)
}
return
nil
}
func
(
c
*
conn
)
UpdatePassword
(
email
string
,
updater
func
(
p
storage
.
Password
)
(
storage
.
Password
,
error
))
error
{
return
c
.
ExecTx
(
func
(
tx
*
trans
)
error
{
p
,
err
:=
getPassword
(
tx
,
email
)
if
err
!=
nil
{
return
err
}
np
,
err
:=
updater
(
p
)
if
err
!=
nil
{
return
err
}
_
,
err
=
tx
.
Exec
(
`
update password
set
hash = $1, username = $2, user_id = $3
where email = $4;
`
,
np
.
Hash
,
np
.
Username
,
np
.
UserID
,
p
.
Email
,
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"update password: %v"
,
err
)
}
return
nil
})
}
func
(
c
*
conn
)
GetPassword
(
email
string
)
(
storage
.
Password
,
error
)
{
return
getPassword
(
c
,
email
)
}
func
getPassword
(
q
querier
,
email
string
)
(
p
storage
.
Password
,
err
error
)
{
email
=
strings
.
ToLower
(
email
)
err
=
q
.
QueryRow
(
`
select
email, hash, username, user_id
from password where email = $1;
`
,
email
)
.
Scan
(
&
p
.
Email
,
&
p
.
Hash
,
&
p
.
Username
,
&
p
.
UserID
,
)
if
err
!=
nil
{
if
err
==
sql
.
ErrNoRows
{
return
p
,
storage
.
ErrNotFound
}
return
p
,
fmt
.
Errorf
(
"select password: %v"
,
err
)
}
return
p
,
nil
}
func
(
c
*
conn
)
DeleteAuthRequest
(
id
string
)
error
{
return
c
.
delete
(
"auth_request"
,
"id"
,
id
)
}
func
(
c
*
conn
)
DeleteAuthCode
(
id
string
)
error
{
return
c
.
delete
(
"auth_code"
,
"id"
,
id
)
}
func
(
c
*
conn
)
DeleteClient
(
id
string
)
error
{
return
c
.
delete
(
"client"
,
"id"
,
id
)
}
func
(
c
*
conn
)
DeleteRefresh
(
id
string
)
error
{
return
c
.
delete
(
"refresh_token"
,
"id"
,
id
)
}
func
(
c
*
conn
)
DeletePassword
(
email
string
)
error
{
return
c
.
delete
(
"password"
,
"email"
,
strings
.
ToLower
(
email
))
}
// Do NOT call directly. Does not escape table.
func
(
c
*
conn
)
delete
(
table
,
id
string
)
error
{
result
,
err
:=
c
.
Exec
(
`delete from `
+
table
+
` where
id
= $1`
,
id
)
func
(
c
*
conn
)
delete
(
table
,
field
,
id
string
)
error
{
result
,
err
:=
c
.
Exec
(
`delete from `
+
table
+
` where
`
+
field
+
`
= $1`
,
id
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"delete %s: %v"
,
table
,
id
)
}
...
...
This diff is collapsed.
Click to expand it.
storage/sql/migrate.go
+
7
−
0
View file @
8012e564
...
...
@@ -137,6 +137,13 @@ var migrations = []migration{
connector_id text not null,
connector_data bytea
);
create table password (
email text not null primary key,
hash bytea not null,
username text not null,
user_id text not null
);
-- keys is a weird table because we only ever expect there to be a single row
create table keys (
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment