palauth-iam-go/check.go

27 lines
547 B
Go
Raw Permalink Normal View History

2023-10-21 12:02:42 +01:00
package palauthiam
import "context"
type CheckPermissionRequest struct {
UserID string
2023-10-21 12:23:27 +01:00
Permission IAMPermission
2023-10-21 12:02:42 +01:00
}
type CheckPermissionResponse struct {
Allowed bool `json:"allowed"`
}
func (c *PalAuthIAMClient) CheckPermission(ctx context.Context, request *CheckPermissionRequest) (bool, error) {
resp := CheckPermissionResponse{}
err := c.getRequest(ctx, "/check", map[string]string{
"userId": request.UserID,
2023-10-21 12:23:27 +01:00
"permission": string(request.Permission),
2023-10-21 12:02:42 +01:00
}, &resp)
if err != nil {
return false, err
}
return resp.Allowed, nil
}