Code Monkey home page Code Monkey logo

cowj's People

Contributors

hemil-ruparel-blox avatar nmondal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cowj's Issues

Async support to trigger a random something should be default

Imagine the case of writing back to Google Storage.
Now, it is obvious that we can do it via:

thread( my_body = req.body  ) as {
    _storage.g_cloud.dumps("foo", "file.json", my_body)
} 

But should we?
We can essentially have a block like routes and proxies which immediately returns while adding the job:

   post:
      /_async_ /webhook : _/dump_g_cloud.zm  

while then dump_g_cloud.zm is :

// dump_g_cloud.zm 
 _storage.g_cloud.dumps("foo", "file.json", my_body)

of course the thread() can neither create or produce a request-id for the async call that would be queried upon later.

Byte array support for load and dump

Cloud Storage implementation only supports json objects and strings. We might want to upload binary files like images and return them.

I am thinking of two functions:

byte_array = loadb("bucket", "path")
dumpb("bucket", "path", byte_array)

Resource File Support : It is sometime necessary to have resource string support that would depend on the script variables

Specifically, there would be the case where we may use a string which needs to have substitution from variables already being used in the script.

x = 42 
string = Test.resource("my_resource_id")

While the resource file might be something as follows:

resources.yaml

my_resource_id:  "Hello, the variable used is : #{x}"

That would be good.
We can store the resources inside static folders (?)

A Jython JSON demo is required

Given Jython does not have json ability which is off the shelf, one small demo showing json processing in Jython is required.

JDBC Data source timing related load failure

Imagine the JDBC db server is booting up - while the cowj is booting up.
Now, cowj knowingly throws an error at boot - because it fails to connect to the db in the load time in the Cowj running thread.

Given the "architecture" is about getting dedicated Connection per thread based on lazy loading,
this at best should be configurable.

Output filter for proxy does not validate response after finally filter

Say I have an API Get Request to '/' which forwards the request to some other API and then messages the data and returns it. In this case I want the output validation to trigger after the finally filter because I want to handle both error and success case. Right now what is happening is it is triggering before finally.

Example -
api.yaml

port: 5003

proxies:
  get:
    /: json_place/users

filters:
  finally:
    /: _/after.zm

plugins:
  cowj.plugins:
    curl: CurlWrapper::CURL

data-sources:
  json_place:
    type: curl
    url: https://jsonplaceholder.typicode.com

static/types/schema.yaml

labels: # how system knows which label to invoke
  ok:  "resp.status == 200" # when response status is 200
  err:  "resp.status != 200" # when it is not

verify:
  out: true

routes:
  /:
    get:
      ok: output.json

static/types/output.json

{
  "$id": "https://blox.xyz/cowj_api/Generic.error.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Output for send otp service",
  "title": "Error",
  "type": "object",
  "properties": {
    "foo": {
      "type": "string"
    }
  },
  "required": ["foo"],
  "additionalProperties": false
}

after.zm

resp.body("{\"foo\": \"bar\"}")

This setup responds with: {"foo": "bar"} correctly but on the console, there is a log:

SEVERE: Output Schema Validation failed. Route '/' : 
 com.worldturner.medeia.api.ValidationFailedException: [Validation Failure
------------------
Rule:     type
Message:  Type mismatch, data has array and schema has object....

As the schema validation expects {"foo": "bar"} but it is getting the response from proxy directly before the finally filter.

If we change it to after, it works.

Expectation -
For Proxy, Output validation should trigger after all finally filters are executed because we might want to message the data before returning response using after and finally filters. Finally is important because it allows us to handle error case as well

Cloud storage plugin does not provide an option to override project id

Issue Description

The cloud storage plugin uses the gcloud default project id. This will not work if project id is not set or if you have multiple projects and want to work with them at the same time. A lot of people have access to the project but might not have set a default project id. And a lot of people might have multiple projects and might not want to change defaults everytime they change projects. Forgetting to change default project might end up with them getting weird error messages.

Proposed solution

In the yaml file, add an optional field for project-id.

If project-id is not specified, use gcloud default

plugins:
  cowj.plugins:
    g_storage: GoogleStorageWrapper::STORAGE

data-sources:
  storage:
    type: g_storage

With project-id specified

plugins:
  cowj.plugins:
    g_storage: GoogleStorageWrapper::STORAGE

data-sources:
  storage:
    type: g_storage
    project-id: foo_bar

JavaScript - Rhino - print() does not work

Seems to be a problem in Nashorn. Solution is easy, just extending TestAsserter for the same.

Test.print() is System.out.printf()
Test.printe() is System.err.printf()

GET input schema verification is by definition disabled

Should it be?
There is a huge discussion on this topic:
https://stackoverflow.com/questions/978061/http-get-with-request-body

Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.
So, yes, you can send a body with GET, and no, it is never useful to do so.

This is why we need QUERY.
https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-method-w-body-02.html

Unchecked exceptions returned as response instead of generic error message

A route with the following code:

1 / 0

Returns response as:

java.lang.RuntimeException: zoomba.lang.core.types.ZException$ArithmeticLogicOperation: Invalid Arithmetic Logical Operation [/] :  --> /Users/hemil/blox/cowj_apis/api/location.zm:1:5 to 5 --> ( Can not do operation ( DIVISION ) :
 ( 1 ) with ( 0 ) !
 left: java.lang.Integer 
 right: java.lang.Integer )

Instead of a generic internal server error

Allow data sources to get the base directory so the files can use _/ notation

The yaml file allows file paths to be specified using _/ notation. Example -

routes:
  get:
    /hello/g: _/hello.groovy
    /hello/j: _/hello.js
    /hello/p: _/hello.py
    /hello/z: _/hello.zm

_/hello.groovy means hello.groovy in the directory of the configuration file. This allows the file to be relocated as long as the relative paths are preserved. But we are not exposing the base directory to data sources. Many data sources would need files as input which are best specified as relative paths in order to facilitate relocation

For development it would be better to have options to "auto-load"

We can start with Scripts, all scripts. Functionality would be encoded in the Yaml file as follows:

cache : 
     scripts: false
     auth: false 
     type: false 

Default would be set to true.
This way people do not have to reload the server - when they modify things in the scripts and such.
We should start with scripts and type.

A much better alternative would be just adding cache : false in the container yaml files.

Main config file cache would essentially talk about scripts in question.
Schema.yaml would only be applicable for JSON files pointed to by the schema.

Responding with non string in Routes return response - crashes output schema validation

Just do this for the script after input schema validation:

payload = req.attribute("_body") // this should already have the parsed data

Error happens:

java.lang.NullPointerException: Cannot invoke "String.length()" because "content" is null
	at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:1217)
	at cowj.TypeSystem.lambda$outputSchemaVerificationFilter$6(TypeSystem.java:344)
	at spark.FilterImpl$1.handle(FilterImpl.java:73)
	at spark.http.matching.AfterAfterFilters.execute(AfterAfterFilters.java:55)
	at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:187)

proxy implementation is not right

Currently CURLWrapper makes a half hearted effort into being a forward proxy.
The massaging of headers and the request body & query params from client to the destination server.

def send( headers, body, params) {
  // producing payload to destination server 
}

But the reverse transform functionality is missing.

def receive( headers, body, status ) {
  // producing payload to client  
}

The proposal for the transform could be:

proxy:
  send: _/send.zm
  receive: _/rec.zm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.