generated from tpl/purs
32 lines
1.1 KiB
Haskell
32 lines
1.1 KiB
Haskell
module Gitea.Repo.Secret where
|
|
|
|
import Prelude hiding ((/))
|
|
|
|
import Control.Monad.Reader (ask)
|
|
import Data.Tuple.Nested ((/\))
|
|
import Data.URL (URL, (/))
|
|
import Effect.Aff.Class (class MonadAff)
|
|
import Gitea.Auth as Auth
|
|
import Gitea.Error as Error
|
|
import Gitea.Trans (GiteaT)
|
|
import Gitea.Types (RepoName(..), SecretName(..), Username(..))
|
|
import HTTP (Method(..), fetch) as HTTP
|
|
import HTTP.Request (json) as HTTP
|
|
|
|
secretsURL :: forall m. Monad m => Username -> RepoName -> SecretName -> GiteaT m URL
|
|
secretsURL (Username owner) (RepoName repo) (SecretName secret) = (\{ baseURI } -> baseURI / "repos" / owner / repo / secret) <$> ask
|
|
|
|
set :: forall m. MonadAff m => Username -> RepoName -> SecretName -> String -> GiteaT m Unit
|
|
set u r s sv = do
|
|
{ auth } <- ask
|
|
url <- secretsURL u r s
|
|
rep <- HTTP.fetch $ HTTP.PUT /\ url /\ HTTP.json { "data": sv } /\ Auth.headers auth
|
|
Error.guardStatusOk rep
|
|
|
|
remove :: forall m. MonadAff m => Username -> RepoName -> SecretName -> GiteaT m Unit
|
|
remove u r s = do
|
|
{ auth } <- ask
|
|
url <- secretsURL u r s
|
|
rep <- HTTP.fetch $ HTTP.DELETE /\ url /\ Auth.headers auth
|
|
Error.guardStatusOk rep
|