public function getRoleNameFromMeta()

in src/EcsRamRoleCredential.php [76:104]


    public function getRoleNameFromMeta()
    {
        $options = [
            'http_errors' => false,
            'timeout' => 1,
            'connect_timeout' => 1,
        ];

        $result = Request::createClient()->request(
            'GET',
            'http://100.100.100.200/latest/meta-data/ram/security-credentials/',
            $options
        );

        if ($result->getStatusCode() === 404) {
            throw new InvalidArgumentException('The role name was not found in the instance');
        }

        if ($result->getStatusCode() !== 200) {
            throw new RuntimeException('Error retrieving credentials from result: ' . $result->getBody());
        }

        $role_name = (string) $result;
        if (!$role_name) {
            throw new RuntimeException('Error retrieving credentials from result is empty');
        }

        return $role_name;
    }