Skip to content

arnodel/grpc-juju-client

Repository files navigation

POC gRPC API for juju

The idea of this is to showcase gRPC by creating a proxy gRPC server for the juju client. Documentation and client APIs for Go and Python are generated from the protobuf specification.

Requirements

Tested on Linux / MacOS with python3 / pip3.

The protobuf spec

A service spec is defined in application.proto. The contents of gen/proto is generated from this. It contains

  • a go/ directory with
    • Generated code for Go client / server (generated with protoc-gen-go and protoc-gen-go-grpc);
    • Generated code for an HTTP gateway to a gRPC server (generated with protoc-gen-grpc-gateway);
  • a python/ directory with generated code for Python client (generated with grpcio-tools);
  • a doc/ directory with generated HTML documentation (with protoc-gen-doc).
  • an openapi/ directory with generated swagger specs

Generating the python / Go code and HTML docs

The buf is used to generate output from the protobuf specs as it streamlines the process a bit.

Some protoc dependencies need to be installed before generation can be run.

make install-deps

Then to re-generate the code / docs:

make generate

The gRPC server

This is implemented in cmd/grpc-juju. Run it and it starts

  • a gRPC server on port 8080 and
  • a gRPC gateway (HTTP server) on port 8090.

It can be installed directly without downloading the repo:

go install github.com/arnodel/grpc-juju-client/cmd/grpc-juju

It requires a juju client to be installed somewhere on the same machine. By default it assumes juju is in the path. You can pass in a custom path:

grpc-juju -juju-client ~/bin/juju

See apis/ for supported apis. Also the gRPC server supports reflection, so it is discoverable (use e.g. https://github.com/fullstorydev/grpcui to play with it)

Example clients

The clients/ directory contains two sample programming acting as clients to the gRPC server. In order to use them grpc-juju should be running on the same machine.

  • clients/go-client contains a Go client that can deploy or remove a deployment of postgresql and print the outcome.
  • clients/python-client contains a Python client with the same functionality. It should be run via the client.sh script to get the import paths correct.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published