TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.65k stars 1.08k forks source link

Creating APIs using file based method under /apps does not work #2868

Closed amanjeev closed 4 years ago

amanjeev commented 4 years ago

Branch/Environment/Version

Describe the bug

Creation of APIs using the file system, by putting files in /apps directory. This is based on the documentation:

Reproduction steps Steps to reproduce the behavior:

  1. Create an API JSON file
    Toggle to see API JSON

{
  "name": "Test API",
  "slug": "test-api",
  "api_id": "1",
  "org_id": "1",
  "auth": {
    "auth_header_name": "Authorization"
  },
  "definition": {
    "location": "header",
    "key": "x-api-version"
  },
  "version_data": {
    "not_versioned": true,
    "versions": {
      "Default": {
        "name": "Default",
        "use_extended_paths": true
    }
   }
  },
  "proxy": {
    "listen_path": "/test-api/",
    "target_url": "http://httpbin.org/",
    "strip_listen_path": true
  },
  "active": true
}

  1. Deploy the file under /opt/tyk-gateway/apps/ and check the file is there with the correct content.
  2. Reload
    curl -s "http://192.168.33.22:8080/tyk/reload/group" -H "Content-Type: application/json" -H "x-tyk-authorization: secret"
    {"status":"ok","message":""}
  3. List APIs
    curl -s "http://192.168.33.22:8080/tyk/apis/" -H "Content-Type: application/json" -H "x-tyk-authorization: secret" | jq '.[].name'
  4. No API with name Test API listed in the output.

Actual behavior

The API is not listed, and does not exist in Tyk Gateway.

Expected behavior

We expect to see the API in the list of APIs returned via the /tyk/apis endpoint.

Additional context

However, when we use the Tyk's /tyk/apis endpoint to create the same APIs, they are created fine.

Tyk Config

Toggle to see API JSON

``` { "enable_hashed_keys_listing": true, "allow_insecure_configs": true, "allow_master_keys": false, "allow_remote_config": true, "control_api_hostname": "", "disable_dashboard_zeroconf": false, "disable_virtual_path_blobs": false, "enable_analytics": false, "enable_api_segregation": false, "enable_bundle_downloader": true, "enable_coprocess": false, "enable_custom_domains": true, "enable_jsvm": true, "enable_non_transactional_rate_limiter": true, "enable_sentinel_rate_limiter": false, "enable_separate_cache_store": false, "enforce_org_data_age": true, "enforce_org_data_detail_logging": false, "enforce_org_quotas": true, "event_trigers_defunct": {}, "experimental_process_org_off_thread": false, "hash_keys": true, "health_check": { "enable_health_checks": false, "health_check_value_timeouts": 60 }, "hide_generator_header": false, "hostname": "", "http_server_options": { "certificates": [], "enable_websockets": true, "flush_interval": 0, "min_version": 0, "override_defaults": false, "read_timeout": 0, "server_name": "MYSERVERIP", "use_ssl": false, "use_ssl_le": false, "write_timeout": 0 }, "listen_port": 8080, "local_session_cache": { "cached_session_eviction": 0, "cached_session_timeout": 0, "disable_cached_session_state": true }, "max_idle_connections_per_host": 500, "middleware_path": "./middleware", "node_secret": "secret", "oauth_redirect_uri_separator": ";", "oauth_refresh_token_expire": 0, "oauth_token_expire": 0, "optimisations_use_async_session_write": true, "pid_file_location": "./tyk-gateway.pid", "public_key_path": "", "secret": "secret", "sentry_code": "", "service_discovery": { "default_cache_timeout": 0 }, "slave_options": { "api_key": "", "bind_to_slugs": false, "connection_string": "", "disable_keyspace_sync": false, "enable_rpc_cache": false, "group_id": "", "rpc_key": "", "use_rpc": false }, "storage": { "database": 0, "enable_cluster": false, "host": "tyk-redis", "hosts": null, "optimisation_max_active": 5000, "optimisation_max_idle": 3000, "password": "", "port": 6379, "type": "redis", "username": "" }, "suppress_default_org_store": false, "suppress_redis_signal_reload": false, "syslog_network_addr": "", "syslog_transport": "", "template_path": "./templates", "uptime_tests": { "config": { "checker_pool_size": 50, "enable_uptime_analytics": false, "failure_trigger_sample_size": 1, "time_wait": 2 }, "disable": true }, "use_graylog": false, "use_logstash": false, "use_redis_log": true, "use_sentry": false, "use_syslog": false } ```

buger commented 4 years ago

Hi!

You do not have "app_path" which points to API directory. And default Tyk config (if you have followed installation steps) contains it https://github.com/TykTechnologies/tyk/blob/master/install/data/tyk.self_contained.conf

After adding it, it should start working.

Cheers!

amanjeev commented 4 years ago

@buger Thanks! Do I need to add a similar path for policies?

buger commented 4 years ago

Yep, like this:

  "policies": {
    "policy_source": "file",
    "policy_record_name": "policies/policies.json"
  },
amanjeev commented 4 years ago

@buger Your docs say

If Tyk is being used in its standard configuration (CE Mode), then API definitions are stored in the apps folder (by default in /opt/tyk-gateway/apps). This file is scanned for files that ending in .json extension and interpreted at startup or reload. See the API Management section of the Tyk Gateway REST API for more details.

That to me looked as if, if not supplied the detfault is /opt/tyk-gateway/apps which is where I have my JSON files.

buger commented 4 years ago

Yeah, it more meant "default" config