<commit_before>{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE RecordWildCards     #-}
{-# LANGUAGE StandaloneDeriving  #-}
{-# LANGUAGE TemplateHaskell     #-}
{-# LANGUAGE TupleSections       #-}

-- Module      : Khan.Meta
-- Copyright   : (c) 2013 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)

module Khan.Meta (meta) where

import           Control.Applicative
import           Control.Error
import qualified Data.ByteString.Char8    as BS
import           Data.Text.Encoding
import           Khan.Internal
import           Network.AWS
-- import           Network.AWS.EC2
import           Network.AWS.EC2.Metadata

defineOptions "Describe" $ do
    textOption "dInstanceId" "instance-id" ""
        "Id of the instance to describe."

    regionOption "dRegion" "region" Ireland
        "Region of the instance."

deriving instance Show Describe

instance Discover Describe where
    discover d = do
        iid <- decodeUtf8 <$> metadata InstanceId
        az  <- BS.unpack . BS.init <$> metadata AvailabilityZone
        reg <- fmapError $ tryRead ("Failed to read region from: " ++ az) az
        return $! d
            { dInstanceId = iid
            , dRegion     = reg
            }

instance Validate Describe where
    validate Describe{..} =
        check dInstanceId "--instance-id must be specified."

meta :: Command
meta = Command "meta" "Manage Instance Metadata."
    [ subCommand "describe" describe
    ]
  where
    describe d@Describe{..} = do
        logInfo $ "Describing instance " ++ show d ++ "..."
        -- r@DescribeTagsResponse{..} <- send $ DescribeTags
        --     [ TagResourceId [dInstanceId]
        --     ]

        -- logInfo $ show r

--        within dRegion


<commit_msg>Re-enabling describe tags test<commit_after>{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE RecordWildCards     #-}
{-# LANGUAGE StandaloneDeriving  #-}
{-# LANGUAGE TemplateHaskell     #-}
{-# LANGUAGE TupleSections       #-}

-- Module      : Khan.Meta
-- Copyright   : (c) 2013 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)

module Khan.Meta (meta) where

import           Control.Applicative
import           Control.Error
import qualified Data.ByteString.Char8    as BS
import           Data.Text.Encoding
import           Khan.Internal
import           Network.AWS
import           Network.AWS.EC2
import           Network.AWS.EC2.Metadata

defineOptions "Describe" $ do
    textOption "dInstanceId" "instance-id" ""
        "Id of the instance to describe."

    regionOption "dRegion" "region" Ireland
        "Region of the instance."

deriving instance Show Describe

instance Discover Describe where
    discover d = do
        iid <- decodeUtf8 <$> metadata InstanceId
        az  <- BS.unpack . BS.init <$> metadata AvailabilityZone
        reg <- fmapError $ tryRead ("Failed to read region from: " ++ az) az
        return $! d
            { dInstanceId = iid
            , dRegion     = reg
            }

instance Validate Describe where
    validate Describe{..} =
        check dInstanceId "--instance-id must be specified."

meta :: Command
meta = Command "meta" "Manage Instance Metadata."
    [ subCommand "describe" describe
    ]
  where
    describe d@Describe{..} = do
        logInfo $ "Describing instance " ++ show d ++ "..."
        r@DescribeTagsResponse{..} <- send $ DescribeTags
            [ TagResourceId [dInstanceId]
            ]

        logInfo $ show r

--        within dRegion



{'fraction_non_alphanumeric': 0.10494425593795444, 'fraction_numerical': 0.0058167716917111, 'mean_word_length': 2.057037037037037, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6491577', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1192, 'n_words': 371}