generate_access_policy_headers ( $users )

Generates the HTTP headers to be used for the Access Control Policy Grants.

Access

public

Parameters

Parameter

Type

Required

Description

$users

array

Required

An array of associative arrays. Each associative array contains an id value and a permission value.

Returns

Type

Description

array

HTTP headers to be applied to the request.

See Also

Source

Method defined in services/s3.class.php | Toggle source view (45 lines) | View on GitHub

public function generate_access_policy_headers($users)
{
    $headers = array();

    foreach ($users as $user)
    {
        // Determine permission. If doesn't exist, create it.
        $permission = 'x-amz-grant-' . str_replace('_', '-', strtolower($user['permission']));
        if (!isset($headers[$permission]))
        {
            $headers[$permission] = array();
        }

        // Handle the IDs
        switch ($user['id'])
        {
            case self::USERS_AUTH:    // Authorized Users
            case self::USERS_ALL:     // All Users
            case self::USERS_LOGGING: // The Logging User
                $headers[$permission][] = 'uri="' . $user['id'] . '"';
                break;

            // Email Address or Canonical Id
            default:
                if (strpos($user['id'], '@'))
                {
                    // Treat as email address
                    $headers[$permission][] = 'emailAddress="' . $user['id'] . '"';
                }
                else
                {
                    // Assume Canonical Id
                    $headers[$permission][] = 'id="' . $user['id'] . '"';
                }
                break;
        }
    }

    foreach ($headers as &$permission)
    {
        $permission = implode(', ', $permission);
    }

    return $headers;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback