grpc

package module
v0.0.0-...-9fd10f7 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 18 Imported by: 0

README

GRPC Module

This module can be used to run a grpc server in your flamingo application. It uses the google grpc implementation and makes it easy to use within a flamingo application.

Before you start using this module - it makes sense to be familiar with the official grpc go tutorials

The module provides:

  • Starting of a grpc server with the registered grpc services
  • A concept to bind grpc services (in our own modules)
  • Providing authentication features, that can be used to secure grpc services. For example by using OAuth tokens in a bearer request header.

How to use it

  1. Generate: Define your grpc service in your .proto file. And generate the go client and server.
  2. Service Implementation: Implementing the service interface generated from our service definition: doing the actual “work” of our service.
  3. Binding: Inside your module you need to register the service implementation. This is done like this:
func (m *SampleModule) Configure(injector *dingo.Injector) {
	injector.BindMulti(new(grpc.ServerRegister)).ToProvider(serverRegisterProvider)
}

func serverRegisterProvider(s *ServiceImplementation) grpc.ServerRegister {
	return func(server grpc.ServerRegistrar) {
		generated.RegisterExampleServiceServer(server, s)
	}
}

Where ServiceImplementation is your implementation of the generated service interface. And RegisterExampleServiceServer is the generated helper method to register.

  1. Add flamingo grpc server: Inside your main.go add the grpc.ServerModule to the flamingo bootstrap.
  2. You may now configure the authenticators inside your configuration:
grpc.identifier: test

Example

See the example application inside this module. The grpc server start on the default port :11101

Authenticators

To enable OAuth bearer authentication add this to your config.cue

grpc: identifier: [
    {"identifier": "management", "provider": "oauth2", "issuer": "http://localhost:8080/auth/realms/testreal", "clientID": "sampleapp"},
]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeycloakClientRoles

func KeycloakClientRoles(token oauth.Identity, client string) ([]string, error)

func KeycloakClients

func KeycloakClients(token oauth.Identity) (map[string][]string, error)

func KeycloakRealmRoles

func KeycloakRealmRoles(token oauth.Identity) ([]string, error)

Types

type CallIdentifier

type CallIdentifier interface {
	Identifier() string
	Identify(ctx context.Context) (auth.Identity, error)
}

type CallIdentifierFactory

type CallIdentifierFactory func(config config.Map) (CallIdentifier, error)

type IdentityService

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

func (*IdentityService) Identify

func (service *IdentityService) Identify(ctx context.Context) auth.Identity

func (*IdentityService) IdentifyAll

func (service *IdentityService) IdentifyAll(ctx context.Context) []auth.Identity

func (*IdentityService) IdentifyAs

func (service *IdentityService) IdentifyAs(ctx context.Context, checkType auth.IdentityTypeChecker) (auth.Identity, error)

IdentifyAs returns an identity for a given interface identity, err := s.IdentifyAs(ctx, request, OpenIDTypeChecker) identity.(oauth.OpenIDIdentity)

func (*IdentityService) IdentifyFor

func (service *IdentityService) IdentifyFor(ctx context.Context, identifier string) (auth.Identity, error)

func (*IdentityService) Inject

func (service *IdentityService) Inject(providers []CallIdentifier) *IdentityService

type Module

type Module struct{}

func (*Module) Configure

func (*Module) Configure(injector *dingo.Injector)

func (*Module) CueConfig

func (*Module) CueConfig() string

type ServerModule

type ServerModule struct{}

func (*ServerModule) Configure

func (*ServerModule) Configure(injector *dingo.Injector)

func (*ServerModule) Depends

func (*ServerModule) Depends() []dingo.Module

type ServerRegister

type ServerRegister func(server ServerRegistrar)

type ServerRegistrar

type ServerRegistrar grpc.ServiceRegistrar

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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