Update SQL storage backend

This commit is contained in:
Joel Speed 2018-01-29 21:07:46 +00:00
parent 0857a0fe09
commit 7fc3f230df
No known key found for this signature in database
GPG Key ID: 6E80578D6751DEFB

View File

@ -110,18 +110,18 @@ func (c *conn) CreateAuthRequest(a storage.AuthRequest) error {
force_approval_prompt, logged_in, force_approval_prompt, logged_in,
claims_user_id, claims_username, claims_preferred_username, claims_user_id, claims_username, claims_preferred_username,
claims_email, claims_email_verified, claims_groups, claims_email, claims_email_verified, claims_groups,
connector_id, connector_data, connector_id,
expiry expiry
) )
values ( values (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
); );
`, `,
a.ID, a.ClientID, encoder(a.ResponseTypes), encoder(a.Scopes), a.RedirectURI, a.Nonce, a.State, a.ID, a.ClientID, encoder(a.ResponseTypes), encoder(a.Scopes), a.RedirectURI, a.Nonce, a.State,
a.ForceApprovalPrompt, a.LoggedIn, a.ForceApprovalPrompt, a.LoggedIn,
a.Claims.UserID, a.Claims.Username, a.Claims.PreferredUsername, a.Claims.UserID, a.Claims.Username, a.Claims.PreferredUsername,
a.Claims.Email, a.Claims.EmailVerified, encoder(a.Claims.Groups), a.Claims.Email, a.Claims.EmailVerified, encoder(a.Claims.Groups),
a.ConnectorID, a.ConnectorData, a.ConnectorID,
a.Expiry, a.Expiry,
) )
if err != nil { if err != nil {
@ -152,16 +152,16 @@ func (c *conn) UpdateAuthRequest(id string, updater func(a storage.AuthRequest)
claims_user_id = $9, claims_username = $10, claims_preferred_username = $11, claims_user_id = $9, claims_username = $10, claims_preferred_username = $11,
claims_email = $12, claims_email_verified = $13, claims_email = $12, claims_email_verified = $13,
claims_groups = $14, claims_groups = $14,
connector_id = $15, connector_data = $16, connector_id = $15,
expiry = $17 expiry = $16
where id = $18; where id = $17;
`, `,
a.ClientID, encoder(a.ResponseTypes), encoder(a.Scopes), a.RedirectURI, a.Nonce, a.State, a.ClientID, encoder(a.ResponseTypes), encoder(a.Scopes), a.RedirectURI, a.Nonce, a.State,
a.ForceApprovalPrompt, a.LoggedIn, a.ForceApprovalPrompt, a.LoggedIn,
a.Claims.UserID, a.Claims.Username, a.Claims.PreferredUsername, a.Claims.UserID, a.Claims.Username, a.Claims.PreferredUsername,
a.Claims.Email, a.Claims.EmailVerified, a.Claims.Email, a.Claims.EmailVerified,
encoder(a.Claims.Groups), encoder(a.Claims.Groups),
a.ConnectorID, a.ConnectorData, a.ConnectorID,
a.Expiry, r.ID, a.Expiry, r.ID,
) )
if err != nil { if err != nil {
@ -183,7 +183,7 @@ func getAuthRequest(q querier, id string) (a storage.AuthRequest, err error) {
force_approval_prompt, logged_in, force_approval_prompt, logged_in,
claims_user_id, claims_username, claims_preferred_username, claims_user_id, claims_username, claims_preferred_username,
claims_email, claims_email_verified, claims_groups, claims_email, claims_email_verified, claims_groups,
connector_id, connector_data, expiry connector_id, expiry
from auth_request where id = $1; from auth_request where id = $1;
`, id).Scan( `, id).Scan(
&a.ID, &a.ClientID, decoder(&a.ResponseTypes), decoder(&a.Scopes), &a.RedirectURI, &a.Nonce, &a.State, &a.ID, &a.ClientID, decoder(&a.ResponseTypes), decoder(&a.Scopes), &a.RedirectURI, &a.Nonce, &a.State,
@ -191,7 +191,7 @@ func getAuthRequest(q querier, id string) (a storage.AuthRequest, err error) {
&a.Claims.UserID, &a.Claims.Username, &a.Claims.PreferredUsername, &a.Claims.UserID, &a.Claims.Username, &a.Claims.PreferredUsername,
&a.Claims.Email, &a.Claims.EmailVerified, &a.Claims.Email, &a.Claims.EmailVerified,
decoder(&a.Claims.Groups), decoder(&a.Claims.Groups),
&a.ConnectorID, &a.ConnectorData, &a.Expiry, &a.ConnectorID, &a.Expiry,
) )
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
@ -208,14 +208,14 @@ func (c *conn) CreateAuthCode(a storage.AuthCode) error {
id, client_id, scopes, nonce, redirect_uri, id, client_id, scopes, nonce, redirect_uri,
claims_user_id, claims_username, claims_preferred_username, claims_user_id, claims_username, claims_preferred_username,
claims_email, claims_email_verified, claims_groups, claims_email, claims_email_verified, claims_groups,
connector_id, connector_data, connector_id,
expiry expiry
) )
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14); values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);
`, `,
a.ID, a.ClientID, encoder(a.Scopes), a.Nonce, a.RedirectURI, a.Claims.UserID, a.ID, a.ClientID, encoder(a.Scopes), a.Nonce, a.RedirectURI, a.Claims.UserID,
a.Claims.Username, a.Claims.PreferredUsername, a.Claims.Email, a.Claims.EmailVerified, a.Claims.Username, a.Claims.PreferredUsername, a.Claims.Email, a.Claims.EmailVerified,
encoder(a.Claims.Groups), a.ConnectorID, a.ConnectorData, a.Expiry, encoder(a.Claims.Groups), a.ConnectorID, a.Expiry,
) )
if err != nil { if err != nil {
@ -233,13 +233,13 @@ func (c *conn) GetAuthCode(id string) (a storage.AuthCode, err error) {
id, client_id, scopes, nonce, redirect_uri, id, client_id, scopes, nonce, redirect_uri,
claims_user_id, claims_username, claims_preferred_username, claims_user_id, claims_username, claims_preferred_username,
claims_email, claims_email_verified, claims_groups, claims_email, claims_email_verified, claims_groups,
connector_id, connector_data, connector_id,
expiry expiry
from auth_code where id = $1; from auth_code where id = $1;
`, id).Scan( `, id).Scan(
&a.ID, &a.ClientID, decoder(&a.Scopes), &a.Nonce, &a.RedirectURI, &a.Claims.UserID, &a.ID, &a.ClientID, decoder(&a.Scopes), &a.Nonce, &a.RedirectURI, &a.Claims.UserID,
&a.Claims.Username, &a.Claims.PreferredUsername, &a.Claims.Email, &a.Claims.EmailVerified, &a.Claims.Username, &a.Claims.PreferredUsername, &a.Claims.Email, &a.Claims.EmailVerified,
decoder(&a.Claims.Groups), &a.ConnectorID, &a.ConnectorData, &a.Expiry, decoder(&a.Claims.Groups), &a.ConnectorID, &a.Expiry,
) )
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
@ -256,16 +256,16 @@ func (c *conn) CreateRefresh(r storage.RefreshToken) error {
id, client_id, scopes, nonce, id, client_id, scopes, nonce,
claims_user_id, claims_username, claims_preferred_username, claims_user_id, claims_username, claims_preferred_username,
claims_email, claims_email_verified, claims_groups, claims_email, claims_email_verified, claims_groups,
connector_id, connector_data, connector_id,
token, created_at, last_used token, created_at, last_used
) )
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15); values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);
`, `,
r.ID, r.ClientID, encoder(r.Scopes), r.Nonce, r.ID, r.ClientID, encoder(r.Scopes), r.Nonce,
r.Claims.UserID, r.Claims.Username, r.Claims.PreferredUsername, r.Claims.UserID, r.Claims.Username, r.Claims.PreferredUsername,
r.Claims.Email, r.Claims.EmailVerified, r.Claims.Email, r.Claims.EmailVerified,
encoder(r.Claims.Groups), encoder(r.Claims.Groups),
r.ConnectorID, r.ConnectorData, r.ConnectorID,
r.Token, r.CreatedAt, r.LastUsed, r.Token, r.CreatedAt, r.LastUsed,
) )
if err != nil { if err != nil {
@ -299,18 +299,17 @@ func (c *conn) UpdateRefreshToken(id string, updater func(old storage.RefreshTok
claims_email_verified = $8, claims_email_verified = $8,
claims_groups = $9, claims_groups = $9,
connector_id = $10, connector_id = $10,
connector_data = $11, token = $11,
token = $12, created_at = $12,
created_at = $13, last_used = $13
last_used = $14
where where
id = $15 id = $14
`, `,
r.ClientID, encoder(r.Scopes), r.Nonce, r.ClientID, encoder(r.Scopes), r.Nonce,
r.Claims.UserID, r.Claims.Username, r.Claims.PreferredUsername, r.Claims.UserID, r.Claims.Username, r.Claims.PreferredUsername,
r.Claims.Email, r.Claims.EmailVerified, r.Claims.Email, r.Claims.EmailVerified,
encoder(r.Claims.Groups), encoder(r.Claims.Groups),
r.ConnectorID, r.ConnectorData, r.ConnectorID,
r.Token, r.CreatedAt, r.LastUsed, id, r.Token, r.CreatedAt, r.LastUsed, id,
) )
if err != nil { if err != nil {
@ -370,7 +369,7 @@ func scanRefresh(s scanner) (r storage.RefreshToken, err error) {
&r.Claims.UserID, &r.Claims.Username, &r.Claims.PreferredUsername, &r.Claims.UserID, &r.Claims.Username, &r.Claims.PreferredUsername,
&r.Claims.Email, &r.Claims.EmailVerified, &r.Claims.Email, &r.Claims.EmailVerified,
decoder(&r.Claims.Groups), decoder(&r.Claims.Groups),
&r.ConnectorID, &r.ConnectorData, &r.ConnectorID,
&r.Token, &r.CreatedAt, &r.LastUsed, &r.Token, &r.CreatedAt, &r.LastUsed,
) )
if err != nil { if err != nil {
@ -655,13 +654,13 @@ func scanPassword(s scanner) (p storage.Password, err error) {
func (c *conn) CreateOfflineSessions(s storage.OfflineSessions) error { func (c *conn) CreateOfflineSessions(s storage.OfflineSessions) error {
_, err := c.Exec(` _, err := c.Exec(`
insert into offline_session ( insert into offline_session (
user_id, conn_id, refresh user_id, conn_id, refresh, connector_data
) )
values ( values (
$1, $2, $3 $1, $2, $3, $4
); );
`, `,
s.UserID, s.ConnID, encoder(s.Refresh), s.UserID, s.ConnID, encoder(s.Refresh), s.ConnectorData,
) )
if err != nil { if err != nil {
if c.alreadyExistsCheck(err) { if c.alreadyExistsCheck(err) {
@ -687,9 +686,10 @@ func (c *conn) UpdateOfflineSessions(userID string, connID string, updater func(
update offline_session update offline_session
set set
refresh = $1 refresh = $1
where user_id = $2 AND conn_id = $3; connector_data = $2
where user_id = $3 AND conn_id = $4;
`, `,
encoder(newSession.Refresh), s.UserID, s.ConnID, encoder(newSession.Refresh), s.ConnectorData, s.UserID, s.ConnID,
) )
if err != nil { if err != nil {
return fmt.Errorf("update offline session: %v", err) return fmt.Errorf("update offline session: %v", err)
@ -705,7 +705,7 @@ func (c *conn) GetOfflineSessions(userID string, connID string) (storage.Offline
func getOfflineSessions(q querier, userID string, connID string) (storage.OfflineSessions, error) { func getOfflineSessions(q querier, userID string, connID string) (storage.OfflineSessions, error) {
return scanOfflineSessions(q.QueryRow(` return scanOfflineSessions(q.QueryRow(`
select select
user_id, conn_id, refresh user_id, conn_id, refresh, connector_data
from offline_session from offline_session
where user_id = $1 AND conn_id = $2; where user_id = $1 AND conn_id = $2;
`, userID, connID)) `, userID, connID))
@ -713,7 +713,7 @@ func getOfflineSessions(q querier, userID string, connID string) (storage.Offlin
func scanOfflineSessions(s scanner) (o storage.OfflineSessions, err error) { func scanOfflineSessions(s scanner) (o storage.OfflineSessions, err error) {
err = s.Scan( err = s.Scan(
&o.UserID, &o.ConnID, decoder(&o.Refresh), &o.UserID, &o.ConnID, decoder(&o.Refresh), &o.ConnectorData,
) )
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {