You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King III (JIRA)" <ji...@apache.org> on 2019/01/03 14:18:00 UTC
[jira] [Closed] (THRIFT-4221) Add Rails like Before Action to
Thrift
[ https://issues.apache.org/jira/browse/THRIFT-4221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James E. King III closed THRIFT-4221.
-------------------------------------
Resolution: Won't Do
Assignee: James E. King III
Fix Version/s: (was: 1.0)
Agree with [~jensg] here. THeaderProtocol is an appropriate solution to carrying additional session-based metadata around.
> Add Rails like Before Action to Thrift
> --------------------------------------
>
> Key: THRIFT-4221
> URL: https://issues.apache.org/jira/browse/THRIFT-4221
> Project: Thrift
> Issue Type: New Feature
> Components: Wish List
> Affects Versions: 1.0
> Reporter: Devansh Gupta
> Assignee: James E. King III
> Priority: Major
> Labels: patch
> Attachments: golang_generated.diff, t_go_generator.diff
>
>
> One issue that comes up often is when we have a service defined with some functions and we want to do Authentication & Authorization we need to manually call a function from inside the service implementation every time.
> See:
> https://stackoverflow.com/questions/4621715/how-to-handle-authentication-and-authorization-with-thrift
> A decently popular question.
> This ticket proposes to add a _before_action_ (naming flexible) hook which will be called before the Service call method is executed. It can _only_ raise the same errors as defined by the function.
> _It requires the *generate_hooks* option to be set_
> Example diff for Golang generated code for simple service:
> {code}
> exception NotAuthorisedException {
> 1: string errorMessage,
> }
> exception ApiException {
> 1: string errorMessage,
> }
> service MyService {
> string myMethod(1: string authString, 2: string otherArgs ) throws ( 1: NotAuthorisedException e1, 2: ApiException e ),
> }
> {code}
> {code}
> + // Called before any other action is called
> + BeforeAction(serviceName string, actionName string, args map[string]interface{}) (err error)
> + // Called if an action returned an error
> + ProcessError(err error) error
> }
> type MyServiceClient struct {
> @@ -391,7 +395,12 @@ func (p *myServiceProcessorMyMethod) Process(seqId int32, iprot, oprot thrift.TP
> result := MyServiceMyMethodResult{}
> var retval string
> var err2 error
> - if retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_); err2 != nil {
> + err2 = p.handler.BeforeAction("MyService", "MyMethod", map[string]interface{}{"AuthString": args.AuthString, "OtherArgs_": args.OtherArgs_})
> + if err2 == nil {
> + retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_)
> + }
> + if err2 != nil {
> + err2 = p.handler.ProcessError(err2)
> {code}
> It simply calls BeforeAction, if it raises an error it does NOT procede with making the normal call.
> Diffs Attached.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)