Beispiel #1
0
        Aws::String Join(char delimiter, const Aws::String& leftSegment, const Aws::String& rightSegment)
        {
            Aws::StringStream ss;

            if (!leftSegment.empty())
            {
                if (leftSegment.back() == delimiter)
                {
                    ss << leftSegment.substr(0, leftSegment.length() - 1);
                }
                else
                {
                    ss << leftSegment;
                }
            }

            ss << delimiter;

            if (!rightSegment.empty())
            {
                if (rightSegment.front() == delimiter)
                {
                    ss << rightSegment.substr(1);
                }
                else
                {
                    ss << rightSegment;
                }
            }

            return ss.str();
        }
    static bool ClassSetup()
    {
        // README:
        // modify the TEST_TITLE_DATA_LOC to a location of a testTitleData.json file
        // The format of this file is described in the sdk readme
        //  - OR -
        // Comment the "return false;" below, and
        //   Fill in all the variables under: POPULATE THIS SECTION WITH REAL INFORMATION

        std::ifstream titleInput;
        titleInput.open(TEST_TITLE_DATA_LOC, std::ios::binary | std::ios::in);
        if (titleInput)
        {
            int begin = titleInput.tellg();
            titleInput.seekg(0, std::ios::end);
            int end = titleInput.tellg();
            char* titleData = new char[end - begin];
            titleInput.seekg(0, std::ios::beg);
            titleInput.read(titleData, end - begin);
            titleData[end - begin] = '\0';

            Document testInputs;
            testInputs.Parse<0>(titleData);
            SetTitleInfo(testInputs);

            titleInput.close();
        }
        else
        {
            return false;
            // TODO: Put the info for your title here (Fallback in case it can't read from the file)

            // POPULATE THIS SECTION WITH REAL INFORMATION
            playFabSettings->titleId = ""; // The titleId for your title, found in the "Settings" section of PlayFab Game Manager
            TITLE_CAN_UPDATE_SETTINGS = true; // Make sure this is enabled in your title, found in the "Settings" section, "API Features" section of PlayFab Game Manager
            userName = ""; // This is an arbitrary user name, which will be utilized for this test
            userEmail = ""; // This is the email for the user
            userPassword = ""; // This is the password for the user
            characterName = ""; // This should be a valid character on the given user's account
        }

        // Verify all the inputs won't cause crashes in the tests
        return static_cast<bool>(titleInput)
            && !playFabSettings->titleId.empty()
            && !userName.empty()
            && !userEmail.empty()
            && !userPassword.empty()
            && !characterName.empty();
    }
    void PersistIdentityId(const Aws::String& identityId) override 
    { 
        SetIdentityId(identityId); 
        m_identityIdPersisted = !identityId.empty();

        if (m_identityIdUpdatedCallback)
        {
            m_identityIdUpdatedCallback(*this);
        }
    }
Beispiel #4
0
Aws::String GetHomeDirectory()
{
    static const char* HOME_DIR_ENV_VAR = "USERPROFILE";

    AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Checking " << HOME_DIR_ENV_VAR << " for the home directory.");
    Aws::String homeDir = Aws::Environment::GetEnv(HOME_DIR_ENV_VAR);
    AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Environment value for variable " << HOME_DIR_ENV_VAR << " is " << homeDir);
    if(homeDir.empty())
    {
        AWS_LOGSTREAM_WARN(FILE_SYSTEM_UTILS_LOG_TAG, "Home dir not stored in environment, trying to fetch manually from the OS.");
        HANDLE hToken;
    
        if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken))
        {
            DWORD len = MAX_PATH;
            WCHAR path[MAX_PATH];
            if (GetUserProfileDirectoryW(hToken, path, &len))
            {                
                homeDir = Aws::Utils::StringUtils::FromWString(path);
            }
            CloseHandle(hToken);
        }        

        AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Pulled " << homeDir << " as home directory from the OS.");
    }

    Aws::String retVal = (homeDir.size() > 0) ? Aws::Utils::StringUtils::Trim(homeDir.c_str()) : "";

    if (!retVal.empty())
    {
        if (retVal.at(retVal.length() - 1) != Aws::FileSystem::PATH_DELIM)
        {
            retVal += Aws::FileSystem::PATH_DELIM;
        }
    }
    
    return retVal;
}
Aws::String FileSystemUtils::GetHomeDirectory()
{
    static const char* HOME_DIR_ENV_VAR = "HOME";

    AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Checking " << HOME_DIR_ENV_VAR << " for the home directory.");
 
    const char* homeEnvDir = std::getenv(HOME_DIR_ENV_VAR);
    Aws::String homeDir(homeEnvDir ? homeEnvDir : "");

    AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Environment value for variable " << HOME_DIR_ENV_VAR << " is " << homeDir);

    if(homeDir.empty())
    {
        AWS_LOG_WARN(FILE_SYSTEM_UTILS_LOG_TAG, "Home dir not stored in environment, trying to fetch manually from the OS.");

	passwd pw;
	passwd *p_pw = nullptr;
	char pw_buffer[4096];
	getpwuid_r(getuid(), &pw, pw_buffer, sizeof(pw_buffer), &p_pw);
        if(p_pw && p_pw->pw_dir)
        {
            homeDir = p_pw->pw_dir;
        }
	
        AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Pulled " << homeDir << " as home directory from the OS.");
    }

    Aws::String retVal = homeDir.size() > 0 ? StringUtils::Trim(homeDir.c_str()) : "";
    if(!retVal.empty())
    {
        if(retVal.at(retVal.length() - 1) != PATH_DELIM)
        {
            AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Home directory is missing the final " << PATH_DELIM << " appending one to normalize");
            retVal += PATH_DELIM;
        }
    }

    AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Final Home Directory is " << retVal);

    return retVal;
}
void InstanceProfileCredentialsProvider::RefreshIfExpired()
{
    AWS_LOG_DEBUG(instanceLogTag, "Checking if latest credential pull has expired.");

    std::lock_guard<std::mutex> locker(m_reloadMutex);
    if (!m_credentials || IsTimeToRefresh(m_loadFrequencyMs))
    {
        AWS_LOG_INFO(instanceLogTag, "Credentials have expired attempting to repull from EC2 Metadata Service.");
        Aws::String mdRet = m_metadataClient->GetDefaultCredentials();

        if (mdRet.empty())
        {
            AWS_LOG_WARN(instanceLogTag, "Not able to pull credentials from the metadata service, returning empty credentials.");
            m_credentials = Aws::MakeShared<AWSCredentials>(instanceLogTag, "", "");
            return;
        }

        const char* accessKeyId = "AccessKeyId";
        const char* secretAccessKey = "SecretAccessKey";
        Aws::String accessKey, secretKey, token;

        using namespace Aws::Utils::Json;
        JsonValue jsonValue(mdRet);

        if (jsonValue.WasParseSuccessful())
        {
            accessKey = jsonValue.GetString(accessKeyId);
            AWS_LOGSTREAM_INFO(instanceLogTag, "Successfully pulled credentials from metadata service with access key " << accessKey);

            secretKey = jsonValue.GetString(secretAccessKey);
            token = jsonValue.GetString("Token");
        }
        else
        {
            AWS_LOGSTREAM_ERROR(instanceLogTag, "Failed to parse output from Ec2MetadataService with error " << jsonValue.GetErrorMessage());
        }

        m_credentials = Aws::MakeShared<AWSCredentials>(instanceLogTag, accessKey, secretKey, token);
    }
}