Skip to content

Commit

Permalink
Merge 68d19fb into 379328b
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Jun 2, 2019
2 parents 379328b + 68d19fb commit 160509d
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ petstore.json
*.pdf
*.mmdb
*.cov
*.so
!testdata/*.mmdb
*.pid
coprocess_gen_test.go
Expand Down
10 changes: 6 additions & 4 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ const (
RequestXML RequestInputType = "xml"
RequestJSON RequestInputType = "json"

OttoDriver MiddlewareDriver = "otto"
PythonDriver MiddlewareDriver = "python"
LuaDriver MiddlewareDriver = "lua"
GrpcDriver MiddlewareDriver = "grpc"
OttoDriver MiddlewareDriver = "otto"
PythonDriver MiddlewareDriver = "python"
LuaDriver MiddlewareDriver = "lua"
GrpcDriver MiddlewareDriver = "grpc"
GoPluginDriver MiddlewareDriver = "goplugin"

BodySource IdExtractorSource = "body"
HeaderSource IdExtractorSource = "header"
Expand Down Expand Up @@ -362,6 +363,7 @@ type APIDefinition struct {
PinnedPublicKeys map[string]string `bson:"pinned_public_keys" json:"pinned_public_keys"`
EnableJWT bool `bson:"enable_jwt" json:"enable_jwt"`
UseStandardAuth bool `bson:"use_standard_auth" json:"use_standard_auth"`
UseGoPluginAuth bool `bson:"use_go_plugin_auth" json:"use_go_plugin_auth"`
EnableCoProcessAuth bool `bson:"enable_coprocess_auth" json:"enable_coprocess_auth"`
JWTSigningMethod string `bson:"jwt_signing_method" json:"jwt_signing_method"`
JWTSource string `bson:"jwt_source" json:"jwt_source"`
Expand Down
5 changes: 4 additions & 1 deletion apidef/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const Schema = `{
"openid_options": {
"type": ["object", "null"]
},
"use_standard_auth":{
"use_standard_auth": {
"type": "boolean"
},
"use_go_plugin_auth": {
"type": "boolean"
},
"enable_coprocess_auth": {
"type": "boolean"
},
Expand Down
13 changes: 11 additions & 2 deletions bin/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


MATRIX=(
"-tags 'coprocess python'"
"-tags 'coprocess grpc'"
"-tags 'coprocess python goplugin'"
"-tags 'coprocess grpc goplugin'"
)
TEST_TIMEOUT=2m

Expand Down Expand Up @@ -40,6 +40,9 @@ i=0

go get -t

# build Go-plugin used in tests
go build -o ./test/goplugins/goplugins.so -buildmode=plugin ./test/goplugins || fatal "building Go-plugin failed"

# need to do per-pkg because go test doesn't support a single coverage
# profile for multiple pkgs
for pkg in $PKGS; do
Expand All @@ -55,7 +58,13 @@ if [[ ! $LATEST_GO ]]; then
exit 0
fi

# build Go-plugin used in tests but with race support
mv ./test/goplugins/goplugins.so ./test/goplugins/goplugins_old.so
go build -race -o ./test/goplugins/goplugins.so -buildmode=plugin ./test/goplugins \
|| fatal "building Go-plugin with race failed"

go test -race -v -timeout $TEST_TIMEOUT $PKGS || fatal "go test -race failed"
mv ./test/goplugins/goplugins_old.so ./test/goplugins/goplugins.so

for opts in "${MATRIX[@]}"; do
show go vet $opts $PKGS || fatal "go vet errored"
Expand Down
79 changes: 79 additions & 0 deletions ctx/ctx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ctx

import (
"context"
"net/http"

"github.com/TykTechnologies/tyk/storage"
"github.com/TykTechnologies/tyk/user"
)

const (
SessionData = iota
UpdateSession
AuthToken
HashedAuthToken
VersionData
VersionDefault
OrgSessionContext
ContextData
RetainHost
TrackThisEndpoint
DoNotTrackThisEndpoint
UrlRewritePath
RequestMethod
OrigRequestURL
LoopLevel
LoopLevelLimit
ThrottleLevel
ThrottleLevelLimit
Trace
CheckLoopLimits
)

func setContext(r *http.Request, ctx context.Context) {
r2 := r.WithContext(ctx)
*r = *r2
}

func ctxSetSession(r *http.Request, s *user.SessionState, token string, scheduleUpdate bool) {
if s == nil {
panic("setting a nil context SessionData")
}

if token == "" {
token = GetAuthToken(r)
}

if s.KeyHashEmpty() {
s.SetKeyHash(storage.HashKey(token))
}

ctx := r.Context()
ctx = context.WithValue(ctx, SessionData, s)
ctx = context.WithValue(ctx, AuthToken, token)

if scheduleUpdate {
ctx = context.WithValue(ctx, UpdateSession, true)
}

setContext(r, ctx)
}

func GetAuthToken(r *http.Request) string {
if v := r.Context().Value(AuthToken); v != nil {
return v.(string)
}
return ""
}

func GetSession(r *http.Request) *user.SessionState {
if v := r.Context().Value(SessionData); v != nil {
return v.(*user.SessionState)
}
return nil
}

func SetSession(r *http.Request, s *user.SessionState, token string, scheduleUpdate bool) {
ctxSetSession(r, s, token, scheduleUpdate)
}
Loading

0 comments on commit 160509d

Please sign in to comment.