-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add top level APIs for fetching secrets
- Adds top level APIs for fetching secrets (`getSecret` and `getSecretEither`) - Removes call to `defaultAzureCredentials` in client. Users need to supply `AccessToken` - Split types and functions.
- Loading branch information
Showing
4 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
|
||
module Azure.Secret.Types | ||
( KeyVaultResponse (..) | ||
, SecretName (..) | ||
, KeyVaultHost (..) | ||
) where | ||
|
||
import Data.Aeson (FromJSON (..), withObject, (.:)) | ||
import Data.Text (Text) | ||
import GHC.Generics (Generic) | ||
|
||
newtype KeyVaultResponse = KeyVaultResponse | ||
{ unKeyValueReponse :: Text | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
instance FromJSON KeyVaultResponse where | ||
parseJSON = withObject "KeyVaultResponse" $ \o -> do | ||
unKeyValueReponse <- o .: "value" | ||
pure KeyVaultResponse{..} | ||
|
||
newtype SecretName = SecretName {unSecretName :: Text} deriving stock (Eq, Show) | ||
|
||
newtype KeyVaultHost = KeyVaultHost {unKeyVaultHost :: Text} deriving stock (Eq, Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Main where | ||
|
||
import Azure.Secret (getSecret) | ||
import Azure.Secret.Types (KeyVaultHost (..), SecretName (..)) | ||
import Azure.Types (newEmptyToken) | ||
import Azure.Auth (defaultAzureCredential) | ||
|
||
main :: IO () | ||
main = do | ||
tok <- newEmptyToken | ||
cred <- defaultAzureCredential Nothing "https://vault.azure.net" tok | ||
-- In order to run this, you need to replace @SecretName@ and @KeyVaultHost@ with | ||
-- appropriate values in your resource group. These are just dummy values. | ||
getSecret (SecretName "radiohead") (KeyVaultHost "albums") cred >>= print |