Coder Social home page Coder Social logo

oso's Introduction

Haskell bindings to polar

This library contains Haskell bindings to the Polar query engine, and provides an API for the Oso authorization library.

Example

module Main where

import Control.Exception
import Oso


-- Define ordinary Haskell types, deriving PolarValue to allow them to be used
-- with Polar.
newtype User = User
  { roles :: [Role]
  }
  deriving stock (Eq, Generic, Show)
  deriving PolarValue via GenericPolarRecord User


data Role = Role
  { name :: Text
  , resource :: Organization
  }
  deriving stock (Eq, Generic, Show)
  deriving PolarValue via GenericPolarRecord Role


data Repository = Repository
  { name :: Text
  , organization :: Organization
  }
  deriving stock (Eq, Generic, Show)
  deriving PolarValue via GenericPolarRecord Repository


newtype Organization = Organization
  { name :: Text }
  deriving stock (Eq, Generic, Show)
  deriving PolarValue via GenericPolarRecord Repository


main :: IO ()
main = do
  -- Create a new handle to the Polar query engine.
  oso <- newOso

  -- Register any types used for RBAC
  registerType @User oso
  registerType @Role oso
  registerType @Repository oso
  registerType @Organization oso

  -- Load the policy.polar file
  expect =<< loadFiles oso ["policy.polar"]

  -- Fetch data needed for authorization. For this example we'll just construct
  -- some test values.
  let circuitHub = Organization{ name = "CircuitHub" }
  let oso        = Organization{ name = "oso" }

  let ourRepository = Repository{ name = "circuithub", organization = circuitHub }
  let chRepository  = Repository{ name = "circuithub", organization = circuitHub }
  let osoRepository = Repository{ name = "oso", organization = oso }

  let chUser = User{ roles = [ Role{ name = "owner", resource = circuitHub } ] }

  -- Run some queries!
  isAllowed oso chUser "read" chRepository  -- True

  isAllowed oso chUser "read" osoRepository -- False


expect :: Exception e => Either e a -> IO a
expect = either throw pure

oso's People

Contributors

ocharles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

oso's Issues

Licensing question

Hello!

I just wanted to know: does this Haskell library have any license?

At first, I was interested in using it but there was some features that existed in the other client libraries (Ruby, JS...) that were missing here (e.g. data filtering). Also, compiling the library automatically required some doing (compile the Oso API library and link with it).

I played with the code just to see what could be done (implemented some of the features I wanted to test, ease the compilation process...). But since there is no official license for the library (though Oso is Apache-2 licensed), I don't think I can do anything with that experiment.

So I was wondering what the project's license was and what it allowed me to do with it.

Thanks in any case ๐Ÿ™‚

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.