on master help sign in
Merge pull request #44 from alexfmpe/deploy-init-missing-keys

Fail 'ob deploy init' when not given a ssh-key

commit45294fb1bd0d25cb7abc641d54c9dc4bf1d73305 authorLuigy Leon <luichi.19@gmail.com> dateWed 30 May 2018, 19:07 (8 years ago) parent0e8155b452414b
1 file changed+10−10
lib/command/src/Obelisk/Command/Deploy.hs+10−10
lib/command/src/Obelisk/Command/Deploy.hs+10−10
@@ -31,6 +31,16 @@ deployInit thunkPtr configDir deployDir sshKeyPath hostnames = do
3131 hasConfigDir <- liftIO $ do
3232 createDirectoryIfMissing True deployDir
3333 doesDirectoryExist configDir
34+ localKey <- liftIO (doesFileExist sshKeyPath) >>= \case
35+ False -> failWith $ T.pack $ "ob deploy init: file does not exist: " <> sshKeyPath
36+ True -> pure $ deployDir </> "ssh_key"
37+ callProcessAndLogOutput (Notice, Error) $
38+ cp [sshKeyPath, localKey]
39+ liftIO $ setFileMode localKey $ ownerReadMode .|. ownerWriteMode
40+ liftIO $ writeFile (deployDir </> "backend_hosts") $ unlines hostnames
41+ forM_ hostnames $ \hostname -> do
42+ putLog Notice $ "Verifying host keys (" <> T.pack hostname <> ")"
43+ verifyHostKey (deployDir </> "backend_known_hosts") localKey hostname
3444 when hasConfigDir $ do
3545 callProcessAndLogOutput (Notice, Error) $
3646 cp
@@ -39,16 +49,6 @@ deployInit thunkPtr configDir deployDir sshKeyPath hostnames = do
3949 , configDir
4050 , deployDir </> "config"
4151 ]
42− keyExists <- liftIO $ doesFileExist sshKeyPath
43− when keyExists $ do
44− let localKey = deployDir </> "ssh_key"
45− callProcessAndLogOutput (Notice, Error) $
46− cp [sshKeyPath, localKey]
47− liftIO $ setFileMode localKey $ ownerReadMode .|. ownerWriteMode
48− liftIO $ writeFile (deployDir </> "backend_hosts") $ unlines hostnames
49− forM_ hostnames $ \hostname -> do
50− putLog Notice $ "Verifying host keys (" <> T.pack hostname <> ")"
51− verifyHostKey (deployDir </> "backend_known_hosts") localKey hostname
5252 liftIO $ createThunk (deployDir </> "src") thunkPtr
5353 liftIO $ setupObeliskImpl deployDir
5454 initGit deployDir