-
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.
- Loading branch information
Marco Zocca
committed
Jun 25, 2023
1 parent
f483ab2
commit 867f3e0
Showing
8 changed files
with
160 additions
and
21 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
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 |
---|---|---|
@@ -1 +1,13 @@ | ||
module MSAzureAPI where | ||
module MSAzureAPI ( | ||
-- ** HTTP request helpers | ||
tryReq | ||
-- ** Common types | ||
, Collection | ||
, collectionValue | ||
, collectionNextLink | ||
-- *** Location | ||
, Location(..) | ||
, showLocation | ||
) where | ||
|
||
import MSAzureAPI.Internal.Common |
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
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,58 @@ | ||
module MSAzureAPI.MachineLearning.Usages where | ||
|
||
import Control.Applicative (Alternative(..)) | ||
import Control.Monad.IO.Class (MonadIO(..)) | ||
import Data.Foldable (asum) | ||
import Data.Functor (void) | ||
-- import Data.Maybe (listToMaybe) | ||
import GHC.Generics (Generic(..)) | ||
|
||
-- aeson | ||
import qualified Data.Aeson as A (ToJSON(..), genericToEncoding, FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=), Key, Value, camelTo2) | ||
-- bytestring | ||
import qualified Data.ByteString as BS (ByteString) | ||
import qualified Data.ByteString.Char8 as BS8 (pack, unpack) | ||
import qualified Data.ByteString.Lazy as LBS (ByteString) | ||
-- hoauth2 | ||
-- import Network.OAuth.OAuth2 (OAuth2Token(..)) | ||
import Network.OAuth.OAuth2.Internal (AccessToken(..)) | ||
-- req | ||
import Network.HTTP.Req (Req, Url, Option, Scheme(..), header, (=:)) | ||
-- text | ||
import Data.Text (Text, pack, unpack) | ||
import qualified Data.Text.Lazy as TL (Text, pack, unpack, toStrict) | ||
|
||
import qualified MSAzureAPI.Internal.Common as MSA (APIPlane(..), (==:), put, get, getBs, post, getLbs, Collection, Location, showLocation, aesonOptions) | ||
|
||
-- | Gets the current usage information as well as limits for AML resources for given subscription and location. | ||
-- | ||
-- docs : <https://learn.microsoft.com/en-us/rest/api/azureml/2023-04-01/usages/list?tabs=HTTP> | ||
-- | ||
-- @GET https:\/\/management.azure.com\/subscriptions\/{subscriptionId}\/providers\/Microsoft.MachineLearningServices\/locations\/{location}\/usages?api-version=2023-04-01@ | ||
getUsages :: Text -- ^ subscription ID | ||
-> MSA.Location -- ^ location | ||
-> AccessToken -> Req (MSA.Collection Usage) | ||
getUsages sid loc = MSA.get MSA.APManagement [ | ||
"subscriptions", sid, | ||
"providers", "Microsoft.MachineLearningServices", | ||
"locations", MSA.showLocation loc, | ||
"usages" | ||
] ("api-version" MSA.==: "2023-04-01") | ||
|
||
data Usage = Usage { | ||
uCurrentValue :: Int | ||
, uLimit :: Int | ||
, uType :: Text | ||
, uName :: UsageName | ||
} deriving (Eq, Show, Ord, Generic) | ||
instance A.FromJSON Usage where | ||
parseJSON = A.genericParseJSON (MSA.aesonOptions "u") | ||
|
||
data UsageName = UsageName { | ||
unLocalizedValue :: Text | ||
, unValue :: Text | ||
} deriving (Eq, Show, Ord, Generic) | ||
instance A.FromJSON UsageName where | ||
parseJSON = A.genericParseJSON (MSA.aesonOptions "un") | ||
|
||
|
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