Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goatherd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
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
CIP-Admins
goatherd
Commits
4120c10c
Commit
4120c10c
authored
2 years ago
by
Michael Eischer
Browse files
Options
Downloads
Patches
Plain Diff
get rid of goto for db transaction
parent
058fdc76
No related branches found
No related tags found
1 merge request
!3
Accumulated extensions to goatherd from I4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
goatherd.go
+35
-34
35 additions, 34 deletions
goatherd.go
with
35 additions
and
34 deletions
goatherd.go
+
35
−
34
View file @
4120c10c
...
...
@@ -318,7 +318,7 @@ func checkHOTP(hotp *twofactor.HOTP, remote string, name string, offer string) (
debugf
(
"[%v] autoresync in progress: %v"
,
remote
,
s
)
if
uint64
(
time
.
Now
()
.
Unix
()
-
s
.
Time
)
<=
cfg
.
AutoresyncTime
{
if
s
.
Num
>=
cfg
.
AutoresyncRepeat
&&
s
.
Counter
-
hotp
.
Counter
()
<
cfg
.
AutoresyncLookahead
{
// if the user had a sufficient number of
successful
tries that were not within
// if the user had a sufficient number of
consecutive
tries that were not within
// standard lookahead range but within cfg.AutoresyncLookahead within cfg.AutoresyncTime seconds,
// temporarily increase lookahead to authenticate and resync.
debugf
(
"[%v] autoresync conditions: increasing lookahead to "
,
cfg
.
AutoresyncLookahead
)
...
...
@@ -374,49 +374,50 @@ func checkHOTP(hotp *twofactor.HOTP, remote string, name string, offer string) (
// transaction, retrying if it fails.
func
checkOffer
(
remote
string
,
name
string
,
offer
string
)
(
bool
,
error
)
{
for
{
debugf
(
"[%v] begin transaction"
,
remote
)
tx
,
err
:=
db
.
Begin
()
errPanic
(
err
)
inner
:=
func
(
tx
*
sql
.
Tx
)
(
bool
,
error
)
{
debugf
(
"[%v] looking up data for %v"
,
remote
,
name
)
hotp
,
err
:=
getOTP
(
tx
,
name
)
if
err
!=
nil
{
return
false
,
err
}
ok
:=
false
ok
,
err
:=
checkHOTP
(
hotp
,
remote
,
name
,
offer
)
if
err
!=
nil
{
return
false
,
err
}
debugf
(
"[%v] looking up data for %v"
,
remote
,
name
)
hotp
,
err
:=
getOTP
(
tx
,
name
)
if
transactionFailed
(
err
)
{
goto
retry
}
else
if
err
==
sql
.
ErrNoRows
{
_
=
tx
.
Rollback
()
return
false
,
err
}
errPanic
(
err
)
if
ok
{
debugf
(
"[%v] ok, set new count"
,
remote
)
err
:=
setCount
(
tx
,
name
,
hotp
.
Counter
())
if
err
!=
nil
{
return
false
,
err
}
}
ok
,
err
=
checkHOTP
(
hotp
,
remote
,
name
,
offer
)
if
transactionFailed
(
err
)
{
goto
retry
debugf
(
"[%v] commiting"
,
remote
)
err
=
tx
.
Commit
()
if
err
!=
nil
{
return
false
,
err
}
return
ok
,
nil
}
debugf
(
"[%v] begin transaction"
,
remote
)
tx
,
err
:=
db
.
Begin
()
errPanic
(
err
)
if
ok
{
debugf
(
"[%v] ok, set new count"
,
remote
)
err
:=
setCount
(
tx
,
name
,
hotp
.
Counter
())
if
transactionFailed
(
err
)
{
goto
retry
ok
,
err
:=
inner
(
tx
)
if
err
!=
nil
{
debugf
(
"[%v] retry %v"
,
remote
,
err
)
_
=
tx
.
Rollback
()
if
err
==
sql
.
ErrNoRows
{
return
false
,
nil
}
else
if
transactionFailed
(
err
)
{
continue
}
errPanic
(
err
)
}
debugf
(
"[%v] commiting"
,
remote
)
err
=
tx
.
Commit
()
if
transactionFailed
(
err
)
{
goto
retry
}
errPanic
(
err
)
return
ok
,
nil
retry
:
debugf
(
"[%v] retry"
,
remote
)
_
=
tx
.
Rollback
()
}
}
...
...
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