Code Monkey home page Code Monkey logo

zendservice_amazon's Introduction

ZendService\Amazon component

Build Status

Installation

curl -s https://getcomposer.org/installer | php
php composer.phar install

Documentation

Read the documentation for the ZendService\Amazon component.

zendservice_amazon's People

Contributors

acoda avatar adamlundrigan avatar billkarwin avatar dasprid avatar demiankatz avatar denixport avatar dgasparri avatar evandotpro avatar ezimuel avatar farazdagi avatar jonathanmaron avatar jonnott avatar jonthewhite avatar maks3w avatar matwright avatar michalbundyra avatar mlaug avatar ocramius avatar postalservice14 avatar prolic avatar ralphschindler avatar rtuin avatar rufinus avatar samsonasik avatar sasezaki avatar slamdunk avatar thomasweidner avatar weierophinney avatar xerkus avatar yukikaoru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zendservice_amazon's Issues

HTTP 403 Forbidden

Hello everybody,

I have an issue with the basic example script provide in the Amazon doc (http://zf2.readthedocs.org/en/latest/modules/zendservice.amazon.s3.html) which look like this:

public function testAWSUpload()
{
$my_aws_key = 'XXXXXXXXXXXXXXXXXXXXXXX';
$my_aws_secret_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

    $s3 = new S3\S3($my_aws_key, $my_aws_secret_key);

    $list = $s3->getBuckets();

In debug mode this code throw me an HTTP 403 Forbidden. Here is the request:

GET / HTTP/1.1
Host: s3.amazonaws.com
Connection: close
Accept-Encoding: gzip, deflate
User-Agent: Zend\Http\Client
Content-Type: application/xml
Date: Thu, 08 Oct 2015 16:01:58 GMT
Authorization: AWS XXXXXXXXXXXXXXXXXX:pyGz5Fjvqo2ahnmHq78/nfV5p9M=

And there is the response:

HTTP/1.1 403 Forbidden
x-amz-request-id: F84DE8F4433CA8C3
x-amz-id-2: pK7eAIyPEIMtaYNWDUHLX8qIqRJVCdqKX6alDGlWJKL2ikKZTsKACkiP0mOt5jidYDJvQ2zAQJk=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Thu, 08 Oct 2015 16:01:58 GMT
Server: AmazonS3

2eb

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.XXXXXXXXXXXXXXXXXXXXXXGET

application/xml
Thu, 08 Oct 2015 16:01:58 GMT
/pyGz5Fjvqo2ahnmHq78/nfV5p9M=47 45 54 0a 0a 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 6d 6c 0a 54 68 75 2c 20 30 38 20 4f 63 74 20 32 30 31 35 20 31 36 3a 30 31 3a 35 38 20 47 4d 54 0a 2fF84DE8F4433CA8C3pK7eAIyPEIMtaYNWDUHLX8qIqRJVCdqKX6alDGlWJKL2ikKZTsKACkiP0mOt5jidYDJvQ2zAQJk=
0

I test my AWS KEY and AWS SECRET KEY on this site who return me the good name and canonical ID: http://www.bucketexplorer.com/awsutility.aspx

Anobody have a clue on what's happening?

Thank you

ZF3 port for this package?

I was curious whether there were plans to port this package to ZF3. I regularly build with a CMS based on ZF which recently upgraded from 2 to 3. Would love to have assets stored on S3 as seamlessly as before.

If there aren't plans, would be happy to contribute to the extent that I'm able.

Thanks!

AbstractEc2::setRegion() not in use

AbstractEc2::setRegion() writes to $_defaultRegion. But $_defaultRegion is only used in the Constructor if you dont provide an region. In all other cases $_region is used.

So if you have an instance of eg ZendService\Amazon\Ec2\Instance and use setRegion its not used at all.

Fix:
Line 104 in AbstractEc2 change to: self::$_region = $region;

SignatureDoesNotMatch with ZF 2.2.5 due to Date format

The date format for Zend\Http\Client seems to have changed from ZF 2.2.4 to ZF 2.2.5. Previously, the date was formatted as "Sun, 03 Nov 2013 15:07:45 -0500". However, starting with ZF 2.2.5 the format is "Sun, 03 Nov 2013 20:07:45 GMT". (I couldn't yet nail down exactly why, but was able to "resolve" it by replacing ZF 2.2.5's \Zend\Http directory with ZF 2.2.4's.).

This impacts the AWS Request Signature due to the mismatch with how \ZendService\Amazon\S3\S3::getRequestDate() generates the signature.

I've patched that method using

$date = new \DateTime('now', new \DateTimeZone('GMT'));
return $date->format('D, d M Y H:i:s \G\M\T');

which matches how \Zend\Http\Header\AbstractDate::setDate() works.

Thanks!

How can I set up region?

$sqs = new Sqs(self::ACCESS_KEY_ID, self::SECRET_KEY, "eu-west-1");
gives
Argument 3 passed to ZendService\Amazon\AbstractAmazon::__construct() must be an instance of Zend\Http\Client, string given, called in .../vendor/zendframework/zendservice-amazon/library/ZendService/Amazon/Sqs/Sqs.php on line 61
error.
Thanks.

Off-by-one error in ZendService\Amazon\S3\Stream::stream_read

In https://github.com/zendframework/ZendService_Amazon/blob/master/library/ZendService/Amazon/S3/Stream.php#L175 is an off-by-one error:

Imagine you want to read a larger file (450215 bytes) using PHP's readfile function.
On first attempt, stream_read will be called with $count set to 8192 with the result that $range_start will be 0 (because it is the first call) and $range_end will be set to 0+8192=8192. This will be used as Range header 0-8192 which will actually read 8193 bytes (see http://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7233.html#header.content-range) which you can see when you check length of $response->getBody() later.

The problem is now that we set $this->_objectBuffer to the larger value but extract only 8192 bytes via $data = substr($this->_objectBuffer, $this->_position, $count); and set position based on strlen($data).

So while we use the correct position on our next stream_read call but $this_>_objectBuffer is larger than expected we will miss (truncate) data.

Quick fix: Change

$range_end   = $this->_position+$count;

into

$range_end   = $this->_position+$count-1;

Now we are really only requesting $count bytes and $this->_objectBuffer contains exactly what we have already processed so we don't miss (truncate) any data anymore.

Add a way to detect `RequestThrottled` errors

The advertising API returns RequestThrottled errors when too many requests were made. Currently there seems to be no way to differentiate such errors from searches with no results. To overcome this limitation a method like the one below should be added to the ResultSet class.

public function hasError()
{
    return ($this->_xpath->evaluate('name(/*)') == 'ItemSearchErrorResponse');
}

Update Request/PR: Amazon PA API 5.0

PA API 4 will sunset on October 31st 2019.
Upgrade to PA API 5.0 is necessary in order for the package to function after said date.
Anyone working on this currently?

file_exists Always return true even if file does not exist

The php function file_exists() uses the the stream wrapper function url_stat()
Unfortunately \ZendService\Amazon\S3\Stream function url_stat always return a value even if the file does not exists
It means that everytime you uses file_exists() it always return true .

I only tested using FakeS3 - which simulate an amazon s3 "server" https://github.com/jubos/fake-s3
So it might be related but looking at the url_stat function I am pretty certain this is not caused by FakeS3

    /**
     * Return array of URL variables
     *
     * @param  string $path
     * @param  integer $flags
     * @return array
     */
    public function url_stat($path, $flags)
    {
        $stat = array();
        $stat['dev'] = 0;
        $stat['ino'] = 0;
        $stat['mode'] = 0777;
        $stat['nlink'] = 0;
        $stat['uid'] = 0;
        $stat['gid'] = 0;
        $stat['rdev'] = 0;
        $stat['size'] = 0;
        $stat['atime'] = 0;
        $stat['mtime'] = 0;
        $stat['ctime'] = 0;
        $stat['blksize'] = 0;
        $stat['blocks'] = 0;
    $name = $this->_getNamePart($path);
    if(($slash = strchr($name, '/')) === false || $slash == strlen($name)-1) {
        /* bucket */
        $stat['mode'] |= 040000;
    } else {
        $stat['mode'] |= 0100000;
    }
           $info = $this->_getS3Client($path)->getInfo($name);
        if (!empty($info)) {
            $stat['size']  = $info['size'];
            $stat['atime'] = time();
            $stat['mtime'] = $info['mtime'];
        }
        return $stat;
    }

I believe it should be

public function url_stat($path, $flags) {
        $stat = array();
        $stat['dev'] = 0;
        $stat['ino'] = 0;
        $stat['mode'] = 0777;
        $stat['nlink'] = 0;
        $stat['uid'] = 0;
        $stat['gid'] = 0;
        $stat['rdev'] = 0;
        $stat['size'] = 0;
        $stat['atime'] = 0;
        $stat['mtime'] = 0;
        $stat['ctime'] = 0;
        $stat['blksize'] = 0;
        $stat['blocks'] = 0;

        $name = $this->_getNamePart($path);
        if (($slash = strchr($name, '/')) === false || $slash == strlen($name) - 1) {
            /* bucket */
            $stat['mode'] |= 040000;
        } else {
            $stat['mode'] |= 0100000;
        }

        $info = $this->_getS3Client($path)->getInfo($name);

        if (!empty($info)) {
            $stat['size'] = $info['size'];
            $stat['atime'] = time();
            $stat['mtime'] = $info['mtime'];
            return $stat;
        }

        return false;

    }

ResultSet::totalResults() fails when !ResultSet::valid()

When an invalid response was returned by Amazon (e.g. RequestThrottled), using ResultSet::totalResults() results in the following error:

Notice: Trying to get property of non-object in /.../ZendService/Amazon/ResultSet.php on line 73.

That method should first check whether or not the response is valid.

Add support for parallel requests

Using e.g. curl_multi() it is possible to do HTTP requests in parallel. This technique would decrease the loading time in situations where more than one requests need to be done. This makes also a lot of sense when retrieving information from APIs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.