You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for fmt.Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed as the action argument
#1729
Methods such as the Authorize(actor interface{}, action interface{}, resource interface{}) method only accept direct string types as a value for the action parameter.
A common implementation of Oso is to create an enum defining available actions using a custom Action type. A very basic implementation of this might look something like this:
However, if you pass one of these constants into the Authorize function, it will not properly detect whether or not the action is authorized. This is because the Authorize() function expects a string, not a custom type.
There is also no log message, warning or error indicating the mistake.
One possible solution to this would be to update the Authorize function to accept an implementation of the fmt.Stringer interface.
This might look something like this:
funcAuthorize(actor, action, resourceinterface{}) error {
varactionStrstringswitchv:=action.(type) {
casestring:
actionStr=vcase fmt.Stringer:
actionStr=v.String()
default:
returnfmt.Errorf("action must be either a valid string or implement the fmt.Stringer interface")
}
fmt.Printf("found action: %v\n", actionStr)
returnnil
}
. . .
err:=Authorize(user, Action_LoginMobile, resource)
Alternately, simply providing an error or a warning indicating that the Authorization will fail due to an incorrect type being passed to the method would at least inform the caller that they need to be passing a string type, and not a type definition that resolves to a string.
The text was updated successfully, but these errors were encountered:
nathan-fiscaletti
changed the title
Add support for Stringer implementations in Oso methods, or propagate a warning message in instances where a type defined string is passed
Add support for Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed
Nov 3, 2023
nathan-fiscaletti
changed the title
Add support for Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed
Add support for fmt.Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed
Nov 3, 2023
nathan-fiscaletti
changed the title
Add support for fmt.Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed
Add support for fmt.Stringer implementations in Go SDK Oso methods, or propagate a warning message in instances where a type defined string is passed as the action argument
Nov 3, 2023
Methods such as the
Authorize(actor interface{}, action interface{}, resource interface{})
method only accept directstring
types as a value for theaction
parameter.A common implementation of Oso is to create an
enum
defining available actions using a customAction
type. A very basic implementation of this might look something like this:However, if you pass one of these constants into the
Authorize
function, it will not properly detect whether or not the action is authorized. This is because theAuthorize()
function expects astring
, not a custom type.There is also no log message, warning or error indicating the mistake.
One possible solution to this would be to update the
Authorize
function to accept an implementation of thefmt.Stringer
interface.This might look something like this:
Alternately, simply providing an error or a warning indicating that the Authorization will fail due to an incorrect type being passed to the method would at least inform the caller that they need to be passing a
string
type, and not a type definition that resolves to astring
.The text was updated successfully, but these errors were encountered: