wepala / weos-controller

Apache License 2.0
0 stars 0 forks source link

Ensure that account id is always in the context of gRPC calls #42

Open akeemphilbert opened 2 years ago

akeemphilbert commented 2 years ago

Due Date: 6/12/21

Description

In the REST side of things we have middleare that looks for the X-ACCOUNT-ID header and adds the account id to the context. 
We'd need the equivalent for grpc

UAT

Place UAT here

Deployment Steps

SubTasks

RandyDeo commented 2 years ago

Useful links : https://stackoverflow.com/questions/40379960/context-withvalue-how-to-add-several-key-value-pairs https://go.dev/blog/context

RandyDeo commented 2 years ago

https://stackoverflow.com/questions/47599509/grpc-context-on-the-client-side

akeemphilbert commented 2 years ago

Hey team! Please add your planning poker estimate with ZenHub @RandyDeo @shaniah868

RandyDeo commented 2 years ago

42 - In order for the accountID to always be in the context for gRPC calls, it will be needed to be passed into the context at the client level. With the generation of protobuf files, there is the resulting file which handles the grpc and within there, your service/ defined rpc calls will be generated as a function as well. These require a context to be passed in which is done at the client side. Therefore, a context function such as WithValue can be utilized which would add to the context and be passed along with your function calls to the server.

Alternatively, Metadata (Header) is another viable option. A client may only send a Header, however a server can send both Headers and Trailers. So for attaching the AccountID at the clientside, metadata.NewContext() can be utilized to send it, and on the serverside, metadata.FromContext() to recieve the metadata.

Useful Links: https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md https://stackoverflow.com/questions/47599509/grpc-context-on-the-client-side