Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
m-team
oidc
mytoken
server
Commits
a3e58c1d
Commit
a3e58c1d
authored
4 years ago
by
Gabriel Zachmann
Browse files
Options
Downloads
Patches
Plain Diff
restructer polling code in db
parent
f38413b5
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
internal/db/db.go
+13
-0
13 additions, 0 deletions
internal/db/db.go
internal/db/dbModels/authcodeInfo.go
+24
-9
24 additions, 9 deletions
internal/db/dbModels/authcodeInfo.go
with
37 additions
and
9 deletions
internal/db/db.go
+
13
−
0
View file @
a3e58c1d
...
...
@@ -36,3 +36,16 @@ func NewNullString(s string) sql.NullString {
Valid
:
true
,
}
}
func
Transact
(
fn
func
(
*
sqlx
.
Tx
)
error
)
error
{
tx
,
err
:=
DB
()
.
Beginx
()
if
err
!=
nil
{
return
err
}
err
=
fn
(
tx
)
if
err
!=
nil
{
tx
.
Rollback
()
return
err
}
return
tx
.
Commit
()
}
This diff is collapsed.
Click to expand it.
internal/db/dbModels/authcodeInfo.go
+
24
−
9
View file @
a3e58c1d
...
...
@@ -4,6 +4,8 @@ import (
"database/sql"
"log"
"github.com/jmoiron/sqlx"
"github.com/zachmann/mytoken/internal/db"
"github.com/zachmann/mytoken/internal/supertoken/capabilities"
"github.com/zachmann/mytoken/internal/supertoken/restrictions"
...
...
@@ -19,12 +21,12 @@ type AuthFlowInfo struct {
}
type
authFlowInfo
struct
{
State
string
Issuer
string
Restrictions
restrictions
.
Restrictions
Capabilities
capabilities
.
Capabilities
Name
sql
.
NullString
PollingCode
sql
.
NullString
`db:"polling_code"`
State
string
Issuer
string
Restrictions
restrictions
.
Restrictions
Capabilities
capabilities
.
Capabilities
Name
sql
.
NullString
PollingCode
ID
*
uint64
`db:"polling_code
_id
"`
}
func
newAuthFlowInfo
(
i
*
AuthFlowInfo
)
*
authFlowInfo
{
...
...
@@ -34,13 +36,26 @@ func newAuthFlowInfo(i *AuthFlowInfo) *authFlowInfo {
Restrictions
:
i
.
Restrictions
,
Capabilities
:
i
.
Capabilities
,
Name
:
db
.
NewNullString
(
i
.
Name
),
PollingCode
:
db
.
NewNullString
(
i
.
PollingCode
),
}
}
func
(
e
*
AuthFlowInfo
)
Store
()
error
{
log
.
Printf
(
"Storing auth flow info"
)
store
:=
newAuthFlowInfo
(
e
)
_
,
err
:=
db
.
DB
()
.
NamedExec
(
`INSERT INTO AuthInfo (state, iss, restrictions, capabilities, name, polling_code) VALUES(:state, :issuer, :restrictions, :capabilities, :name, :polling_code)`
,
store
)
return
err
return
db
.
Transact
(
func
(
tx
*
sqlx
.
Tx
)
error
{
if
e
.
PollingCode
!=
""
{
res
,
err
:=
tx
.
Exec
(
`INSERT INTO PollingCodes (polling_code) VALUES(?)`
,
e
.
PollingCode
)
if
err
!=
nil
{
return
err
}
pid
,
err
:=
res
.
LastInsertId
()
if
err
!=
nil
{
return
err
}
upid
:=
uint64
(
pid
)
store
.
PollingCodeID
=
&
upid
}
_
,
err
:=
tx
.
NamedExec
(
`INSERT INTO AuthInfo (state, iss, restrictions, capabilities, name, polling_code_id) VALUES(:state, :issuer, :restrictions, :capabilities, :name, :polling_code_id)`
,
store
)
return
err
})
}
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