Skip to content

Commit

Permalink
grpc-gateway: improve speed by not looping over all metadata.
Browse files Browse the repository at this point in the history
* Add schwag to facilitate appending security stubs for swagger
  • Loading branch information
hexfusion committed Jun 9, 2017
1 parent 4b62046 commit e6de3a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 16 additions & 16 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,23 +1000,23 @@ func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) {
return nil, nil
}

for k := range md {
if k == "token" || k == "authorization" {
ts, tok := md[k]
if !tok {
return nil, nil
}
token := ts[0]
authInfo, uok := as.authInfoFromToken(ctx, token)
if !uok {
plog.Warningf("invalid auth token: %s", token)
return nil, ErrInvalidAuthToken
}
plog.Debugf("checking value in loop %s", k)
return authInfo, nil
}
//TODO(mitake|hexfusion) review unifying key names
ts, ok := md["token"]
if !ok {
ts, ok = md["authorization"]
}
if !ok {
return nil, nil
}
return nil, nil

token := ts[0]
authInfo, uok := as.authInfoFromToken(ctx, token)
if !uok {
plog.Warningf("invalid auth token: %s", token)
return nil, ErrInvalidAuthToken
}

return authInfo, nil
}

func (as *authStore) GenTokenPrefix() (string, error) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ for pb in etcdserverpb/rpc api/v3lock/v3lockpb/v3lock api/v3election/v3electionp
done
rm -rf Documentation/dev-guide/apispec/swagger/etcdserver/

# append security to swagger spec
go get -u "github.com/hexfusion/schwag"
schwag -input=Documentation/dev-guide/apispec/swagger/rpc.swagger.json

# install protodoc
# go get -v -u github.com/coreos/protodoc
#
Expand Down

0 comments on commit e6de3a2

Please sign in to comment.