Coder Social home page Coder Social logo

Comments (4)

nikita-volkov avatar nikita-volkov commented on June 8, 2024

TLDR completely, as suggested )
I actually have something "in the spirit" already implemented in private projects. Haven't worked on integrating it into the acid-state yet though. The configurations are separated for client and server, the code explains why. Besides solving the configuration issues it also abstracts over connecting to local or remote server or running the server itself with openExisting.
@lemmih what do you think about that?

startServer 
  :: IsAcidic a
  => Either (Int, Set ByteString) FilePath 
  -- ^ Port and secrets or a socket file
  -> AcidState a
  -- ^ State
  -> IO ()
startServer options acid = case options of
  Left (port, secrets) -> do
    Acid.acidServer 
      (Acid.sharedSecretCheck secrets) 
      (Network.PortNumber $ fromIntegral port) 
      acid
  Right socket -> do
    Acid.acidServer 
      Acid.skipAuthenticationCheck
      (Network.UnixSocket $ FilePath.encodeString socket) 
      acid



data URL 
  = Socket FilePath
  -- ^ A path to a socket file
  | Host Text Int (Maybe ByteString) 
  -- ^ Host, port and secret
  | Path FilePath
  -- ^ A path to local state
  | Name Text 
  -- ^ A name of state located under standard local directory
  deriving (Eq, Ord, Show)

-- | Open an existing state by "URL".
-- TODO: handle connection failure and probably return 'Either'.
openExisting :: IsAcidic a => URL -> IO (AcidState a)
openExisting url = case url of
  Host host port (Just secret) -> 
    Acid.openRemoteState 
      (Acid.sharedSecretPerform secret) 
      (Text.unpack host)
      (Network.PortNumber $ fromIntegral port)
  Host host port _ -> 
    Acid.openRemoteState 
      Acid.skipAuthenticationPerform 
      (Text.unpack host)
      (Network.PortNumber $ fromIntegral port)
  Socket path -> do
    path' <- FilePath.resolve path
    Acid.openRemoteState
      Acid.skipAuthenticationPerform 
      ""
      (Network.UnixSocket $ FilePath.encodeString path')
  Path path -> do
    path' <- FilePath.resolve path
    Acid.openLocalStateFrom (FilePath.encodeString $ path') $
      error $ "No initialized local state found at following path: " <> FilePath.encodeString path
  Name name -> do
    home <- FilePath.getHomeDirectory
    let path = home <> ".acid-databases" <> FilePath.fromText name
    openLocalStateFrom (FilePath.encodeString path) $
      error $ "No initialized local state found under following name: " <> Text.unpack name

from acid-state.

lemmih avatar lemmih commented on June 8, 2024

I defer all judgement regarding the remote backend to @stepcut.

from acid-state.

dag avatar dag commented on June 8, 2024

@nikita-volkov Your ideas inspired me to rethink some things, so I think I have an API I'm satisfied with now.

from acid-state.

stepcut avatar stepcut commented on June 8, 2024

However, the fact that sharedSecretCheck takes a set of secrets suggests that acid-state wants to support more complex setups where you have multiple clients connecting from multiple systems. In this type of use, I think separate configurations better reflect reality, at the expense of complicating the simpler cases a bit.

Correct -- it is setup so that there could be multiple clients and then you could revoke access to one of them. It is also setup so that other authentication schemes could be used besides shared secrets.

Although not currently supported, it could also be nice if there were two permission levels -- read vs read/write. Or perhaps a scheme where each client has a whitelist of which specific methods they can invoke.

from acid-state.

Related Issues (20)

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.