← Back to team overview

openstack team mailing list archive

Re: use php to make container public or not

 

sorry , i did not use keystone....

On Tue, Dec 6, 2011 at 7:10 PM, crayon_z <crayon.zxs@xxxxxxxxx> wrote:

> **
> Hi, pf shineyear.
>
> It seems that you use swauth or tempauth as the auth system for Swift.
> Have you tried the keystone auth system? How to make a container private
> with keystone auth system? It seems that all the containers created are
> public.
>
> Thanks.
>
> ------------------------------
> Crayon
>
>  *Sender:* pf shineyear <shinepf@xxxxxxxxx>
> *Date:* 2011年11月23日(星期三) 下午12:47
> *To:* openstack <openstack@xxxxxxxxxxxxxxxxxxx>
> *Subject:* [Openstack] use php to make container public or not
>  php curl have a shit feature: can not post an empty http header, so if
> you want to perform a command like this in php:
>
> swift -A http://10.38.10.127:8080/auth/v1.0 -U AUTH_testa27:AUTH_testu27
> -K testp post -r ' ' mycontainer2
>
> the "X-Container-Read" will not be send, so you can not make a container
> unpublic from public
>
> i write an example code to show how make it work with php, just use ' not
> " and plus \n at the end
>
> hope can make some help
>
>
> <?php
>
>     $prefix = "AUTH_";
>     $account_name = $prefix."testa27";
>     $user_name = $prefix."testu27";
>     $user_pass = "testp";
>     $container = "mycontainer2";
>     $user_token = "AUTH_tkb21f5fcfea144cf9a99ed1de9a577db2";
>     $path = "/v1/".$account_name."/".$container;
>
>
>     #if you want to make container public use this
>     #$http_headers = array("X-Auth-Token: ".$user_token,
> 'X-Container-Read: .r:*');
>
>     #if you want to make container not public use this
>     $http_headers = array("X-Auth-Token: ".$user_token, 'X-Container-Read:
> \n');
>
>     print_r($http_header);
>
>     $ch = curl_init();
>
>     curl_setopt($ch, CURLOPT_URL, "http://10.38.10.127:8080".$path);
>     curl_setopt($ch, CURLOPT_POST, 1);
>     curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
>     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
>     curl_setopt($ch, CURLINFO_HEADER_OUT, true);
>
>     print "test set container public\n";
>
>     curl_exec($ch);
>
>     $headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);
>
>     print_r($headers);
>
>     if (!curl_errno($ch))
>     {
>         $info = curl_getinfo($ch);
>
>         if ((int)($info['http_code'] / 100) != 2)
>         {
>             print "set container public return error
> ".$info['http_code']."\n";
>             return -1;
>         }
>     }
>     else
>     {
>         print "set container public error\n";
>         return -2;
>     }
>
>     curl_close($ch);
>
> ?>
>

References