From f470601503fe5417000939c2e2b6549ad71a39a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Thu, 12 Oct 2023 15:46:11 +0200 Subject: [PATCH 1/2] build(flake): introduce aeson, yaml, bytestring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- app/Main.hs | 7 +++++++ maid.cabal | 11 ++++++++++- package.yaml | 3 +++ stack.yaml.lock | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 3952c81..a3da4a2 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DeriveGeneric #-} -- (2) + module Main where -- import MonadRandom @@ -7,6 +9,11 @@ import Lib import System.IO import System.Process +import qualified Data.ByteString.Char8 as BS +import qualified Data.Yaml as Y +import GHC.Generics +import Data.Aeson + getRandomMaidIndex :: (MonadRandom m) => m Int getRandomMaidIndex = do let n = length maids - 1 diff --git a/maid.cabal b/maid.cabal index fe1a79b..44064bb 100644 --- a/maid.cabal +++ b/maid.cabal @@ -1,6 +1,6 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.5. +-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack @@ -32,8 +32,11 @@ library src build-depends: MonadRandom >=0.6 + , aeson , base >=4.7 && <5 + , bytestring , process + , yaml default-language: Haskell2010 executable maid @@ -45,9 +48,12 @@ executable maid ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: MonadRandom >=0.6 + , aeson , base >=4.7 && <5 + , bytestring , maid , process + , yaml default-language: Haskell2010 test-suite maid-test @@ -60,7 +66,10 @@ test-suite maid-test ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: MonadRandom >=0.6 + , aeson , base >=4.7 && <5 + , bytestring , maid , process + , yaml default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 053ad3b..982de77 100644 --- a/package.yaml +++ b/package.yaml @@ -23,6 +23,9 @@ dependencies: - base >= 4.7 && < 5 - MonadRandom >= 0.6 - process + - aeson + - yaml + - bytestring library: source-dirs: src diff --git a/stack.yaml.lock b/stack.yaml.lock index 7ce337e..1cbe28f 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,8 +6,8 @@ packages: [] snapshots: - completed: + sha256: 1867d84255dff8c87373f5dd03e5a5cb1c10a99587e26c8793e750c54e83ffdc size: 639139 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/0.yaml - sha256: 1867d84255dff8c87373f5dd03e5a5cb1c10a99587e26c8793e750c54e83ffdc original: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/0.yaml From de41aa4dc29e1fda7c799427d8c1f0a3ab7b1dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Thu, 12 Oct 2023 15:50:55 +0200 Subject: [PATCH 2/2] feat: proof of concept config parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- app/Main.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Main.hs b/app/Main.hs index a3da4a2..67b5ab6 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -14,6 +14,9 @@ import qualified Data.Yaml as Y import GHC.Generics import Data.Aeson +data Cred = Cred { example :: String, other :: String } deriving (Show, Generic) -- (1,2) +instance FromJSON Cred -- (3) + getRandomMaidIndex :: (MonadRandom m) => m Int getRandomMaidIndex = do let n = length maids - 1 @@ -91,6 +94,11 @@ performCleanup = do main :: IO () main = do + content <- BS.readFile "config.yaml" -- (4) + let parsedContent = Y.decode content :: Maybe Cred -- (5) + case parsedContent of + Nothing -> putStrLn "[-] no config found" + (Just (Cred u p)) -> putStrLn ("[+] example: " ++ u ++ ", other: " ++ p) maid <- getRandomMaid putStrLn maid putStrLn "[+] !!!Cleaning Time!!!"