コード例 #1
0
void ProfileConfigFileAWSCredentialsProvider::RefreshIfExpired()
{
    std::lock_guard<std::mutex> locker(m_reloadMutex);
    if (!m_credentials || IsTimeToRefresh(m_loadFrequencyMs))
    {
        AWS_LOG_DEBUG(profileLogTag, "Refreshing credentials.");

        Aws::Map<Aws::String, Aws::String> propertyValueMap = ParseProfileConfigFile(m_fileName);

        Aws::String accessKey, secretKey, sessionToken;
        auto accessKeyIter = propertyValueMap.find(m_profileToUse + ":" + AWS_ACCESS_KEY_ID);
        auto secretKeyIter = propertyValueMap.find(m_profileToUse + ":" + AWS_SECRET_ACCESS_KEY);
        auto sessionTokenIter = propertyValueMap.find(m_profileToUse + ":" + AWS_SESSION_TOKEN);

        if (accessKeyIter != propertyValueMap.end())
            accessKey = accessKeyIter->second;
        else
        AWS_LOG_INFO(profileLogTag, "Access key for profile not found.");

        if (secretKeyIter != propertyValueMap.end())
            secretKey = secretKeyIter->second;
        else
        AWS_LOG_INFO(profileLogTag, "Secret key for profile not found.");

        if (sessionTokenIter != propertyValueMap.end())
            sessionToken = sessionTokenIter->second;
        else
        AWS_LOG_INFO(profileLogTag, "Optional session token for profile not found.");

        m_credentials = Aws::MakeShared<AWSCredentials>(profileLogTag, accessKey, secretKey, sessionToken);
    }
}
コード例 #2
0
ファイル: Directory.cpp プロジェクト: marcomagdy/aws-sdk-cpp
        Aws::Map<Aws::String, DirectoryEntry> DirectoryTree::Diff(DirectoryTree& other)
        {
            Aws::Map<Aws::String, DirectoryEntry> thisEntries;
            auto thisTraversal = [&thisEntries](const DirectoryTree*, const DirectoryEntry& entry)
            {
                thisEntries[entry.relativePath] = entry;
                return true;
            };

            Aws::Map<Aws::String, DirectoryEntry> otherEntries;
            auto otherTraversal = [&thisEntries, &otherEntries](const DirectoryTree*, const DirectoryEntry& entry)
            {
                auto thisEntry = thisEntries.find(entry.relativePath);
                if (thisEntry != thisEntries.end())
                {
                    thisEntries.erase(entry.relativePath);
                }
                else
                {
                    otherEntries[entry.relativePath] = entry;
                }

                return true;
            };

            TraverseDepthFirst(thisTraversal);
            other.TraverseDepthFirst(otherTraversal);

            thisEntries.insert(otherEntries.begin(), otherEntries.end());
            return thisEntries;
        }
コード例 #3
0
TEST_F(QueueOperationTest, TestSendReceiveDelete)
{
    Aws::String queueName = BuildResourceName(BASE_SEND_RECEIVE_QUEUE_NAME);
    Aws::String queueUrl = CreateDefaultQueue(queueName);
    ASSERT_TRUE(queueUrl.find(queueName) != Aws::String::npos);

    SendMessageRequest sendMessageRequest;
    sendMessageRequest.SetMessageBody("TestMessageBody");
    MessageAttributeValue stringAttributeValue;
    stringAttributeValue.SetStringValue("TestString");
    stringAttributeValue.SetDataType("String");
    sendMessageRequest.AddMessageAttributes("TestStringAttribute", stringAttributeValue);

    MessageAttributeValue binaryAttributeValue;
    Aws::Utils::ByteBuffer byteBuffer(10);
    for(unsigned i = 0; i < 10; ++i)
    {
        byteBuffer[i] = (unsigned char)i;
    }

    binaryAttributeValue.SetBinaryValue(byteBuffer);
    binaryAttributeValue.SetDataType("Binary");
    sendMessageRequest.AddMessageAttributes("TestBinaryAttribute", binaryAttributeValue);

    sendMessageRequest.SetQueueUrl(queueUrl);

    SendMessageOutcome sendMessageOutcome = sqsClient->SendMessage(sendMessageRequest);
    ASSERT_TRUE(sendMessageOutcome.IsSuccess());
    EXPECT_TRUE(sendMessageOutcome.GetResult().GetMessageId().length() > 0);

    ReceiveMessageRequest receiveMessageRequest;
    receiveMessageRequest.SetMaxNumberOfMessages(1);
    receiveMessageRequest.SetQueueUrl(queueUrl);
    receiveMessageRequest.AddMessageAttributeNames("All");

    ReceiveMessageOutcome receiveMessageOutcome = sqsClient->ReceiveMessage(receiveMessageRequest);
    ASSERT_TRUE(receiveMessageOutcome.IsSuccess());
    ReceiveMessageResult receiveMessageResult = receiveMessageOutcome.GetResult();
    ASSERT_EQ(1uL, receiveMessageResult.GetMessages().size());
    EXPECT_EQ("TestMessageBody", receiveMessageResult.GetMessages()[0].GetBody());
    Aws::Map<Aws::String, MessageAttributeValue> messageAttributes = receiveMessageResult.GetMessages()[0].GetMessageAttributes();
    ASSERT_TRUE(messageAttributes.find("TestStringAttribute") != messageAttributes.end());
    EXPECT_EQ(stringAttributeValue.GetStringValue(), messageAttributes["TestStringAttribute"].GetStringValue());
    ASSERT_TRUE(messageAttributes.find("TestBinaryAttribute") != messageAttributes.end());
    EXPECT_EQ(byteBuffer, messageAttributes["TestBinaryAttribute"].GetBinaryValue());

    DeleteMessageRequest deleteMessageRequest;
    deleteMessageRequest.SetQueueUrl(queueUrl);
    deleteMessageRequest.SetReceiptHandle(receiveMessageResult.GetMessages()[0].GetReceiptHandle());

    DeleteMessageOutcome deleteMessageOutcome = sqsClient->DeleteMessage(deleteMessageRequest);
    ASSERT_TRUE(deleteMessageOutcome.IsSuccess());

    receiveMessageOutcome = sqsClient->ReceiveMessage(receiveMessageRequest);
    EXPECT_EQ(0uL, receiveMessageOutcome.GetResult().GetMessages().size());

    DeleteQueueRequest deleteQueueRequest;
    deleteQueueRequest.WithQueueUrl(queueUrl);

    DeleteQueueOutcome deleteQueueOutcome = sqsClient->DeleteQueue(deleteQueueRequest);
    ASSERT_TRUE(deleteQueueOutcome.IsSuccess());
}