Skip to content

ol(cli): add invoke subcommand under existing ol tool#369

Open
fairozkhan10 wants to merge 3 commits intoopen-lambda:mainfrom
fairozkhan10:feat/invoke-subcommand
Open

ol(cli): add invoke subcommand under existing ol tool#369
fairozkhan10 wants to merge 3 commits intoopen-lambda:mainfrom
fairozkhan10:feat/invoke-subcommand

Conversation

@fairozkhan10
Copy link

Summary

Adds an ol invoke subcommand (in Go) under the existing ol tool to POST to an OL worker endpoint.

Features

  • Function name via positional arg or --func (mutually exclusive, one required)
  • Payload sources:
    • --data (inline JSON)
    • --json (path to JSON file)
    • --file (binary payload; sets Content-Type to application/octet-stream)
  • Repeated --header "K: V" support
  • --url (otherwise falls back to $OL_URL, default http://127.0.0.1:5000)
  • --path route template (default /invoke/{func})
  • --timeout seconds
  • --pretty pretty-prints JSON responses
  • Non-2xx responses return non-zero exit code

Why under ol

Requested by maintainers: keep invocation in the existing CLI (ol) rather than a separate tool.

Manual test (smoke)

With a small mock worker on host port 5000:

export OL_URL=http://host.docker.internal:5000
./ol-linux help invoke

./ol-linux invoke --func echo --data '{"hello":"ol"}' --pretty
./ol-linux invoke --func echo --json payload.json --pretty
./ol-linux invoke --func echo --file input.bin --header "X-Demo: test"

@fairozkhan10
Copy link
Author

mock worker

python3 - <<'PY'
from http.server import BaseHTTPRequestHandler, HTTPServer
import json, re
class H(BaseHTTPRequestHandler):
def do_POST(self):
import re, json
m = re.match(r"^/invoke/([^/]+)$", self.path)
ln = int(self.headers.get("Content-Length","0"))
body = self.rfile.read(ln).decode() if ln>0 else "{}"
try: payload = json.loads(body or "{}")
except: payload = {"raw": body}
if not m: self.send_response(404); self.end_headers(); return
self.send_response(200); self.send_header("Content-Type","application/json"); self.end_headers()
self.wfile.write(json.dumps({"function": m.group(1), "received": payload}).encode())
HTTPServer(("127.0.0.1", 5000), H).serve_forever()
PY

run from repo/go (Linux container)

export OL_URL=http://host.docker.internal:5000
./ol-linux help invoke
./ol-linux invoke --func echo --data '{"hello":"ol"}' --pretty
./ol-linux invoke --func echo --json payload.json --pretty
./ol-linux invoke --func echo --file input.bin --header "X-Demo: test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant