safari

package module
v0.0.0-...-8bebc79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2016 License: MIT Imports: 14 Imported by: 0

README

Safari Zone

A set of services demonstrating GRPC integration. There are no guarantees on any of this working as this is meant to be a learning exercise. I'd say it's 70% of the way there. The cmd/ folder has the execs for the services and gui/bot.

Services

Services implement an interface that allows for configuration and interceptors to be injected as well as an HTTP gateway to be set up.

Registry

The registry service is in charge of authorization/authentication. It manages accounts and issues tokens (JWT) for other services to use. The tokens are signed asymmetrically with ECDSA private key and the public key is available at an endpoint. Tokens are scoped to roles.

Pokedex

The pokedex service is meant to mimic a content API. A user can only see info on pokemon they have caught, while a service has full access.

Warden

The warden service is the meat of the gameplay and is meant to demonstrate a more complex service. This service issues to tickets w/ expiries for battles. The battles are delivered via bi-directional streams.

Clients

Bot

There is a bot client that manages the flow and user interaction via a state machine. Uses a pretty slick state machine pattern from this talk.

GUI

The gui has an embedded bot and exposes a UI using github.com/gizak/termui

Other Neat things

  • HTTP Gateway via grpc-gateway
  • JWT Authorization Interceptor
  • KVC Util
  • Auto-gen service stubs

Not Implemented

  • TLS auth
  • Logging, Recovery Interceptors
  • Api Proxy
  • Meaningful Tests or Documentation

Notes

  • json openapi docs under service routes
  • different packages for pbf & gw, to not muddy up vars
  • UID is reproduces the same values every run
  • openssl ecparam -out reg.pem -name secp256k1 -genkey (x509 lib can't read curve)
  • gateway should translate grpc codes -> HTTP codes (16 -> 404)
  • @authorize annotations in the proto would be awesome
  • Slim docker containers
  • k8s is not finished
OAK_KEY=$(curl -s "http://localhost:8080/registry/v0/trainer/52fdfc07/auth?scope=PROFESSOR" -H "Authorization: Basic NTJmZGZjMDc6c2FtK2RlbGlhNEVWRVI=" | jq --raw-output '.access')
ASH_KEY=$(curl -s "http://localhost:8080/registry/v0/trainer/037c4d7b/auth" -H "Authorization: Basic MDM3YzRkN2I6VEhFdmVyeWJlc3Q=" | jq --raw-output '.access')
curl "http://localhost:8080/registry/v0/trainer/52fdfc07" -H "Authorization: Bearer ${OAK_KEY}"; echo
curl "http://localhost:8080/registry/v0/trainer/037c4d7b" -H "Authorization: Bearer ${ASH_KEY}"; echo

Deploy

  • go (gvm)
  • protoc
  • docker
  • minikube
  • xhyve

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	bot.Bot
	// contains filtered or unexported fields
}

func NewBot

func NewBot(opts Opts) *Bot

func (*Bot) Connect

func (b *Bot) Connect() bot.State

func (*Bot) Context

func (b *Bot) Context() context.Context

func (*Bot) Encounter

func (b *Bot) Encounter() bot.State

func (*Bot) Exit

func (b *Bot) Exit() bot.State

func (*Bot) FetchTicket

func (b *Bot) FetchTicket() bot.State

func (*Bot) Init

func (b *Bot) Init() bot.State

func (*Bot) Register

func (b *Bot) Register() bot.State

func (*Bot) SignIn

func (b *Bot) SignIn() bot.State

func (*Bot) Ticket

func (b *Bot) Ticket() *pbf.Ticket

func (*Bot) Trainer

func (b *Bot) Trainer() *pbf.Trainer

func (*Bot) WalkAround

func (b *Bot) WalkAround() bot.State

type GUI

type GUI struct {
	// contains filtered or unexported fields
}

func NewGUI

func NewGUI(opts Opts) *GUI

func NewGUI(bot *SafariBot) *GUI {

func (*GUI) Run

func (gui *GUI) Run() error

type InputEvt

type InputEvt struct {
	Msg, Src string
}

type InputPanel

type InputPanel struct {
	*ui.Par
	// contains filtered or unexported fields
}

func InputPar

func InputPar(name string, par *ui.Par) InputPanel

Name is used to identify events to the mux "/input/<name>"

func (InputPanel) Append

func (in InputPanel) Append(val string) string

func (InputPanel) Backspace

func (in InputPanel) Backspace() bool

func (InputPanel) Clear

func (in InputPanel) Clear() string

func (InputPanel) KbdHandler

func (in InputPanel) KbdHandler(e ui.Event)

func (InputPanel) Value

func (in InputPanel) Value() string

type InputSource

type InputSource struct {
	// contains filtered or unexported fields
}

func BotSource

func BotSource(name string, b bot.Bot) InputSource

type ListPanel

type ListPanel struct {
	*ui.List
	Format string
	Prefix string
}

func (ListPanel) Append

func (d ListPanel) Append(lines ...string)

func (ListPanel) Clear

func (d ListPanel) Clear()

func (ListPanel) Loading

func (d ListPanel) Loading(fn func())

func (ListPanel) Trim

func (d ListPanel) Trim()

type Opts

type Opts struct {
	WardenAddress   string
	RegistryAddress string
}

func (Opts) DialRegistry

func (o Opts) DialRegistry() (*registry.Client, error)

func (Opts) DialSafari

func (o Opts) DialSafari() (*warden.Client, error)

Directories

Path Synopsis
cmd
bot
gui
srv
proto
pbf
Package pbf is a generated protocol buffer package.
Package pbf is a generated protocol buffer package.
srv
bot
kvc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL