Like grpcurl and cobra had a baby

Related tags

Network grpctl
Overview

EXPERIMENTAL: this repo is in its infancy stage atm so there are a lot of features aren't supported

grpctl

/'grp-cuttle'/

A dynamic cli for interacting with grpc apis. Sort of like a mash of grpcurl and kubectl. This project was inspired by protoc-gen-cobra but sometimes adding another protoc plugin is annoying.

How does it work?

Instead of manually writing or code generating cobra commands grpctl uses the protoreflect.FileDescriptor to interact with services, methods and types.

The mapping is something like this:

  • protoreflect.ServiceDescriptor -> top level command (eg fooctl FooAPI)
  • protoreflect.MethodDescriptor -> second level command (eg fooctl FooAPI ListBar)
  • protoreflect.MessageDescriptor -> flags (eg fooctl FooAPI ListBar --field1="string")

This also means that autocomplete example payloads can be generated.

Reflection mode

grpctl

This mode is for using grpctl with reflection apis.

Install

go get github.com/joshcarp/grpctl/cmd/grpctl

Run

> grpctl add --addr localhost:8080 --plaintext
> grpctl list 
FooAPI Hello
BarAPI ListBars
ServerReflection ServerReflectionInfo

> grpctl --help
A brief description of your application

Usage:
  grpctl [command]

Available Commands:
  BarAPI           BarAPI as defined in api.proto
  FooAPI           FooAPI as defined in api.proto
  ServerReflection ServerReflection as defined in reflection/grpc_reflection_v1alpha/reflection.proto
  add              Add a services to grpctl
  completion       generate the autocompletion script for the specified shell
  config           configure options in grpctl
  help             Help about any command
  list             list service

Flags:
      --config string   config file (default is $HOME/.grpctl.yaml)
  -h, --help            help for grpctl
  -t, --toggle          Help message for toggle

Use "grpctl [command] --help" for more information about a command.

File descriptor mode

examplectl

This mode is for creating an api specific cli tool (like kubectl).

Install

package main

import (
	"github.com/joshcarp/grpcexample/proto/examplepb"
	"github.com/joshcarp/grpctl"
	"github.com/spf13/cobra"
)

func main() {
	cmd := &cobra.Command{
		Use:   "examplectl",
		Short: "a cli tool for example",
	}
	grpctl.Execute(cmd, examplepb.File_api_proto)
}

this will use the service and method descriptors in altethical.File_api_proto to dynamically create cobra commands:

> examplectl --help
a cli tool for examplectl

Usage:
  examplectl [command]

Available Commands:
  BarAPI      BarAPI as defined in api.proto
  FooAPI      FooAPI as defined in api.proto
  completion  generate the autocompletion script for the specified shell
  config      configure options in grpctl
  help        Help about any command

Flags:
      --config string   config file (default is $HOME/.grpctl.yaml)
  -h, --help            help for examplectl
  -t, --toggle          Help message for toggle

Use "examplectl [command] --help" for more information about a command.

> examplectl BarAPI --help
BarAPI as defined in api.proto

Usage:
  examplectl BarAPI [command]

Available Commands:
  ListBars    ListBars as defined in api.proto

Flags:
  -h, --help   help for BarAPI

Global Flags:
      --config string   config file (default is $HOME/.grpctl.yaml)

Use "examplectl BarAPI [command] --help" for more information about a command.

> examplectl BarAPI ListBars --addr localhost:8081 --message foobar --plaintext
message:"foobar"
{
 "message": "Barserver foobar"
}

Features

  • Dynamic generation cobra commands for grpc Services and Methods.
  • Generation of flags for top level input types.
  • Generation of auto completion for types.
  • Proto file descriptor support.
  • gRPC reflection support.
Comments
  • Add streaming support

    Add streaming support

    Adds support for all streamings. This will be able to take a simple json array of objects to pipe into Send and Receive will print out the response all at once.

    In the future it would be good to have a better ux by having a more interactive terminal like the rest of grpctl

    opened by joshcarp 0
  • Add protocol flag, remove plaintext flag

    Add protocol flag, remove plaintext flag

    Removes plaintext flag, mainly because being able to specify a full address without any more flags is nice Adds a protocol flag that allows specification of grpc, connect, and grpcweb

    opened by joshcarp 0
  • Fix completions

    Fix completions

    Fixes https://github.com/joshcarp/grpctl/issues/20

    Completions got broken in a refactor and there weren't any test cases to check this.

    This PR adds WithCompletions that enables completions on a command.

    opened by joshcarp 0
  • CLI

    CLI

    • [ ] service

      • [x] get
      • [x] add
      • [x] remove
      • [x] update
      • [x] list
    • [ ] service.environment

      • [ ] get
      • [ ] add
      • [ ] remove
      • [ ] update
      • [ ] list
    • [ ] user

      • [x] get
      • [x] add
      • [x] remove
      • [x] update
      • [x] list
    • [ ] context

      • [x] get
      • [x] add
      • [x] remove
      • [x] update
      • [x] list
    opened by joshcarp 0
  • Add config commands

    Add config commands

    Add the following commands

    grpctl config add user

    grpctl config add user --name jimmy --headers authorisation=eyfoobar
    

    This should add the user jimmy to ~/.grpctl.yaml

    users:
       - name: jimmy
         headers:
             - key: authorisation
               value: eyfoobar
    

    grpctl config add context

    grpctl config add context --name default --user jimmy
    

    This should add a context to ~/.grpctl.yaml

    contexts:
       - name: default
         user: jimmy
    

    grpctl config remove context/user

    This should remove the user/context from the config

    grpctl config clear all

    This should clear all context, users, and services

    grpctl config clear service

    This should clear all services

    grpctl config clear users

    This should clear all users

    grpctl config clear contexts

    This should clear all contexts

    opened by joshcarp 0
  • Support repeates fields in input

    Support repeates fields in input

    This seems to error at the moment

    message Foo {
        repeated string field = 1;
    }
    

    grpctl .... --field="blah"

    Currently this gives a nasty json marshalling error To fix this either:

    • --field="blah" would simply append "blah" to a string array, the same as specifying -H in the root level commands
    • an error is returned telling user to supply a json array: ["blah"]

    Personally I would prefer the first one, but it would mean that the json creation would need to have context of what type every field is, which is not currently the case

    opened by joshcarp 0
  • aliases for well-known command patterns

    aliases for well-known command patterns

    Just putting a thought here

    Common commands can be automatically given an alias if they fit in one of the common RPC formats. EG:

    ListFoobar -> list CreateBaz -> create

    Works even better if you can alias the service as well but thats probably harder

    grpctl FoobarService ListFoobar
    

    becomes

    grpctl foobar list
    
    opened by anzboi 0
  • RPC command `--help` could give a list of fields and types

    RPC command `--help` could give a list of fields and types

    For discovery and help purposes, it would help to give more information through the --help command on Services and their RPCs

    Services and RPCs can return their docstring as found in the proto files, while RPCs could additionally return a list of request fields and their types.

    Examples

    Service

    $ grpctl {Service} --help
    path.to.Service (path/to/file.proto)
    
    Docstring
    
    Available Commands:
    ...
    
    Flags:
    ...
    
    Global Flags:
    ...
    

    Method

    $ grpctl {Service} {RPC} --help
    path.to.Service/RPC (path/to/file.proto)
    
    Docstring
    
    Request:
    [num] field_name - Type
    
    Flags:
    ...
    
    Global Flags:
    ...
    
    opened by anzboi 0
  • Integration with protoc-gen-validate

    Integration with protoc-gen-validate

    Flags should be validated client side with detailed feedback of issues arising if protoc-gen-validate options are found on the proto files.

    Links: https://github.com/envoyproxy/protoc-gen-validate

    opened by joshcarp 0
Owner
Joshua Carpeggiani
👨‍💻 Software Engineer at ANZ 📚 Computer science at Unimelb
Joshua Carpeggiani
Coral, a friendly Cobra fork with nearly all its features, but only 4 dependencies

Coral Preamble I love Cobra and I love Viper. They are great projects, incredibly useful and outstandingly important for the Go community. But sometim

Christian Muehlhaeuser 427 Nov 26, 2022
Guilherme Biff Zarelli 3 Jun 6, 2022
Moviefetch: a simple program to search and download for movies from websites like 1337x and then stream them

MovieFetch Disclaimer I am NOT responisble for any legal issues or other you enc

Hashm 2 May 12, 2022
A shazam like tool to store songs fingerprints and retrieve them

musig ?? A shazam-like tool that allows you to compute song's fingerprints and reverse lookup song names. It's more or less an implementation of the s

Sami Tabet 415 Nov 20, 2022
kcp is a prototype of a Kubernetes API server that is not a Kubernetes cluster - a place to create, update, and maintain Kube-like APis with controllers above or without clusters.

kcp is a minimal Kubernetes API server How minimal exactly? kcp doesn't know about Pods or Nodes, let alone Deployments, Services, LoadBalancers, etc.

Prototype of Future Kubernetes Ideas 1.8k Nov 26, 2022
Verify IP addresses of respectful crawlers like Googlebot by reverse dns and forward dns lookups

goodbots - trust but verify goodbots verifies the IP addresses of respectful crawlers like Googlebot by performing reverse dns and forward dns lookups

Eric Wu 30 Aug 16, 2022
This project provides fully automated one-click experience to create Cloud and Kubernetes environment to run Data Analytics workload like Apache Spark.

Introduction This project provides a fully automated one-click tool to create Data Analytics platform in Cloud and Kubernetes environment: Single scri

DataPunch - One Click to Create Cloud and Kubernetes Environment for Data Analytics and Apache Spark 44 Nov 16, 2022
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.

grpc-tools A suite of tools for gRPC debugging and development. Like Fiddler/Charles but for gRPC! The main tool is grpc-dump which transparently inte

Bradley Kemp 1.1k Nov 25, 2022
It's like curl -v, with colours.

httpstat Imitation is the sincerest form of flattery. But seriously, https://github.com/reorx/httpstat is the new hotness, and this is a shameless rip

Dave Cheney 6.2k Nov 23, 2022
httpie-like HTTP client written in Go

httpie-go httpie-go (ht) is a user-friendly HTTP client CLI. Requests can be issued with fewer types compared to curl. Responses are displayed with sy

Yusuke Nojima 261 Nov 18, 2022
Automatically compress podcasts to tiny file sizes for bandwidth constrained devices like cellular.

tinycast Automatically compress podcasts to tiny file sizes for bandwidth constrained connections like cellular or satellite.

Stephen Holiday 4 Sep 18, 2022
Scalable WebRTC Signaling Server with ayame-like protocol.

ayu ayu is WebRTC Signaling Server with ayame-like protocol. Scalable: ayu uses Redis to store room states, so it can be used on serverless platforms

castaneai 28 Nov 11, 2022
Fork of Go stdlib's net/http that works with alternative TLS libraries like refraction-networking/utls.

github.com/ooni/oohttp This repository contains a fork of Go's standard library net/http package including patches to allow using this HTTP code with

Open Observatory of Network Interference (OONI) 30 Sep 29, 2022
Events - Event Manager - Nodejs like

events Event Manager - Nodejs like Please take a look at the TESTS, for further comprehension. Example package main import ( "errors" "fmt" "log"

Digital Circle 0 Dec 31, 2021
Golang http&grpc server for gracefully shutdown like nginx -s reload

supervisor Golang http & grpc server for gracefully shutdown like nginx -s reload if you want a server which would be restarted without stopping servi

Terry Fei 0 Jan 8, 2022
JSON assets that are almost static like house_id mappings for the API.

TibiaData API assets JSON assets that are almost static like house_id mappings for the API. This repo contains tooling that generates the assets json

TibiaData 2 Jun 1, 2022
A go module supply Java-Like generic stream programming (while do type check at runtime)

gostream A go module supplying Java-Like generic stream programming (while do type check at runtime) Using Get a Stream To get a Stream, using SliceSt

Sad_Dog 0 Jan 16, 2022
This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

echGo 5 Oct 5, 2022