Skip to content

Commit

Permalink
Adjust grpccurl and python client examples to recent protobuf changes
Browse files Browse the repository at this point in the history
Both the grpcurl and the python client were not working anymore after the changes made in #1447, #1445 and #1511
This PR adjusts these scripts under ./hack/federation to work again.
  • Loading branch information
jschaul committed Jun 28, 2021
1 parent cf87ee4 commit 5ab023e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* schema-profunctor: add `optField` combinator and corresponding documentation (#1621, #1624).
* [Federation] Let a receiving backend decide conversation attribute specifics of its users
added to a new conversation via `POST /federation/register-conversation` (#1622)
* [Federation] Adjust scripts under ./hack/federation to work with recent changes to the federation API (#1632)

## Documentation

Expand Down
31 changes: 18 additions & 13 deletions hack/federation/grpcurlhandle.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/usr/bin/env bash

# Usage:
#
# First, run services (including nginz) locally:
#
# export INTEGRATION_USE_NGINZ=1; ./services/start-services-only.sh
#
# Then, run this command for user search (ideally on a handle that exists)
#
#
#
handle="pyaewrqxggbtbvzdsubkl" # change this to a valid handle in your local database

command -v grpcurl >/dev/null 2>&1 || {
echo >&2 "grpcurl is not installed, aborting. Maybe try ' nix-env -iA nixpkgs.grpcurl '?"
exit 1
}

path=$(echo -n users/by-handle | base64)
body=$(echo -n "alice" | base64)
path=$(echo -n federation/get-user-by-handle | base64)
body=$(echo -n "\"$handle\"" | base64)

TOP_LEVEL="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

Expand All @@ -20,22 +32,15 @@ function getHandle() {
fi
set -x
grpcurl -d @ -format json $AUTHORITY $MODE -import-path "${TOP_LEVEL}/libs/wire-api-federation/proto/" -proto router.proto "$HOST:$PORT" wire.federator.Inward/call <<EOM
{"component": "Brig", "path": "$path", "body": "$body", "originDomain": "localhost"}
{"component": "Brig", "path": "$path", "body": "$body", "originDomain": "grpcurl.example.com"}
EOM
{ set +x; } 2>/dev/null # stop outputting commands and don't print the set +x line
echo "===|"
echo
}

HOST=localhost
HOST="localhost"
SERVERNAME="federator.integration.example.com"
PORT=8443
MODE="-cacert ${TOP_LEVEL}/services/nginz/integration-test/conf/nginz/integration-ca.pem"
SERVERNAME="federator.integration.example.com"
getHandle "local nginz on port 8443 using self-signed cert"

# HOST=
# PORT=443 # tls port of currently-deployed ingress in 'grpc' namespace
# MODE="-insecure"
# SERVERNAME="federator.integration.example.com"
# # making an insecure/ignore-certificates connection over TLS works:
# getHandle "description"
getHandle "local"
27 changes: 18 additions & 9 deletions hack/federation/python-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ poetry run python -m grpc_tools.protoc -I../../../libs/wire-api-federation/proto
Run services locally:

```
export INTEGRATION_USE_NGINZ=1
../../../services/start-services-only.sh
```

Expand All @@ -21,14 +22,22 @@ expected output should be:

```
starting client...
request: path: "users/by-handle"
query {
key: "handle"
value: "alice"
}
response: httpResponse {
responseStatus: 404
responseBody: "Handle not found."
request: path: "federation/get-user-by-handle"
body: "\"pyaewrqxggbtbvzdsubkl\""
originDomain: "python.example.com"
json reponse:
{
"handle": "pyaewrqxggbtbvzdsubkl",
"qualified_id": {
"domain": "example.com",
"id": "0f3880e6-5fb5-4c3d-963d-8ea36e15717c"
},
"accent_id": 0,
"picture": [],
"legalhold_status": "no_consent",
"name": "\u7985\u9a71\ud4d1\u7485",
"id": "0f3880e6-5fb5-4c3d-963d-8ea36e15717c",
"assets": []
}
```
17 changes: 10 additions & 7 deletions hack/federation/python-client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import grpc
import json

from router_pb2 import *
import router_pb2_grpc
Expand All @@ -10,17 +11,19 @@
stub = router_pb2_grpc.InwardStub(channel)

def handle_search(handle):
param = QueryParam(key="handle".encode("utf-8"), value=handle.encode("utf-8"))
return Request(
path="users/by-handle".encode("utf-8"),
query=[param],
method=GET,
path="federation/get-user-by-handle".encode("utf-8"),
body=('"' + handle + '"').encode("utf-8"),
originDomain="python.example.com",
component=Brig)

req = handle_search("alice")
req = handle_search("pyaewrqxggbtbvzdsubkl")

print("request: ", req)

response = stub.call(req)

print("response: ", response)
try:
jsonresponse = json.dumps(json.loads(response.body.decode('utf-8')), indent=2)
print("json reponse:\n", jsonresponse)
except:
print("non-json response:\n", response)

0 comments on commit 5ab023e

Please sign in to comment.