From 846b1d7754043507da8bade90656fdd4b48f4985 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello Date: Wed, 7 Oct 2020 16:47:05 -0600 Subject: [PATCH] static path for appmgr and other feedback --- config/routes | 4 ++-- config/settings.yml | 1 + package.yaml | 8 ++++---- src/Handler/Apps.hs | 10 ++-------- src/Settings.hs | 2 ++ test/Handler/AppSpec.hs | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/config/routes b/config/routes index 94b5128..4a2d706 100644 --- a/config/routes +++ b/config/routes @@ -1,8 +1,8 @@ /apps AppsManifestR GET -- get current apps listing -/apps/#S9PK/#Text/manifest AppManifestR GET -- get app manifest from appmgr - requires query param ?appmgr= -/apps/#S9PK/#Text/config AppConfigR GET -- get app config from appmgr - requires query param ?appmgr= +/apps/#S9PK/#Text/manifest AppManifestR GET -- get app manifest from appmgr +/apps/#S9PK/#Text/config AppConfigR GET -- get app config from appmgr /version VersionR GET diff --git a/config/settings.yml b/config/settings.yml index 629418c..f2222e1 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -32,6 +32,7 @@ resources-path: "_env:RESOURCES_PATH:/var/www/html/resources" ssl-path: "_env:SSL_PATH:/var/ssl" registry-hostname: "_env:REGISTRY_HOSTNAME:registry.start9labs.com" tor-port: "_env:TOR_PORT:447" +static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/" database: database: "_env:PG_DATABASE:start9_registry" diff --git a/package.yaml b/package.yaml index 8636379..2c796a4 100644 --- a/package.yaml +++ b/package.yaml @@ -2,15 +2,15 @@ name: start9-registry version: 0.1.0 default-extensions: -- NoImplicitPrelude +- FlexibleInstances - GeneralizedNewtypeDeriving - LambdaCase - MultiWayIf - NamedFieldPuns +- NoImplicitPrelude - NumericUnderscores - OverloadedStrings - StandaloneDeriving -- FlexibleInstances dependencies: - base >=4.12 && <5 @@ -36,10 +36,12 @@ dependencies: - persistent-template - process - protolude +- shakespeare - template-haskell - text - time - transformers +- typed-process - unordered-containers - unix - wai @@ -51,8 +53,6 @@ dependencies: - yesod - yesod-core - yesod-persistent -- shakespeare -- typed-process library: source-dirs: src diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 3ab643b..4a49881 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -88,20 +88,14 @@ getSysR e = do getAppManifestR :: Extension "s9pk" -> Text -> Handler TypedContent getAppManifestR e@(Extension appId) v = do - appmgrVersion <- lookupGetParam "appmgr" >>= \case - Nothing -> sendResponseStatus status400 ("Appmgr version required" :: Text) - Just a -> pure $ toS a - appMgrDir <- (<> "/") . ( appmgrVersion) . ( "appmgr") . ( "sys") . resourcesDir . appSettings <$> getYesod + appMgrDir <- (<> "/") . staticBinDir . appSettings <$> getYesod appDir <- (<> "/") . ( toS v) . ( appId) . ( "apps") . resourcesDir . appSettings <$> getYesod manifest <- handleS9ErrT $ getManifest appMgrDir appDir e pure $ TypedContent "application/json" (toContent manifest) getAppConfigR :: Extension "s9pk" -> Text -> Handler TypedContent getAppConfigR e@(Extension appId) v = do - appmgrVersion <- lookupGetParam "appmgr" >>= \case - Nothing -> sendResponseStatus status400 ("Appmgr version required" :: Text) - Just a -> pure $ toS a - appMgrDir <- (<> "/") . ( appmgrVersion) . ( "appmgr") . ( "sys") . resourcesDir . appSettings <$> getYesod + appMgrDir <- (<> "/") . staticBinDir . appSettings <$> getYesod appDir <- (<> "/") . ( toS v) . ( appId) . ( "apps") . resourcesDir . appSettings <$> getYesod config <- handleS9ErrT $ getConfig appMgrDir appDir e pure $ TypedContent "application/json" (toContent config) diff --git a/src/Settings.hs b/src/Settings.hs index 2a3cc26..e6160f4 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -50,6 +50,7 @@ data AppSettings = AppSettings , sslCsrLocation :: FilePath , sslCertLocation :: FilePath , torPort :: AppPort + , staticBinDir :: FilePath } instance FromJSON AppSettings where @@ -64,6 +65,7 @@ instance FromJSON AppSettings where sslPath <- o .: "ssl-path" registryHostname <- o .: "registry-hostname" torPort <- o .: "tor-port" + staticBinDir <- o .: "static-bin-dir" let sslKeyLocation = sslPath "key.pem" let sslCsrLocation = sslPath "certificate.csr" diff --git a/test/Handler/AppSpec.hs b/test/Handler/AppSpec.hs index 0cdc379..af80566 100644 --- a/test/Handler/AppSpec.hs +++ b/test/Handler/AppSpec.hs @@ -76,6 +76,6 @@ spec = do withApp $ it "gets bitcoin manifest" $ do request $ do setMethod "GET" - setUrl ("/apps/bitcoind.s9pk/0.2.5/manifest?appmgr=0.2.5" :: Text) + setUrl ("/apps/bitcoind.s9pk/0.2.5/manifest" :: Text) statusIs 200 bodyContains "{\"id\":\"bitcoind\",\"version\":\"0.20.1\",\"title\":\"Bitcoin Core\",\"description\":{\"short\":\"Bitcoin Full Node by Bitcoin Core\",\"long\":\"Bitcoin is an innovative payment network and a new kind of money. Bitcoin uses peer-to-peer technology to operate with no central authority or banks; managing transactions and the issuing of bitcoins is carried out collectively by the network. Bitcoin is open-source; its design is public, nobody owns or controls Bitcoin and everyone can take part. Through many of its unique properties, Bitcoin allows exciting uses that could not be covered by any previous payment system.\"},\"release-notes\":\"https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.20.1.md\",\"has-instructions\":true,\"os-version-required\":\">=0.2.4\",\"os-version-recommended\":\">=0.2.4\",\"ports\":[{\"internal\":8332,\"tor\":8332},{\"internal\":8333,\"tor\":8333}],\"image\":{\"type\":\"tar\"},\"mount\":\"/root/.bitcoin\",\"assets\":[{\"src\":\"bitcoin.conf.template\",\"dst\":\".\",\"overwrite\":true}],\"hidden-service-version\":\"v2\",\"dependencies\":{}}"