Comments (4)
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.
I defer all judgement regarding the remote backend to @stepcut.
from acid-state.
@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.
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)
- Get size of acid-state? HOT 3
- Failed to build acid-state-0.15.1 HOT 8
- acid-state fails to build with GHC 8.8.1 HOT 1
- Changelog entry for 0.16 is missing HOT 1
- Test suite fails on macOS HOT 8
- build fails on ghc 9.0.1 HOT 1
- Hackage release needed for GHC 9.0.2 support HOT 2
- Benchmark `loading-benchmark` fails to build with GHC 7.10 HOT 3
- GHC versions covered by AppVeyor CI HOT 3
- acid-state on cluster HOT 1
- Haddocks for Data.Acid.Memory.Pure.AcidState are misleading HOT 1
- Database seems empty after ctrl+c HOT 4
- Build failures with mtl-2.3
- Support GHC 9.4 HOT 1
- README: possibly outdated irc link
- Build failure with unix-2.8 (GHC 9.6)
- Support GHC 9.6
- Build failure with template-haskell-2.21 (GHC 9.8)
- Benchmarks fail to build on GHC 9.8 due to `system-filepath`
- Unnecessary use of strict bytestrings in Data.Acid.Log HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acid-state.