[openstack-dev] [Openstack] Accessing object data and metadata in Swift middleware

Itamar O itamarost at gmail.com
Wed Apr 24 14:27:05 UTC 2013


I looked into the pointers mentioned above,
and the make_pre_authed_request function was exactly what I needed.
I used:
 resp = make_pre_authed_request(env, 'GET', req.path, agent='MyCall',
swift_source='MC').get_response(self.app)
and got the requested object in resp, including metadata in the headers and
the actual object body.

Thanks!
- Itamar.



On Tue, Apr 23, 2013 at 7:51 AM, Itamar O <itamarost at gmail.com> wrote:

> David, Chmouel,
> Thank you for the pointers!
> I will look into it soon, hoping it solves my needs.
>
> Sorry for not posting to the dev-list from the beginning. I wasn't aware
> of it...
>
> - Itamar.
>
>
> On Mon, Apr 22, 2013 at 8:06 PM, David Goetz <david.goetz at rackspace.com>wrote:
>
>> There are examples in swift.common.middleware of doing this.
>>
>> If you want to try changing the metadata on the way out you can look at:
>>
>>
>> https://github.com/openstack/swift/blob/master/swift/common/middleware/staticweb.py#L367-L384
>>
>> it makes use of the WSGIContext class which allows you to make a call
>> down the pipeline and respond to it on the way back out.
>>
>> If you want to just kinda peek at the object before sending the request
>> you can use make_pre_authed_request as done here for containers:
>>
>>
>> https://github.com/openstack/swift/blob/master/swift/common/middleware/staticweb.py#L198-L201
>>
>> that function will take auth out of the environment so you want to be
>> careful about using it. It you want to keep auth you can do something along
>> the lines of:
>>
>>
>> https://github.com/openstack/swift/blob/master/swift/common/middleware/bulk.py#L250-L259
>>
>> which just makes a sub request using a copy of the current environment.
>> In your case, after you get that response you'd probably just want to let
>> the request continue on the pipeline instead of just completely overriding
>> it like the bulk middleware does.
>>
>> David
>>
>>
>>
>>
>>
>> On Apr 21, 2013, at 10:11 AM, Itamar O wrote:
>>
>> > Hello list,
>> > I am new to OpenStack development, and trying to implement a simple
>> Swift middleware.
>> > I was able to successfully manipulate a PUT request for an object,
>> processing the data that was uploaded by the request and storing some
>> information in the object metadata.
>> > But now I am struggling with handling GET requests for objects.
>> > I would like to access the data and metadata of the requested object
>> before it is passed down the pipeline, but I have no clue how to achieve
>> this.
>> >
>> > In case this is not the appropriate mailing list for this question, I
>> apologize, and would appreciate if someone could refer me to the correct
>> list.
>> > Otherwise, any advice will be much appreciated!
>> >
>> > Thanks,
>> > - Itamar.
>> > _______________________________________________
>> > Mailing list: https://launchpad.net/~openstack
>> > Post to     : openstack at lists.launchpad.net
>> > Unsubscribe : https://launchpad.net/~openstack
>> > More help   : https://help.launchpad.net/ListHelp
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130424/134bed87/attachment.html>


More information about the OpenStack-dev mailing list