Skip to content

Commit

Permalink
Revert "Gateway should skip inactive APIs. Resolves #1151"
Browse files Browse the repository at this point in the history
This reverts commit 7c83993.
  • Loading branch information
asoorm committed Oct 2, 2017
1 parent 7c83993 commit e834045
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 42 deletions.
11 changes: 4 additions & 7 deletions api_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const sampleDefiniton = `{
"proxy": {
"listen_path": "/v1",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

const nonExpiringDef = `{
Expand All @@ -65,8 +64,7 @@ const nonExpiringDef = `{
"proxy": {
"listen_path": "/v1",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

const nonExpiringMultiDef = `{
Expand Down Expand Up @@ -100,8 +98,7 @@ const nonExpiringMultiDef = `{
"proxy": {
"listen_path": "/v1",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

func createDefinitionFromString(defStr string) *APISpec {
Expand Down Expand Up @@ -381,7 +378,7 @@ func TestGetAPISpecsDashboardSuccess(t *testing.T) {
// Mock Dashboard
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/system/apis" {
w.Write([]byte(`{"Status": "OK", "Nonce": "1", "Message": [{"api_definition": {"active": true}}]}`))
w.Write([]byte(`{"Status": "OK", "Nonce": "1", "Message": [{"api_definition": {}}]}`))
} else {
t.Fatal("Unknown dashboard API request", r)
}
Expand Down
15 changes: 2 additions & 13 deletions api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,7 @@ func prepareStorage() (*RedisClusterStorageManager, *RedisClusterStorageManager,
return &redisStore, &redisOrgStore, healthStore, &rpcAuthStore, &rpcOrgStore
}

func skipSpec(spec *APISpec) bool {

// Remove inactive APIs from the specs
if !spec.Active {
log.WithFields(logrus.Fields{
"prefix": "main",
"api_name": spec.Name,
"domain": spec.Domain,
}).Info("Skipping Inactive.")
return true
}
func skipSpecBecauseInvalid(spec *APISpec) bool {

if spec.Proxy.ListenPath == "" {
log.WithFields(logrus.Fields{
Expand Down Expand Up @@ -119,7 +109,7 @@ func processSpec(spec *APISpec, apisByListen map[string]int,
"api_name": spec.Name,
}).Info("Loading API")

if skipSpec(spec) {
if skipSpecBecauseInvalid(spec) {
log.WithFields(logrus.Fields{
"prefix": "main",
"api_name": spec.Name,
Expand Down Expand Up @@ -565,7 +555,6 @@ func loadApps(specs []*APISpec, muxer *mux.Router) {
loadList := make([]*ChainObject, len(specs))
apisByListen := countApisByListenHash(specs)
for i, spec := range specs {

go func(spec *APISpec, i int) {
subrouter := muxer
// Handle custom domains
Expand Down
3 changes: 1 addition & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const apiTestDef = `{
"proxy": {
"listen_path": "/v1",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

func loadSampleAPI(t *testing.T, def string) {
Expand Down
3 changes: 1 addition & 2 deletions apps/app_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
"target_url": "http://httpbin.org",
"strip_listen_path": true
},
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/coprocess_app_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@
],
"driver": "python"
},
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/coprocess_app_sample_protected.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@
},
"driver": "python"
},
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/coprocess_grpc_app_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@
]
}
},
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/coprocess_grpc_app_sample_protected.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@
"session_lifetime": 35
},
"custom_middleware_bundle": "test-bundle",
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/coprocess_lua_app_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@
],
"driver": "lua"
},
"enable_batch_request_support": true,
"active": true
"enable_batch_request_support": true
}
3 changes: 1 addition & 2 deletions apps/quickstart.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
"target_url": "http://httpbin.org/",
"strip_listen_path": true
},
"do_not_track": true,
"active": true
"do_not_track": true
}
6 changes: 2 additions & 4 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,7 @@ const sampleAPI = `{
"proxy": {
"listen_path": "/sample",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

func TestListener(t *testing.T) {
Expand Down Expand Up @@ -983,8 +982,7 @@ const apiWithTykListenPathPrefix = `{
"proxy": {
"listen_path": "/tyk-foo/",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

func TestListenPathTykPrefix(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions oauth_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ const oauthDefinition = `{
"proxy": {
"listen_path": "/APIID/",
"target_url": "` + testHttpAny + `"
},
"active": true
}
}`

func getOAuthChain(spec *APISpec, muxer *mux.Router) {
Expand Down

0 comments on commit e834045

Please sign in to comment.