in src/aws-cpp-sdk-core/source/config/AWSConfigFileProfileConfigLoader.cpp [414:533]
void FlushSection(const State currentState, const Aws::String& currentSectionName, Aws::Map<Aws::String, Aws::String>& currentKeyValues)
{
if(START == currentState || currentSectionName.empty())
{
return; //nothing to flush
}
if(PROFILE_FOUND == currentState)
{
Profile& profile = m_foundProfiles[currentSectionName];
for(const auto& keyVal : currentKeyValues)
{
auto setterFuncPtr = FindInStaticArray(PROFILE_PROPERTY_FUNCS, keyVal.first);
if(setterFuncPtr)
{
AWS_LOGSTREAM_DEBUG(PARSER_TAG, "Found " << setterFuncPtr->PropertyKey << " " << keyVal.second);
setterFuncPtr->Setter(profile, keyVal.second);
}
else
{
auto specialPropertyKey = std::find_if(PROFILE_KEY_SPECIAL_HANDLING, PROFILE_KEY_SPECIAL_HANDLING + PROFILE_KEY_SPECIAL_HANDLING_SZ,
[&keyVal](const char* entry)
{
return !!entry && keyVal.first == entry;
});
if (specialPropertyKey && specialPropertyKey != PROFILE_KEY_SPECIAL_HANDLING + PROFILE_KEY_SPECIAL_HANDLING_SZ)
{
AWS_LOGSTREAM_INFO(PARSER_TAG, "Unknown property: " << keyVal.first << " in the profile: " << currentSectionName);
}
}
}
auto accessKeyIdIter = currentKeyValues.find(ACCESS_KEY_ID_KEY);
Aws::String accessKey, secretKey, sessionToken, accountId;
if (accessKeyIdIter != currentKeyValues.end())
{
accessKey = accessKeyIdIter->second;
AWS_LOGSTREAM_DEBUG(PARSER_TAG, "found access key " << accessKey);
auto secretAccessKeyIter = currentKeyValues.find(SECRET_KEY_KEY);
auto sessionTokenIter = currentKeyValues.find(SESSION_TOKEN_KEY);
if (secretAccessKeyIter != currentKeyValues.end())
{
secretKey = secretAccessKeyIter->second;
}
else
{
AWS_LOGSTREAM_ERROR(PARSER_TAG, "No secret access key found even though an access key was specified. This will cause all signed AWS calls to fail.");
}
if (sessionTokenIter != currentKeyValues.end())
{
sessionToken = sessionTokenIter->second;
}
const auto accountIdIter = currentKeyValues.find(ACCOUNT_ID_KEY);
if (accountIdIter != currentKeyValues.end())
{
accountId = accountIdIter->second;
}
profile.SetCredentials(Aws::Auth::AWSCredentials(accessKey,
secretKey,
sessionToken,
DateTime{(std::chrono::time_point<std::chrono::system_clock>::max)()},
accountId));
}
if (!profile.GetSsoStartUrl().empty() || !profile.GetSsoRegion().empty()
|| !profile.GetSsoAccountId().empty() || !profile.GetSsoRoleName().empty())
{
// If there is no sso session, all fields are required. If an SSO session is present,
// then only account id and sso role name are required.
auto hasSession = currentKeyValues.find(SSO_SESSION_KEY) != currentKeyValues.end();
auto hasInvalidProfileWithoutSession = !hasSession &&
(profile.GetSsoStartUrl().empty()
|| profile.GetSsoRegion().empty()
|| profile.GetSsoAccountId().empty()
|| profile.GetSsoRoleName().empty());
auto hasInvalidProfileWithSession = hasSession &&
(profile.GetSsoAccountId().empty()
|| profile.GetSsoRoleName().empty());
if (hasInvalidProfileWithoutSession || hasInvalidProfileWithSession) {
profile.SetSsoStartUrl("");
profile.SetSsoRegion("");
profile.SetSsoAccountId("");
profile.SetSsoRoleName("");
AWS_LOGSTREAM_ERROR(PARSER_TAG, "invalid SSO configuration for aws profile " << currentSectionName);
}
}
profile.SetName(currentSectionName);
profile.SetAllKeyValPairs(std::move(currentKeyValues));
}
else if (SSO_SESSION_FOUND == currentState) {
Profile::SsoSession& ssoSession = m_foundSsoSessions[currentSectionName];
for(const auto& keyVal : currentKeyValues)
{
auto setterFuncPtr = FindInStaticArray(SSO_SESSION_PROPERTY_FUNCS, keyVal.first);
if(setterFuncPtr)
{
AWS_LOGSTREAM_DEBUG(PARSER_TAG, "Found sso-session property " << setterFuncPtr->PropertyKey << " " << keyVal.second);
setterFuncPtr->Setter(ssoSession, keyVal.second);
}
else
{
AWS_LOGSTREAM_INFO(PARSER_TAG, "Unknown property: " << keyVal.first << " in the sso-session: " << currentSectionName);
}
}
ssoSession.SetName(currentSectionName);
ssoSession.SetAllKeyValPairs(std::move(currentKeyValues));
}
else
{
AWS_LOGSTREAM_FATAL(PARSER_TAG, "Unknown parser error: unexpected state " << currentState);
}
}