Safe Haskell | None |
---|---|
Language | Haskell2010 |
Dependencies
The examples require the following declarations (which in turn mean that the req
and bytestring
libraries are imported by the user's project). You will also need the OverloadedStrings
language extension :
import qualified Data.ByteString.Lazy as LB import Network.HTTP.Req (responseBody) import Network.Goggles
Examples
This first example, listBucket
, reads content from a cloud storage bucket:
- it loads the GCP credentials (username and RSA key),
- retrieves a token via OAuth2,
- performs a single call to the Cloud Storage API endpoint that lists the metadata related to the contents of a storage bucket, and
- returns the raw API data to the user as a lazy ByteString.
listBucket :: IO LB.ByteString listBucket = do let usr = "...iam.gserviceaccount.com" bucket = "<my-gcs-bucket>" key = "<rsa_key>" pvtkey <- parseRSAPrivateKey key let creds = GCPServiceAccount pvtkey usr Nothing "" hdl <- createHandle creds scopesDefault responseBody <$> evalWebApiIO hdl (listObjects bucket)
- data GCP
- scopesDefault :: [Text]
- getObject :: Text -> Text -> WebApiM GCP LbsResponse
- getObjectMetadata :: Text -> Text -> WebApiM GCP LbsResponse
- listObjects :: Text -> WebApiM GCP LbsResponse
- putObject :: Text -> Text -> ByteString -> WebApiM GCP LbsResponse
- requestTokenGCP :: WebApiM GCP (Token GCP)
Documentation
scopesDefault :: [Text] Source #
OAuth2 scopes for the various Google Cloud Platform services.
Please refer to
https://developers.google.com/identity/protocols/googlescopes
for the full list
getObject :: Text -> Text -> WebApiM GCP LbsResponse Source #
`getObject b p` retrieves the contents of a GCS object (of full path p
) in bucket b
getObjectMetadata :: Text -> Text -> WebApiM GCP LbsResponse Source #
`getObjectMetadata b p` retrieves the metadata of a GCS object (of full path p
) in bucket b
listObjects :: Text -> WebApiM GCP LbsResponse Source #
`listObjects b` retrieves a list of objects stored in bucket b
putObject :: Text -> Text -> ByteString -> WebApiM GCP LbsResponse Source #
`putObject b p body` uploads a bytestring body
into a GCS object (of full path p
) in bucket b
requestTokenGCP :: WebApiM GCP (Token GCP) Source #
Implementation of tokenFetch