Skip to content

Commit

Permalink
Drop dummy token from JSON API check (#12593)
Browse files Browse the repository at this point in the history
* Drop dummy token from JSON API check

That token is broken in a number of ways, e.g. broken ledger ids,
parties that may not exist, ….

When we created that there was no healthcheck endpoint on the JSON API
but now that there is one, we can just use that one and it doesn’t
need any token so things get a lot simpler.

changelog_begin
changelog_end

* I promise it compiles this time

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Jan 26, 2022
1 parent 3366c6f commit 9c3f1ce
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ import Control.Concurrent
import Control.Concurrent.Async
import Control.Monad
import Control.Monad.Extra hiding (fromMaybeM)
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe
import qualified Data.Map.Strict as Map
import DA.PortFile
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Network.HTTP.Simple as HTTP
import Network.Socket.Extended (getFreePort)
import System.Console.ANSI
import System.FilePath
import System.Process.Typed
import System.IO.Extra
import System.Info.Extra
import Web.Browser
import qualified Web.JWT as JWT
import Data.Aeson

import Options.Applicative.Extended (YesNoAuto, determineAutoM)

Expand Down Expand Up @@ -142,22 +136,8 @@ withJsonApi (SandboxPort sandboxPort) (JsonApiPort jsonApiPort) extraArgs a = do
] ++ extraArgs
withSdkJar args "json-api-logback.xml" $ \ph -> do
putStrLn "Waiting for JSON API to start: "
-- The secret doesn’t matter here
let token = JWT.encodeSigned (JWT.HMACSecret "secret") mempty mempty
{ JWT.unregisteredClaims = JWT.ClaimsMap $
Map.fromList [("https://daml.com/ledger-api", Object $ HashMap.fromList
[("actAs", toJSON ["Alice" :: T.Text]), ("ledgerId", "sandbox"), ("applicationId", "foobar")])]
-- TODO https://github.com/digital-asset/daml/issues/12145
-- Drop the ledgerId field once it becomes optional.
}
-- For now, we have a dummy authorization header here to wait for startup since we cannot get a 200
-- response otherwise. We probably want to add some method to detect successful startup without
-- any authorization
let headers =
[ ("Authorization", "Bearer " <> T.encodeUtf8 token)
] :: HTTP.RequestHeaders
waitForHttpServer 240 (unsafeProcessHandle ph) (putStr "." *> threadDelay 500000)
("http://localhost:" <> show jsonApiPort <> "/v1/query") headers
("http://localhost:" <> show jsonApiPort <> "/readyz") []
a ph

data JsonApiConfig = JsonApiConfig
Expand Down

0 comments on commit 9c3f1ce

Please sign in to comment.