| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.CloudFoundry.Environment
Description
The purpose of this library is to assist you in writing Haskell apps that run on Cloud Foundry. It provides convenience functions and structures that map to Cloud Foundry environment variable primitives.
This package is a port of https://github.com/cloudfoundry-community/go-cfenv
Synopsis
- current :: IO Application
- isRunningOnCf :: IO Bool
- lookupCurrent :: IO (Maybe Application)
- credentialString :: String -> Service -> Maybe String
- withLabel :: String -> Services -> [Service]
- withName :: String -> Services -> Maybe Service
- withTag :: String -> Services -> [Service]
- data Application = Application {}
- data Limits = Limits {}
- data Service = Service {}
- newtype Services = Services (Map String [Service])
- data CfEnvError
Documentation
current :: IO Application #
Get the current Cloud Foundry environment.
Example using scotty:
import Data.String (fromString)
import Data.Monoid (mconcat)
import Web.Scotty
import qualified System.CloudFoundry.Environment as CfEnv
main = do
app <- CfEnv.current
scotty (CfEnv.port app) $
get "/" $ do
html $ mconcat ["<pre>", (fromString (show app)), "</pre>"]isRunningOnCf :: IO Bool #
Detect if the application is running as a Cloud Foundry application.
import System.CloudFoundry.Environment CfEnv
main :: IO ()
main = do
isRunningOnCf <- CfEnv.isRunningOnCf
if isRunningOnCf
then putStrLn "Running on Cloud Foundry"
else putStrLn "Not running on Cloud Foundry"lookupCurrent :: IO (Maybe Application) #
Get the current Cloud Foundry environment and return the result in a Maybe.
See current.
Arguments
| :: String | The key to each for in the credentials section |
| -> Service | The service to get the value from |
| -> Maybe String | The value of that credential string if it is found |
Get a credential string from a service.
Arguments
| :: String | The label to search for |
| -> Services | All services bound to the application |
| -> [Service] | A list of matching services |
Get the services by label.
Arguments
| :: String | The name of the service to be found |
| -> Services | All services bound to the application |
| -> Maybe Service | The service if it is found |
Get the service by name.
Arguments
| :: String | The tag to search for |
| -> Services | All services bound to the application |
| -> [Service] | A list of matching services |
Get all services which have the provided tag.
data Application #
Holds information about the current app running on Cloud Foundry.
This is returned from current.
Constructors
| Application | |
Fields
| |
Instances
| Eq Application # | |
| Show Application # | |
Defined in System.CloudFoundry.Environment.Internal.Types Methods showsPrec :: Int -> Application -> ShowS # show :: Application -> String # showList :: [Application] -> ShowS # | |
Constructors
| Limits | |
Instances
| Eq Limits # | |
| Show Limits # | |
| Generic Limits # | |
| FromJSON Limits # | |
| type Rep Limits # | |
Defined in System.CloudFoundry.Environment.Internal.Types type Rep Limits = D1 (MetaData "Limits" "System.CloudFoundry.Environment.Internal.Types" "cfenv-0.1.0.0-7wivOZL2gAV510sC4QCrs9" False) (C1 (MetaCons "Limits" PrefixI True) (S1 (MetaSel (Just "disk") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: (S1 (MetaSel (Just "fds") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: S1 (MetaSel (Just "mem") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)))) | |
Description of a bound service. Use credentialString to extract the
connection details.
Constructors
| Service | |
Instances
| Eq Service # | |
| Show Service # | |
| Generic Service # | |
| FromJSON Service # | |
| type Rep Service # | |
Defined in System.CloudFoundry.Environment.Internal.Types type Rep Service = D1 (MetaData "Service" "System.CloudFoundry.Environment.Internal.Types" "cfenv-0.1.0.0-7wivOZL2gAV510sC4QCrs9" False) (C1 (MetaCons "Service" PrefixI True) ((S1 (MetaSel (Just "name") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: S1 (MetaSel (Just "label") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :*: (S1 (MetaSel (Just "tags") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [String]) :*: (S1 (MetaSel (Just "plan") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: S1 (MetaSel (Just "credentials") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map String String)))))) | |
A collection of Service instances. withTag, withName and withLabel can be
used to find the specific services that you want.
data CfEnvError #
Exceptions which are raised from this package.
Constructors
| DecodeError String String | Thrown when a JSON decode failed for either the VCAP_APPLICATION or VCAP_SERIVCES environment variables. |
| NotInteger String String | Thrown when an environment variable which is meant to contain an integer contains invalid characters. |
Instances
| Eq CfEnvError # | |
| Show CfEnvError # | |
Defined in System.CloudFoundry.Environment.Internal.Types Methods showsPrec :: Int -> CfEnvError -> ShowS # show :: CfEnvError -> String # showList :: [CfEnvError] -> ShowS # | |
| Exception CfEnvError # | |
Defined in System.CloudFoundry.Environment.Internal.Types Methods toException :: CfEnvError -> SomeException # fromException :: SomeException -> Maybe CfEnvError # displayException :: CfEnvError -> String # | |