mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #9660 from gyuho/SA4004
auth: fix SA4004 - unconditionally terminated for-loop
This commit is contained in:
commit
9718dd81d9
@ -1129,7 +1129,7 @@ func (as *authStore) Revision() uint64 {
|
|||||||
return atomic.LoadUint64(&as.revision)
|
return atomic.LoadUint64(&as.revision)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *authStore) AuthInfoFromTLS(ctx context.Context) *AuthInfo {
|
func (as *authStore) AuthInfoFromTLS(ctx context.Context) (ai *AuthInfo) {
|
||||||
peer, ok := peer.FromContext(ctx)
|
peer, ok := peer.FromContext(ctx)
|
||||||
if !ok || peer == nil || peer.AuthInfo == nil {
|
if !ok || peer == nil || peer.AuthInfo == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -1137,18 +1137,26 @@ func (as *authStore) AuthInfoFromTLS(ctx context.Context) *AuthInfo {
|
|||||||
|
|
||||||
tlsInfo := peer.AuthInfo.(credentials.TLSInfo)
|
tlsInfo := peer.AuthInfo.(credentials.TLSInfo)
|
||||||
for _, chains := range tlsInfo.State.VerifiedChains {
|
for _, chains := range tlsInfo.State.VerifiedChains {
|
||||||
for _, chain := range chains {
|
if len(chains) < 1 {
|
||||||
cn := chain.Subject.CommonName
|
continue
|
||||||
if as.lg != nil {
|
|
||||||
as.lg.Debug("found command name", zap.String("common-name", cn))
|
|
||||||
} else {
|
|
||||||
plog.Debugf("found common name %s", cn)
|
|
||||||
}
|
|
||||||
return &AuthInfo{Username: cn, Revision: as.Revision()}
|
|
||||||
}
|
}
|
||||||
|
ai = &AuthInfo{
|
||||||
|
Username: chains[0].Subject.CommonName,
|
||||||
|
Revision: as.Revision(),
|
||||||
|
}
|
||||||
|
if as.lg != nil {
|
||||||
|
as.lg.Debug(
|
||||||
|
"found command name",
|
||||||
|
zap.String("common-name", ai.Username),
|
||||||
|
zap.String("user-name", ai.Username),
|
||||||
|
zap.Uint64("revision", ai.Revision),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
plog.Debugf("found common name %s", ai.Username)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
return ai
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) {
|
func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) {
|
||||||
|
2
test
2
test
@ -473,7 +473,7 @@ function staticcheck_pass {
|
|||||||
if [ -n "${staticcheckResult}" ]; then
|
if [ -n "${staticcheckResult}" ]; then
|
||||||
# TODO: resolve these after go1.8 migration
|
# TODO: resolve these after go1.8 migration
|
||||||
# See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
|
# See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
|
||||||
STATIC_CHECK_MASK="SA(1012|1019|2002|4004)"
|
STATIC_CHECK_MASK="SA(1012|1019|2002)"
|
||||||
if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
|
if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
|
||||||
echo -e "staticcheck checking failed:\\n${staticcheckResult}"
|
echo -e "staticcheck checking failed:\\n${staticcheckResult}"
|
||||||
exit 255
|
exit 255
|
||||||
|
Loading…
x
Reference in New Issue
Block a user