Skip to content

Commit

Permalink
Read endpoint url from proper file (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmspzz authored Jun 19, 2019
1 parent b79a73e commit 10e7a05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
17 changes: 4 additions & 13 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ getAWSEnv = do
manager <- liftIO (Conduit.newManager Conduit.tlsManagerSettings)
ref <- liftIO (newIORef Nothing)
let roleARN = eitherToMaybe $ AWS.roleARNOf profile =<< config
let curerntEnv = AWS.Env region
let currentEnv = AWS.Env region
(\_ _ -> pure ())
(AWS.retryConnectionFailure 3)
mempty
manager
ref
auth
case roleARN of
Just role -> newEnvFromRole role curerntEnv
Just role -> newEnvFromRole role currentEnv
Nothing -> return
$ AWS.configure (maybe S3.s3 s3EndpointOverride endpointURL) curerntEnv
$ AWS.configure (maybe S3.s3 s3EndpointOverride endpointURL) currentEnv

newEnvFromRole :: MonadIO m => T.Text -> AWS.Env -> ExceptT String m AWS.Env
newEnvFromRole roleARN currentEnv = do
Expand All @@ -149,15 +149,6 @@ newEnvFromRole roleARN currentEnv = do
++ show assumeRoleResult
Just newAuth -> return $ currentEnv & AWS.envAuth .~ newAuth

getAWSRegion :: (MonadIO m, MonadCatch m) => ExceptT String m AWS.Env
getAWSRegion = do
region <- discoverRegion
endpointURL <- runMaybeT . exceptToMaybeT $ discoverEndpoint
set AWS.envRegion region
<$> ( AWS.newEnv AWS.Discover
<&> AWS.configure (maybe S3.s3 s3EndpointOverride endpointURL)
)

allCacheKeysMissingMessage :: String
allCacheKeysMissingMessage
= "Error: expected at least one of \"local\", \
Expand Down Expand Up @@ -1866,7 +1857,7 @@ discoverEndpoint = do
profile <- liftIO $ lookupEnv "AWS_PROFILE"
let fileEndPointURL =
( getAWSConfigFilePath
>>= flip getEndpointFromFile (fromMaybe "default" profile)
>>= getEndpointFromFile (fromMaybe "default" profile)
)
`catch` \(e :: IOError) -> ExceptT . return . Left . show $ e
(ExceptT . return $ envEndpointURL) <|> fileEndPointURL
Expand Down
4 changes: 2 additions & 2 deletions src/Network/AWS/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import Network.URL
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Except (ExceptT (..), withExceptT)

newtype ConfigFile = ConfigFile { _awsConfigIni :: Ini }
newtype CredentialsFile = CredentialsFile { _awsCredentialsIni :: Ini }
newtype ConfigFile = ConfigFile { _awsConfigIni :: Ini } deriving Show
newtype CredentialsFile = CredentialsFile { _awsCredentialsIni :: Ini } deriving Show

class FromIni a where
asIni :: a -> Ini
Expand Down

0 comments on commit 10e7a05

Please sign in to comment.